star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit bb45368afca9ceeb600ad1111da591702bec6a65
parent b413c5a230c3c89f1fa747d42c1e479b079b73ec
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  9 Mar 2015 14:01:10 +0100

Begin the implementation and the tests of the s3d_shape API

Diffstat:
Mcmake/CMakeLists.txt | 3++-
Asrc/s3d_shape.c | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/s3d_shape_c.h | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_s3d_shape.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 240 insertions(+), 1 deletion(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -54,7 +54,7 @@ set(VERSION_MINOR 0) set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) -set(S3D_FILES_SRC s3d_device.c s3d_scene.c) +set(S3D_FILES_SRC s3d_device.c s3d_scene.c s3d_shape.c) set(S3D_FILES_INC s3d.h) # Prepend each file in the `S3D_FILES_<SRC|INC>' list by `S3D_SOURCE_DIR' @@ -87,6 +87,7 @@ if(NOT NO_TEST) new_test(test_s3d_device) new_test(test_s3d_scene) + new_test(test_s3d_shape) endif(NOT NO_TEST) ################################################################################ diff --git a/src/s3d_shape.c b/src/s3d_shape.c @@ -0,0 +1,116 @@ +/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) + * + * This software is a computer program whose purpose is to describe a + * virtual 3D environment that can be ray-traced and sampled both robustly + * and efficiently. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#include "s3d.h" +#include "s3d_device_c.h" +#include "s3d_shape_c.h" + +#include <rsys/mem_allocator.h> + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +shape_release(ref_T* ref) +{ + struct s3d_shape* shape; + struct s3d_device* dev; + ASSERT(ref); + shape = CONTAINER_OF(ref, struct s3d_shape, ref); + dev = shape->dev; + /* The shape should not be attached */ + ASSERT(is_list_empty(&shape->scene_attachment)); + MEM_FREE(dev->allocator, shape); + S3D(device_ref_put(dev)); +} + +/******************************************************************************* + * Exported s3d_shape functions: + ******************************************************************************/ +res_T +s3d_shape_create(struct s3d_device* dev, struct s3d_shape** out_shape) +{ + struct s3d_shape* shape = NULL; + res_T res = RES_OK; + + if(!dev || !out_shape) { + res = RES_BAD_ARG; + goto error; + } + shape = MEM_CALLOC(dev->allocator, 1, sizeof(struct s3d_shape)); + if(!shape) { + res = RES_MEM_ERR; + goto error; + } + list_init(&shape->scene_attachment); + shape->type = SHAPE_NONE; + S3D(device_ref_get(dev)); + ref_init(&shape->ref); + shape->dev = dev; + +exit: + if(out_shape) *out_shape = shape; + return res; +error: + if(shape) { + S3D(shape_ref_put(shape)); + shape = NULL; + } + goto exit; +} + +res_T +s3d_shape_ref_get(struct s3d_shape* shape) +{ + if(!shape) return RES_BAD_ARG; + ref_get(&shape->ref); + return RES_OK; +} + +res_T +s3d_shape_ref_put(struct s3d_shape* shape) +{ + if(!shape) return RES_BAD_ARG; + ref_put(&shape->ref, shape_release); + return RES_OK; +} + +res_T +s3d_shape_detach(struct s3d_shape* shape) +{ + if(!shape) return RES_BAD_ARG; + if(is_list_empty(&shape->scene_attachment)) /* The shape is not attached */ + return RES_OK; + list_del(&shape->scene_attachment); + S3D(shape_ref_put(shape)); + return RES_OK; +} diff --git a/src/s3d_shape_c.h b/src/s3d_shape_c.h @@ -0,0 +1,54 @@ +/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) + * + * This software is a computer program whose purpose is to describe a + * virtual 3D environment that can be ray-traced and sampled both robustly + * and efficiently. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#ifndef S3D_SHAPE_C_H +#define S3D_SHAPE_C_H + +#include <rsys/list.h> +#include <rsys/ref_count.h> + +enum shape_type { + SHAPE_TRIMESH, + SHAPE_SCENE, + SHAPE_TYPES_COUNT__, + SHAPE_NONE = SHAPE_TYPES_COUNT__ +}; + +struct s3d_shape { + struct list_node scene_attachment; + enum shape_type type; + struct s3d_device* dev; + ref_T ref; +}; + +#endif /* S3D_SHAPE_C_H */ + diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c @@ -0,0 +1,68 @@ +/* Copyright (C) |Meso|Star> 2015 (contact@meso-star.com) + * + * This software is a computer program whose purpose is to describe a + * virtual 3D environment that can be ray-traced and sampled both robustly + * and efficiently. + * + * This software is governed by the CeCILL license under French law and + * abiding by the rules of distribution of free software. You can use, + * modify and/or redistribute the software under the terms of the CeCILL + * license as circulated by CEA, CNRS and INRIA at the following URL + * "http://www.cecill.info". + * + * As a counterpart to the access to the source code and rights to copy, + * modify and redistribute granted by the license, users are provided only + * with a limited warranty and the software's author, the holder of the + * economic rights, and the successive licensors have only limited + * liability. + * + * In this respect, the user's attention is drawn to the risks associated + * with loading, using, modifying and/or developing or reproducing the + * software by the user in light of its specific status of free software, + * that may mean that it is complicated to manipulate, and that also + * therefore means that it is reserved for developers and experienced + * professionals having in-depth computer knowledge. Users are therefore + * encouraged to load and test the software's suitability as regards their + * requirements in conditions enabling the security of their systems and/or + * data to be ensured and, more generally, to use and operate it in the + * same conditions as regards security. + * + * The fact that you are presently reading this means that you have had + * knowledge of the CeCILL license and that you accept its terms. */ + +#include "s3d.h" +#include "test_s3d_utils.h" + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct s3d_device* dev; + struct s3d_shape* shape; + (void)argc, (void)argv; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(s3d_device_create(NULL, &allocator, &dev), RES_OK); + + CHECK(s3d_shape_create(NULL, NULL), RES_BAD_ARG); + CHECK(s3d_shape_create(dev, NULL), RES_BAD_ARG); + CHECK(s3d_shape_create(NULL, &shape), RES_BAD_ARG); + CHECK(s3d_shape_create(dev, &shape), RES_OK); + + CHECK(s3d_shape_detach(NULL), RES_BAD_ARG); + CHECK(s3d_shape_detach(shape), RES_OK); + + CHECK(s3d_shape_ref_get(NULL), RES_BAD_ARG); + CHECK(s3d_shape_ref_get(shape), RES_OK); + CHECK(s3d_shape_ref_put(NULL), RES_BAD_ARG); + CHECK(s3d_shape_ref_put(shape), RES_OK); + CHECK(s3d_shape_ref_put(shape), RES_OK); + + CHECK(s3d_device_ref_put(dev), RES_OK);; + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + return 0; +}