commit f035b25a197253d032d136f5ba94d786128de55a
parent a9f68b5b689cf4ee00b196c948aea07b499d6025
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 25 Nov 2016 09:00:24 +0100
Implement the s3dut_mesh API
Diffstat:
| A | src/s3dut_mesh.c | | | 90 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | src/s3dut_mesh.h | | | 42 | ++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 132 insertions(+), 0 deletions(-)
diff --git a/src/s3dut_mesh.c b/src/s3dut_mesh.c
@@ -0,0 +1,90 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "s3dut.h"
+#include "s3dut_mesh.h"
+
+#include <rsys/mem_allocator.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static void
+release_mesh(ref_T* ref)
+{
+ struct s3dut_mesh* mesh;
+ ASSERT(ref);
+ mesh = CONTAINER_OF(ref, struct s3dut_mesh, ref);
+ darray_double_release(&mesh->coords);
+ darray_size_t_release(&mesh->ids);
+ MEM_RM(mesh->allocator, mesh);
+}
+
+/*******************************************************************************
+ * Exported functions
+ ******************************************************************************/
+res_T
+s3dut_mesh_ref_get(struct s3dut_mesh* mesh)
+{
+ if(!mesh) return RES_BAD_ARG;
+ ref_get(&mesh->ref);
+ return RES_OK;
+}
+
+res_T
+s3dut_mesh_ref_put(struct s3dut_mesh* mesh)
+{
+ if(!mesh) return RES_BAD_ARG;
+ ref_put(&mesh->ref, release_mesh);
+ return RES_OK;
+}
+
+/*******************************************************************************
+ * Local function
+ ******************************************************************************/
+res_T
+mesh_create(struct mem_allocator* allocator, struct s3dut_mesh** out_mesh)
+{
+ struct s3dut_mesh* mesh = NULL;
+ struct mem_allocator* mem_allocator;
+ res_T res = RES_OK;
+
+ if(!out_mesh) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ mem_allocator = allocator ? allocator : &mem_default_allocator;
+ mesh = MEM_CALLOC(mem_allocator, 1, sizeof(struct s3dut_mesh));
+ if(!mesh) {
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ mesh->allocator = mem_allocator;
+ ref_init(&mesh->ref);
+ darray_double_init(mem_allocator, &mesh->coords);
+ darray_size_t_init(mem_allocator, &mesh->ids);
+
+exit:
+ if(out_mesh) *out_mesh = mesh;
+ return res;
+error:
+ if(mesh) {
+ S3DUT(mesh_ref_put(mesh));
+ mesh = NULL;
+ }
+ goto exit;
+}
+
diff --git a/src/s3dut_mesh.h b/src/s3dut_mesh.h
@@ -0,0 +1,42 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef S3DUT_MESH_H
+#define S3DUT_MESH_H
+
+#include <rsys/dynamic_array_double.h>
+#include <rsys/dynamic_array_size_t.h>
+#include <rsys/ref_count.h>
+
+enum s3dut_mesh_type {
+ S3DUT_MESH_SPHERE
+};
+
+struct s3dut_mesh {
+ enum s3dut_mesh_type type;
+ struct darray_double coords;
+ struct darray_size_t ids;
+
+ ref_T ref;
+ struct mem_allocator* allocator;
+};
+
+extern LOCAL_SYM res_T
+mesh_create
+ (struct mem_allocator* allocator,
+ struct s3dut_mesh** out_mesh);
+
+#endif /* S3DUT_MESH_H */
+