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 6bbd7d19755a04c283db5bd189b97ba5fff0c09f
parent dd78aa8092fffb9940cdad6ea87604500242a5dd
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  1 Jul 2016 11:01:29 +0200

Relax the shape detachment constraints during a scene session

A shape that is not used by a scene session can be detached from the
scene.

Diffstat:
Msrc/s3d_scene.c | 15++++++++++-----
Msrc/test_s3d_scene.c | 8++++++++
2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -442,17 +442,18 @@ error: goto exit; } -static void +static res_T scene_detach_shape(struct s3d_scene* scn, struct s3d_shape* shape) { struct geometry** pgeom; ASSERT(scn && shape && !is_list_empty(&shape->scene_attachment)); ASSERT(shape->type == GEOM_MESH || shape->type == GEOM_INSTANCE); - ASSERT(scn->session_mask == 0); pgeom = htable_geom_find(&scn->cached_geoms, &shape); if(pgeom) { /* Remove the cached shape mesh */ struct geometry* geom = *pgeom; + if(scn->session_mask != 0) return RES_BAD_OP; + if(geom->irtc != RTC_INVALID_GEOMETRY_ID) { rtcDeleteGeometry(scn->rtc_scn, geom->irtc); geom->irtc = RTC_INVALID_GEOMETRY_ID; @@ -469,6 +470,7 @@ scene_detach_shape(struct s3d_scene* scn, struct s3d_shape* shape) } S3D(shape_ref_put(shape)); + return RES_OK; } static res_T @@ -847,9 +849,10 @@ s3d_scene_attach_shape(struct s3d_scene* scn, struct s3d_shape* shape) res_T s3d_scene_detach_shape(struct s3d_scene* scn, struct s3d_shape* shape) { + res_T res = RES_OK; char is_attached; + if(!scn || !shape) return RES_BAD_ARG; - if(scn->session_mask != 0) return RES_BAD_OP; if(!(S3D(shape_is_attached(shape, &is_attached)), is_attached)) return RES_BAD_ARG; #ifndef NDEBUG @@ -865,7 +868,8 @@ s3d_scene_detach_shape(struct s3d_scene* scn, struct s3d_shape* shape) ASSERT(is_found); } #endif - scene_detach_shape(scn, shape); + res = scene_detach_shape(scn, shape); + if(res != RES_OK) return res; return RES_OK; } @@ -878,7 +882,8 @@ s3d_scene_clear(struct s3d_scene* scn) LIST_FOR_EACH_SAFE(node, tmp, &scn->shapes) { struct s3d_shape* shape = CONTAINER_OF (node, struct s3d_shape, scene_attachment); - scene_detach_shape(scn, shape); + const res_T res = scene_detach_shape(scn, shape); + ASSERT(res == RES_OK); (void)res; } return RES_OK; } diff --git a/src/test_s3d_scene.c b/src/test_s3d_scene.c @@ -173,9 +173,17 @@ main(int argc, char** argv) CHECK(s3d_scene_end_session(scn), RES_OK); CHECK(s3d_scene_end_session(scn), RES_BAD_OP); + CHECK(s3d_scene_get_session_mask(scn, &mask), RES_OK); CHECK(mask, 0); + CHECK(s3d_scene_detach_shape(scn, shapes[0]), RES_OK); + CHECK(s3d_scene_begin_session(scn, S3D_TRACE), RES_OK); + CHECK(s3d_scene_attach_shape(scn, shapes[0]), RES_OK); + CHECK(s3d_scene_detach_shape(scn, shapes[0]), RES_OK); + CHECK(s3d_scene_attach_shape(scn, shapes[0]), RES_OK); + CHECK(s3d_scene_end_session(scn), RES_OK); + CHECK(s3d_scene_attach_shape(scn2, shapes[1]), RES_OK); CHECK(s3d_scene_attach_shape(scn2, shapes[2]), RES_OK); CHECK(s3d_scene_begin_session(scn2, S3D_SAMPLE|S3D_TRACE), RES_OK);