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 ee8cf0567a598920f9710039864f7c936880d9f4
parent 4ef3ee2c6998edd30867b1087ac20d226da4a8ff
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 22 Jul 2016 12:24:26 +0200

Fix the scene_sync routine

Since the shape can be attached to multiple scenes, it cannot register
anymore its synchronisation status (i.e. its backend state). This commit
remove these synchronisation states such as resize_mask, update_mask and
update_transform.

Diffstat:
Msrc/s3d_instance.c | 1-
Msrc/s3d_instance.h | 1-
Msrc/s3d_mesh.c | 44+-------------------------------------------
Msrc/s3d_mesh.h | 7-------
Msrc/s3d_scene.c | 45++++++++++++++++++++++++++-------------------
Msrc/s3d_scene_c.h | 1+
Msrc/s3d_shape.c | 3---
Msrc/test_s3d_scene.c | 6+++++-
8 files changed, 33 insertions(+), 75 deletions(-)

diff --git a/src/s3d_instance.c b/src/s3d_instance.c @@ -74,7 +74,6 @@ instance_create } f33_set_identity(inst->transform); /* rotation */ f3_splat(inst->transform + 9, 0.f); /* Translation */ - inst->update_transform = 0; ref_init(&inst->ref); S3D(scene_ref_get(scn)); inst->scene = scn; diff --git a/src/s3d_instance.h b/src/s3d_instance.h @@ -39,7 +39,6 @@ struct instance { float transform[12]; /* local to world 3x4 column major matrix */ - char update_transform; struct s3d_scene* scene; ref_T ref; }; diff --git a/src/s3d_mesh.c b/src/s3d_mesh.c @@ -60,13 +60,6 @@ mesh_setup_indices if(get_indices == S3D_KEEP) return; - if(ntris == ntris_prev) { - mesh->update_mask |= (INDEX_BUFFER & !mesh->resize_mask); - } else { - mesh->resize_mask |= INDEX_BUFFER; - mesh->update_mask &= !INDEX_BUFFER; - } - if(mesh->indices) { /* Release the old index buffer */ index_buffer_ref_put(mesh->indices); mesh->indices = NULL; @@ -102,7 +95,7 @@ mesh_setup_positions void* data) { float* positions; - unsigned ivert, nverts_prev; + unsigned ivert; res_T res; ASSERT(mesh && nverts && attr && attr->usage == S3D_POSITION); @@ -112,14 +105,6 @@ mesh_setup_positions return; } - nverts_prev = (unsigned)mesh_get_nverts(mesh); - if(nverts == nverts_prev) { - mesh->update_mask |= (VERTEX_BUFFER & ~mesh->resize_mask); - } else { - mesh->resize_mask |= VERTEX_BUFFER; - mesh->update_mask &= !VERTEX_BUFFER; - } - if(mesh->attribs[S3D_POSITION]) { /* Release the old vertex buffer */ vertex_buffer_ref_put(mesh->attribs[S3D_POSITION]); mesh->attribs[S3D_POSITION] = NULL; @@ -304,8 +289,6 @@ mesh_clear(struct mesh* mesh) mesh->attribs[iattr] = NULL; } } - mesh->resize_mask = 0; - mesh->update_mask = 0; darray_float_clear(&mesh->cdf); } @@ -549,26 +532,9 @@ mesh_compute_aabb(struct mesh* mesh, float lower[3], float upper[3]) void mesh_copy_indexed_vertices(const struct mesh* src, struct mesh* dst) { - size_t ntris_src; - size_t ntris_dst; - size_t nverts_src; - size_t nverts_dst; int i; ASSERT(src && dst && src != dst); - ntris_src = mesh_get_ntris(src); - ntris_dst = mesh_get_ntris(dst); - nverts_src = mesh_get_nverts(src); - nverts_dst = mesh_get_nverts(dst); - - /* Setup the index buffer masks */ - if(ntris_src == ntris_dst) { - dst->update_mask = (INDEX_BUFFER & !dst->resize_mask); - } else { - dst->resize_mask |= INDEX_BUFFER; - dst->update_mask &= !INDEX_BUFFER; - } - /* Release the previous index buffer of dst */ if(dst->indices) { index_buffer_ref_put(dst->indices); @@ -580,14 +546,6 @@ mesh_copy_indexed_vertices(const struct mesh* src, struct mesh* dst) dst->indices = src->indices; } - /* Setup the vertex buffer masks */ - if(nverts_src == nverts_dst) { - dst->update_mask = (VERTEX_BUFFER & ~dst->resize_mask); - } else { - dst->resize_mask |= VERTEX_BUFFER; - dst->update_mask &= !VERTEX_BUFFER; - } - FOR_EACH(i, 0, S3D_ATTRIBS_COUNT__) { /* Release the previous vertex buffers of dst */ if(dst->attribs[i]) { diff --git a/src/s3d_mesh.h b/src/s3d_mesh.h @@ -52,11 +52,6 @@ #define BUFFER_DARRAY darray_float #include "s3d_buffer.h" -enum buffer_type { - INDEX_BUFFER = BIT(0), - VERTEX_BUFFER = BIT(1) -}; - /* Filter function and its associated user defined data */ struct hit_filter { s3d_hit_filter_function_T func; @@ -70,8 +65,6 @@ struct mesh { /* Triangular mesh */ struct darray_float cdf; struct hit_filter filter; - int resize_mask; /* Combination of buffer_type */ - int update_mask; /* Combination of buffer_type */ struct s3d_device* dev; ref_T ref; }; diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -313,10 +313,8 @@ scene_register_mesh } /* Define which geometry buffers were updated */ - upd_ids = geom->data.mesh->indices != shape->data.mesh->indices - || ((shape->data.mesh->update_mask & INDEX_BUFFER) != 0); - upd_pos = geom->data.mesh->attribs[S3D_POSITION] != shape->data.mesh->attribs[S3D_POSITION] - || ((shape->data.mesh->update_mask & VERTEX_BUFFER) != 0); + upd_ids = geom->data.mesh->indices != shape->data.mesh->indices; + upd_pos = geom->data.mesh->attribs[S3D_POSITION] != shape->data.mesh->attribs[S3D_POSITION]; /* Get a reference onto the shape mesh indices */ if(geom->data.mesh->indices != shape->data.mesh->indices) { @@ -346,11 +344,22 @@ scene_register_mesh geom->data.mesh->attribs_type[iattr] = shape->data.mesh->attribs_type[iattr]; } - /* The shape mesh was resize => the Embree geometry is no more valid */ - if(shape->data.mesh->resize_mask && geom->irtc != RTC_INVALID_GEOMETRY_ID) { - rtcDeleteGeometry(scn->rtc_scn, geom->irtc); - geom->irtc = RTC_INVALID_GEOMETRY_ID; - scn->is_rtc_scn_outdated = 1; + if(geom->irtc != RTC_INVALID_GEOMETRY_ID) { + struct index_buffer* shape_ids = shape->data.mesh->indices; + struct index_buffer* geom_ids = geom->data.mesh->indices; + struct vertex_buffer* shape_verts = shape->data.mesh->attribs[S3D_POSITION]; + struct vertex_buffer* geom_verts = geom->data.mesh->attribs[S3D_POSITION]; + const size_t shape_nids = darray_u32_size_get(&shape_ids->data); + const size_t geom_nids = darray_u32_size_get(&geom_ids->data); + const size_t shape_nverts = darray_float_size_get(&shape_verts->data); + const size_t geom_nverts = darray_float_size_get(&geom_verts->data); + + /* The shape mesh was resize => the Embree geometry is no more valid */ + if(shape_nids != geom_nids || shape_nverts != geom_nverts) { + rtcDeleteGeometry(scn->rtc_scn, geom->irtc); + geom->irtc = RTC_INVALID_GEOMETRY_ID; + scn->is_rtc_scn_outdated = 1; + } } res = scene_register_embree_geometry(scn, geom); @@ -368,10 +377,6 @@ scene_register_mesh scene_geometry_flush_filter_function(scn, geom, shape); geom->flip_surface = shape->flip_surface; - /* Flush the shape mesh states */ - shape->data.mesh->resize_mask = 0; - shape->data.mesh->update_mask = 0; - exit: return res; error: @@ -390,7 +395,7 @@ scene_register_instance res_T res = RES_OK; ASSERT(scn && shape && shape->type == GEOM_INSTANCE); - /* Recursuvely update the scene */ + /* Recursively update the scene */ res = scene_sync(shape->data.instance->scene, session_mask|S3D_INSTANCE); if(res != RES_OK) goto error; @@ -412,8 +417,6 @@ scene_register_instance } /* Update the cached instance states */ ASSERT(geom->data.instance->scene == shape->data.instance->scene); - f33_set(geom->data.instance->transform, shape->data.instance->transform); - f3_set(geom->data.instance->transform + 9, shape->data.instance->transform + 9); geom->flip_surface = shape->flip_surface; /* The instance cannot contain instances, i.e. one instancing level is @@ -427,8 +430,13 @@ scene_register_instance res = scene_register_embree_geometry(scn, geom); if(res != RES_OK) goto error; - /* Update the Embree instance transformation */ - if(shape->data.instance->update_transform) { + /* Update the Embree instance transformation if necessary */ + if(!f33_eq(shape->data.instance->transform, geom->data.instance->transform) + || !f3_eq(shape->data.instance->transform+9, geom->data.instance->transform+9)) { + + f33_set(geom->data.instance->transform, shape->data.instance->transform); + f3_set(geom->data.instance->transform+9, shape->data.instance->transform+9); + rtcSetTransform (scn->rtc_scn, geom->irtc, @@ -438,7 +446,6 @@ scene_register_instance } scene_geometry_flush_enable_state(scn, geom, shape); - shape->data.instance->update_transform = 0; /* Flush instance state */ exit: return res; diff --git a/src/s3d_scene_c.h b/src/s3d_scene_c.h @@ -95,6 +95,7 @@ struct s3d_scene { char is_rtc_scn_outdated; /* Must the embree scene rebuild */ int session_mask; /* Combination of enum s3d_session_flag */ + size_t nsessions; /* # session active onto the scene */ struct s3d_device* dev; ref_T ref; diff --git a/src/s3d_shape.c b/src/s3d_shape.c @@ -202,7 +202,6 @@ s3d_instance_set_position f3_dot(f33_row(axis, shape->data.instance->transform, 1), position); shape->data.instance->transform[11] = f3_dot(f33_row(axis, shape->data.instance->transform, 2), position); - shape->data.instance->update_transform = 1; return RES_OK; } @@ -221,13 +220,11 @@ s3d_instance_translate (shape->data.instance->transform + 9, shape->data.instance->transform + 9, vec); - shape->data.instance->update_transform = 1; } else if(space == S3D_WORLD_TRANSFORM) { f3_add (shape->data.instance->transform + 9, shape->data.instance->transform + 9, translation); - shape->data.instance->update_transform = 1; } else { return RES_BAD_ARG; } diff --git a/src/test_s3d_scene.c b/src/test_s3d_scene.c @@ -173,7 +173,6 @@ 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); @@ -186,7 +185,12 @@ main(int argc, char** argv) CHECK(s3d_scene_attach_shape(scn2, shapes[1]), RES_OK); CHECK(s3d_scene_attach_shape(scn2, shapes[2]), RES_OK); + CHECK(s3d_scene_attach_shape(scn3, shapes[1]), RES_OK); + CHECK(s3d_scene_begin_session(scn2, S3D_SAMPLE|S3D_TRACE), RES_OK); + CHECK(s3d_scene_begin_session(scn, S3D_SAMPLE), RES_BAD_OP); + CHECK(s3d_scene_begin_session(scn3, S3D_SAMPLE), RES_OK); + CHECK(s3d_scene_end_session(scn3), RES_OK); CHECK(s3d_scene_compute_area(NULL, NULL), RES_BAD_ARG); CHECK(s3d_scene_compute_area(scn2, NULL), RES_BAD_ARG);