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 13cf95fb4dd9e82646f64db18b978fbc85d3d262
parent 4ae8a3839f49464c05830b3b7d59da72e0e2b7cf
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 18 May 2016 15:18:54 +0200

Restrict the support of filter function to meshes

Diffstat:
Msrc/s3d.h | 30+++++++++++++++---------------
Msrc/s3d_geometry.h | 7-------
Msrc/s3d_mesh.h | 7+++++++
Msrc/s3d_scene.c | 7+++----
Msrc/s3d_shape.c | 41+++++++++++++++++++++--------------------
Msrc/s3d_shape_c.h | 3---
Msrc/test_s3d_shape.c | 26+++++++++++++-------------
Msrc/test_s3d_trace_ray.c | 2+-
8 files changed, 60 insertions(+), 63 deletions(-)

diff --git a/src/s3d.h b/src/s3d.h @@ -416,21 +416,6 @@ S3D_API res_T s3d_shape_flip_surface (struct s3d_shape* shape); -/* Define a intersection filter function. The filter function is invoked at - * each intersection found during the s3d_scene_trace_ray(s) calls. If func - * does not return 0, then the intersection is ignored and the ray pursues its - * traversal. */ -S3D_API res_T -s3d_shape_set_hit_filter_function - (struct s3d_shape* shape, - s3d_hit_filter_function_T func, - void* filter_data); - -S3D_API res_T -s3d_shape_get_hit_filter_data - (struct s3d_shape* shape, - void** data); - /******************************************************************************* * Primitive API - Define a geometric primitive of a shape ******************************************************************************/ @@ -501,6 +486,21 @@ s3d_mesh_get_triangle_indices const unsigned itri, unsigned ids[3]); +/* Define a intersection filter function. The filter function is invoked at + * each intersection found during the s3d_scene_trace_ray(s) calls. If func + * does not return 0, then the intersection is ignored and the ray pursues its + * traversal. */ +S3D_API res_T +s3d_mesh_set_hit_filter_function + (struct s3d_shape* shape, + s3d_hit_filter_function_T func, + void* filter_data); + +S3D_API res_T +s3d_mesh_get_hit_filter_data + (struct s3d_shape* shape, + void** data); + /******************************************************************************* * Instance API - An instance is a shape that encapsulates a scene and that * supports a local to world transformation. Since the scene geometry is stored diff --git a/src/s3d_geometry.h b/src/s3d_geometry.h @@ -44,12 +44,6 @@ enum geometry_type { GEOM_NONE = GEOM_TYPES_COUNT__ }; -/* Filter function and its associated user defined data */ -struct hit_filter { - s3d_hit_filter_function_T func; - void* data; -}; - /* Backend geometry */ struct geometry { unsigned name; /* Client side identifier */ @@ -57,7 +51,6 @@ struct geometry { unsigned scene_prim_id_offset; /* Offset from local to scene prim_id */ char flip_surface; /* Is the geometry surface flipped? */ char is_enabled; /* Is the geometry enabled? */ - struct hit_filter filter; enum geometry_type type; union { diff --git a/src/s3d_mesh.h b/src/s3d_mesh.h @@ -57,11 +57,18 @@ enum buffer_type { VERTEX_BUFFER = BIT(1) }; +/* Filter function and its associated user defined data */ +struct hit_filter { + s3d_hit_filter_function_T func; + void* data; +}; + struct mesh { /* Triangular mesh */ struct index_buffer* indices; struct vertex_buffer* attribs[S3D_ATTRIBS_COUNT__]; enum s3d_type attribs_type[S3D_ATTRIBS_COUNT__]; struct darray_float cdf; + struct hit_filter filter; int resize_mask; /* Combination of buffer_type */ int update_mask; /* Combination of buffer_type */ diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -308,8 +308,7 @@ scene_register_mesh /* Update the cached mesh states */ geom->flip_surface = shape->flip_surface; - geom->filter.func = shape->filter; - geom->filter.data = shape->filter_data; + geom->data.mesh->filter = shape->data.mesh->filter; res = scene_register_embree_geometry(scn, geom); if(res != RES_OK) goto error; @@ -326,9 +325,9 @@ scene_register_mesh rtcUpdateBuffer(scn->rtc_scn, geom->irtc, RTC_INDEX_BUFFER); scn->is_rtc_scn_outdated = 1; } - if(geom->filter.func) { /* Update the filter func of the geometry */ + if(geom->data.mesh->filter.func) { /* Upd the filter func of the mesh */ rtcSetIntersectionFilterFunction(scn->rtc_scn, geom->irtc, filter_wrapper); - rtcSetUserData(scn->rtc_scn, geom->irtc, &geom->filter); + rtcSetUserData(scn->rtc_scn, geom->irtc, &geom->data.mesh->filter); } scene_geometry_flush_enable_state(scn, geom, shape); diff --git a/src/s3d_shape.c b/src/s3d_shape.c @@ -201,26 +201,6 @@ s3d_shape_flip_surface(struct s3d_shape* shape) } res_T -s3d_shape_set_hit_filter_function - (struct s3d_shape* shape, - s3d_hit_filter_function_T func, - void* data) -{ - if(!shape) return RES_BAD_ARG; - shape->filter = func; - shape->filter_data = data; - return RES_OK; -} - -res_T -s3d_shape_get_hit_filter_data(struct s3d_shape* shape, void** data) -{ - if(!shape || !data) return RES_BAD_ARG; - *data = shape->filter_data; - return RES_OK; -} - -res_T s3d_instance_set_position (struct s3d_shape* shape, const float position[3]) { @@ -358,3 +338,24 @@ s3d_mesh_get_triangle_indices return RES_OK; } +res_T +s3d_mesh_set_hit_filter_function + (struct s3d_shape* shape, + s3d_hit_filter_function_T func, + void* data) +{ + if(!shape || shape->type != GEOM_MESH) return RES_BAD_ARG; + shape->data.mesh->filter.func = func; + shape->data.mesh->filter.data = data; + return RES_OK; +} + +res_T +s3d_mesh_get_hit_filter_data(struct s3d_shape* shape, void** data) +{ + if(!shape || !data || shape->type != GEOM_MESH) return RES_BAD_ARG; + *data = shape->data.mesh->filter.data; + return RES_OK; +} + + diff --git a/src/s3d_shape_c.h b/src/s3d_shape_c.h @@ -52,9 +52,6 @@ struct s3d_shape { char is_enabled; enum geometry_type type; - s3d_hit_filter_function_T filter; - void* filter_data; - union { struct instance* instance; struct mesh* mesh; diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c @@ -300,23 +300,23 @@ main(int argc, char** argv) CHECK(s3d_shape_flip_surface(shape), RES_OK); CHECK(s3d_shape_flip_surface(shape), RES_OK); - CHECK(s3d_shape_set_hit_filter_function(NULL, NULL, NULL), RES_BAD_ARG); - CHECK(s3d_shape_set_hit_filter_function(shape, NULL, NULL), RES_OK); - CHECK(s3d_shape_set_hit_filter_function(NULL, filter_none, NULL), RES_BAD_ARG); - CHECK(s3d_shape_set_hit_filter_function(shape, filter_none, NULL), RES_OK); - - CHECK(s3d_shape_get_hit_filter_data(NULL, NULL), RES_BAD_ARG); - CHECK(s3d_shape_get_hit_filter_data(shape, NULL), RES_BAD_ARG); - CHECK(s3d_shape_get_hit_filter_data(NULL, &data), RES_BAD_ARG); - CHECK(s3d_shape_get_hit_filter_data(shape, &data), RES_OK); + CHECK(s3d_mesh_set_hit_filter_function(NULL, NULL, NULL), RES_BAD_ARG); + CHECK(s3d_mesh_set_hit_filter_function(shape, NULL, NULL), RES_OK); + CHECK(s3d_mesh_set_hit_filter_function(NULL, filter_none, NULL), RES_BAD_ARG); + CHECK(s3d_mesh_set_hit_filter_function(shape, filter_none, NULL), RES_OK); + + CHECK(s3d_mesh_get_hit_filter_data(NULL, NULL), RES_BAD_ARG); + CHECK(s3d_mesh_get_hit_filter_data(shape, NULL), RES_BAD_ARG); + CHECK(s3d_mesh_get_hit_filter_data(NULL, &data), RES_BAD_ARG); + CHECK(s3d_mesh_get_hit_filter_data(shape, &data), RES_OK); CHECK(data, NULL); - CHECK(s3d_shape_set_hit_filter_function(shape, NULL, NULL), RES_OK); - CHECK(s3d_shape_get_hit_filter_data(shape, &data), RES_OK); + CHECK(s3d_mesh_set_hit_filter_function(shape, NULL, NULL), RES_OK); + CHECK(s3d_mesh_get_hit_filter_data(shape, &data), RES_OK); CHECK(data, NULL); - CHECK(s3d_shape_set_hit_filter_function + CHECK(s3d_mesh_set_hit_filter_function (shape, filter_none, (void*)0xDEADBEEF), RES_OK); - CHECK(s3d_shape_get_hit_filter_data(shape, &data), RES_OK); + CHECK(s3d_mesh_get_hit_filter_data(shape, &data), RES_OK); CHECK((uintptr_t)data, 0xDEADBEEF); CHECK(s3d_scene_attach_shape(scn, shape), RES_OK); diff --git a/src/test_s3d_trace_ray.c b/src/test_s3d_trace_ray.c @@ -285,7 +285,7 @@ main(int argc, char** argv) CHECK(s3d_shape_ref_put(walls), RES_OK); CHECK(s3d_shape_get_id(walls_copy, &walls_id), RES_OK); if(filter) { - CHECK(s3d_shape_set_hit_filter_function + CHECK(s3d_mesh_set_hit_filter_function (walls_copy, filter_func, (void*)0xDECAFBAD), RES_OK); }