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 d67fb82b645e638378118796c51740ceba66a42f
parent 438589f90f9a70244659ece9d03a823e6441e0c2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 20 Mar 2015 12:41:05 +0100

Refactoring of the internal scene setup

Diffstat:
Msrc/s3d_scene.c | 39++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -43,7 +43,7 @@ /******************************************************************************* * Helper functions ******************************************************************************/ -static void +static INLINE void delete_rtc_geometry(struct s3d_scene* scn, struct s3d_shape* shape) { ASSERT(scn && shape && shape->rtc_geom != RTC_INVALID_GEOMETRY_ID); @@ -52,6 +52,21 @@ delete_rtc_geometry(struct s3d_scene* scn, struct s3d_shape* shape) shape->rtc_geom = RTC_INVALID_GEOMETRY_ID; } +/* Map the Embree geometry to its s3d shape */ +static INLINE res_T +shape_register_rtc_geom(struct s3d_scene* scn, struct s3d_shape* shape) +{ + ASSERT(scn && shape && shape->rtc_geom != RTC_INVALID_GEOMETRY_ID); + + /* Map the Embree geometry to its shape */ + if(shape->rtc_geom >= darray_geom2shape_size_get(&scn->geom2shape)) { + res_T res = darray_geom2shape_resize(&scn->geom2shape, shape->rtc_geom+1); + if(res != RES_OK) return res; + } + darray_geom2shape_data_get(&scn->geom2shape)[shape->rtc_geom] = shape; + return RES_OK; +} + static res_T shape_mesh_setup(struct s3d_scene* scn, struct s3d_shape* shape) { @@ -92,14 +107,11 @@ shape_mesh_setup(struct s3d_scene* scn, struct s3d_shape* shape) sizeof(float[3])); /* Map the Embree geometry to its shape */ - if(shape->rtc_geom >= darray_geom2shape_size_get(&scn->geom2shape)) { - res = darray_geom2shape_resize(&scn->geom2shape, shape->rtc_geom+1); - if(res != RES_OK) { - mutex_rw_unlock(shape->lock); - return res; - } + res = shape_register_rtc_geom(scn, shape); + if(res != RES_OK) { + mutex_rw_unlock(shape->lock); + return res; } - darray_geom2shape_data_get(&scn->geom2shape)[shape->rtc_geom] = shape; } mutex_rw_unlock(shape->lock); @@ -124,14 +136,11 @@ shape_instance_setup(struct s3d_scene* scn, struct s3d_shape* shape) shape->rtc_geom = rtcNewInstance (scn->rtc_scn, shape->data.instance.scene->rtc_scn); - if(shape->rtc_geom >= darray_geom2shape_size_get(&scn->geom2shape)) { - res = darray_geom2shape_resize(&scn->geom2shape, shape->rtc_geom+1); - if(res != RES_OK) { - mutex_rw_unlock(shape->lock); - return res; - } + res = shape_register_rtc_geom(scn, shape); + if(res != RES_OK) { + mutex_rw_unlock(shape->lock); + return res; } - darray_geom2shape_data_get(&scn->geom2shape)[shape->rtc_geom] = shape; } if(shape->data.instance.update_transform) { rtcSetTransform