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 b413c5a230c3c89f1fa747d42c1e479b079b73ec
parent f2b2a5e9f4136042f42d966b0f89cfe42d98226d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  9 Mar 2015 12:45:50 +0100

Begin the implementation and the tests of the s3d_scene API

Diffstat:
Mcmake/CMakeLists.txt | 7++++---
Msrc/s3d.h | 2+-
Msrc/s3d_device.c | 8+-------
Asrc/s3d_device_c.h | 45+++++++++++++++++++++++++++++++++++++++++++++
Asrc/s3d_scene.c | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/test_s3d_device.c | 1+
Asrc/test_s3d_scene.c | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 223 insertions(+), 11 deletions(-)

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) +set(S3D_FILES_SRC s3d_device.c s3d_scene.c) set(S3D_FILES_INC s3d.h) # Prepend each file in the `S3D_FILES_<SRC|INC>' list by `S3D_SOURCE_DIR' @@ -77,7 +77,7 @@ rcmake_setup_devel(s3d s3d ${VERSION} se/s3d_version.h) if(NOT NO_TEST) function(new_test _name) add_executable(${_name} ${S3D_SOURCE_DIR}/${_name}.c) - target_link_libraries(${_name} s3d) + target_link_libraries(${_name} s3d RSys) set(_libraries ${ARGN}) foreach(_lib ${_libraries}) target_link_libraries(${_name} ${_lib}) @@ -85,7 +85,8 @@ if(NOT NO_TEST) add_test(${_name} ${_name}) endfunction(new_test) - new_test(test_s3d_device RSys) + new_test(test_s3d_device) + new_test(test_s3d_scene) endif(NOT NO_TEST) ################################################################################ diff --git a/src/s3d.h b/src/s3d.h @@ -149,7 +149,7 @@ s3d_device_ref_put S3D_API res_T s3d_scene_create (struct s3d_device* dev, - struct s3d_scene* scn); + struct s3d_scene** scn); S3D_API res_T s3d_scene_ref_get diff --git a/src/s3d_device.c b/src/s3d_device.c @@ -31,16 +31,10 @@ * knowledge of the CeCILL license and that you accept its terms. */ #include "s3d.h" +#include "s3d_device_c.h" #include <rsys/logger.h> #include <rsys/mem_allocator.h> -#include <rsys/ref_count.h> - -struct s3d_device { - struct logger* logger; - struct mem_allocator* allocator; - ref_T ref; -}; /******************************************************************************* * Helper functions diff --git a/src/s3d_device_c.h b/src/s3d_device_c.h @@ -0,0 +1,45 @@ +/* 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_DEVICE_C_H +#define S3D_DEVICE_C_H + +#include <rsys/ref_count.h> + +struct s3d_device { + struct logger* logger; + struct mem_allocator* allocator; + ref_T ref; +}; + +#endif /* S3D_DEVICE_C_H */ + diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -0,0 +1,106 @@ +/* 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 <rsys/mem_allocator.h> + +struct s3d_scene { + struct s3d_device* dev; + ref_T ref; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +scene_release(ref_T* ref) +{ + struct s3d_scene* scn; + struct s3d_device* dev; + ASSERT(ref); + scn = CONTAINER_OF(ref, struct s3d_scene, ref); + dev = scn->dev; + MEM_FREE(dev->allocator, scn); + S3D(device_ref_put(dev)); +} + +/******************************************************************************* + * Exported s3d_scene functions + ******************************************************************************/ +res_T +s3d_scene_create(struct s3d_device* dev, struct s3d_scene** out_scn) +{ + struct s3d_scene* scn = NULL; + res_T res = RES_OK; + + if(!dev || !out_scn) { + res = RES_BAD_ARG; + goto error; + } + scn = MEM_CALLOC(dev->allocator, 1, sizeof(struct s3d_scene)); + if(!scn) { + res = RES_MEM_ERR; + goto error; + } + ref_init(&scn->ref); + S3D(device_ref_get(dev)); + scn->dev = dev; + +exit: + if(out_scn) *out_scn = scn; + return res; +error: + if(scn) { + S3D(scene_ref_put(scn)); + scn = NULL; + } + goto exit; +} + +res_T +s3d_scene_ref_get(struct s3d_scene* scn) +{ + if(!scn) return RES_BAD_ARG; + ref_get(&scn->ref); + return RES_OK; +} + +res_T +s3d_scene_ref_put(struct s3d_scene* scn) +{ + if(!scn) return RES_BAD_ARG; + ref_put(&scn->ref, scene_release); + return RES_OK; +} + diff --git a/src/test_s3d_device.c b/src/test_s3d_device.c @@ -86,3 +86,4 @@ main(int argc, char** argv) CHECK(mem_allocated_size(), 0); return 0; } + diff --git a/src/test_s3d_scene.c b/src/test_s3d_scene.c @@ -0,0 +1,65 @@ +/* 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_scene* scn; + (void)argc, (void)argv; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(s3d_device_create(NULL, &allocator, &dev), RES_OK); + + CHECK(s3d_scene_create(NULL, NULL), RES_BAD_ARG); + CHECK(s3d_scene_create(dev, NULL), RES_BAD_ARG); + CHECK(s3d_scene_create(NULL, &scn), RES_BAD_ARG); + CHECK(s3d_scene_create(dev, &scn), RES_OK); + + CHECK(s3d_scene_ref_get(NULL), RES_BAD_ARG); + CHECK(s3d_scene_ref_get(scn), RES_OK); + CHECK(s3d_scene_ref_put(NULL), RES_BAD_ARG); + CHECK(s3d_scene_ref_put(scn), RES_OK); + CHECK(s3d_scene_ref_put(scn), 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; +}