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 cd62e62b717d67d30c7a5ebea84e4fb254d327d1
parent a63dff51e8352dcd954149d0113cda3a1286a215
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 27 Mar 2015 16:10:03 +0100

Rename some internal s3d_scene fields

Diffstat:
Msrc/s3d_scene.c | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/s3d_scene_c.h | 23+++++++++++++++--------
2 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/src/s3d_scene.c b/src/s3d_scene.c @@ -80,15 +80,15 @@ scene_build_register_mesh(struct s3d_scene* scn, struct mesh* mesh) scn->is_rtc_scn_outdated = 1; } - if(mesh->geom.irtc >= darray_geom2mesh_size_get(&scn->geom2mesh)) { - res_T res = darray_geom2mesh_resize(&scn->geom2mesh, mesh->geom.irtc + 1); + if(mesh->geom.irtc >= darray_mesh_size_get(&scn->meshes)) { + res_T res = darray_mesh_resize(&scn->meshes, mesh->geom.irtc + 1); if(res != RES_OK) { rtcDeleteGeometry(scn->rtc_scn, mesh->geom.irtc); mesh->geom.irtc = RTC_INVALID_GEOMETRY_ID; return res; } mesh_ref_get(mesh); - darray_geom2mesh_data_get(&scn->geom2mesh)[mesh->geom.irtc] = mesh; + darray_mesh_data_get(&scn->meshes)[mesh->geom.irtc] = mesh; } return RES_OK; } @@ -98,7 +98,7 @@ scene_build_register_instance(struct s3d_scene* scn, struct instance* inst) { ASSERT(scn && inst && inst->scene); /* The instance should not contain instances */ - ASSERT(!darray_geom2inst_size_get(&inst->scene->geom2inst)); + ASSERT(!darray_inst_size_get(&inst->scene->instances)); if(inst->geom.irtc == RTC_INVALID_GEOMETRY_ID) { inst->geom.irtc = rtcNewInstance(scn->rtc_scn, inst->scene->rtc_scn); @@ -107,15 +107,15 @@ scene_build_register_instance(struct s3d_scene* scn, struct instance* inst) scn->is_rtc_scn_outdated = 1; } - if(inst->geom.irtc >= darray_geom2inst_size_get(&scn->geom2inst)) { - res_T res = darray_geom2inst_resize(&scn->geom2inst, inst->geom.irtc + 1); + if(inst->geom.irtc >= darray_inst_size_get(&scn->instances)) { + res_T res = darray_inst_resize(&scn->instances, inst->geom.irtc + 1); if(res != RES_OK) { rtcDeleteGeometry(scn->rtc_scn, inst->geom.irtc); inst->geom.irtc = RTC_INVALID_GEOMETRY_ID; return res; } instance_ref_get(inst); - darray_geom2inst_data_get(&scn->geom2inst)[inst->geom.irtc] = inst; + darray_inst_data_get(&scn->instances)[inst->geom.irtc] = inst; } return RES_OK; } @@ -130,20 +130,20 @@ scene_build_clear(struct s3d_scene* scn) size_t i; ASSERT(scn); - nmeshes = darray_geom2mesh_size_get(&scn->geom2mesh); - meshes = darray_geom2mesh_data_get(&scn->geom2mesh); + nmeshes = darray_mesh_size_get(&scn->meshes); + meshes = darray_mesh_data_get(&scn->meshes); FOR_EACH(i, 0, nmeshes) if(meshes[i]) mesh_ref_put(meshes[i]); - darray_geom2mesh_clear(&scn->geom2mesh); + darray_mesh_clear(&scn->meshes); - ninstances = darray_geom2inst_size_get(&scn->geom2inst); - instances = darray_geom2inst_data_get(&scn->geom2inst); + ninstances = darray_inst_size_get(&scn->instances); + instances = darray_inst_data_get(&scn->instances); FOR_EACH(i, 0, ninstances) { if(instances[i]) { scene_build_clear(instances[i]->scene); instance_ref_put(instances[i]); } } - darray_geom2inst_clear(&scn->geom2inst); + darray_inst_clear(&scn->instances); scn->is_rtc_scn_outdated = 0; scn->build_type = BUILD_NONE; } @@ -161,14 +161,14 @@ scene_setup_shape_mesh res_T res = RES_OK; ASSERT(shape && shape->type == SHAPE_MESH); - pmesh = htable_mesh_find(&scn->meshes, &shape); - /* Create the scene mesh of the shape if necessary */ + /* Retrieve the cached shape mesh */ + pmesh = htable_mesh_find(&scn->cached_meshes, &shape); if(pmesh) { mesh = *pmesh; } else { res = mesh_create(scn->dev, &mesh); if(res != RES_OK) goto error; - res = htable_mesh_set(&scn->meshes, &shape, &mesh); + res = htable_mesh_set(&scn->cached_meshes, &shape, &mesh); if(res != RES_OK) goto error; } @@ -264,14 +264,14 @@ scene_setup_shape_instance(struct s3d_scene* scn, struct s3d_shape* shape) res = scene_build(shape->data.instance->scene, BUILD_INDIRECT); if(res != RES_OK) goto error; - pinst = htable_inst_find(&scn->instances, &shape); + pinst = htable_inst_find(&scn->cached_instances, &shape); /* Create the scene instance of the shape if necessary */ if(pinst) { inst = *pinst; } else { res = instance_create(shape->data.instance->scene, &inst); if(res != RES_OK) goto error; - res = htable_inst_set(&scn->instances, &shape, &inst); + res = htable_inst_set(&scn->cached_instances, &shape, &inst); if(res != RES_OK) goto error; } @@ -280,7 +280,7 @@ scene_setup_shape_instance(struct s3d_scene* scn, struct s3d_shape* shape) f3_set(inst->transform + 9, shape->data.instance->transform + 9); /* The instance cannot contain instances */ - if(darray_geom2inst_size_get(&inst->scene->geom2inst)) { + if(darray_inst_size_get(&inst->scene->instances)) { res = RES_BAD_ARG; goto error; } @@ -316,15 +316,15 @@ scene_detach_shape_mesh(struct s3d_scene* scn, struct s3d_shape* shape) ASSERT(scn && shape && !is_list_empty(&shape->scene_attachment)); ASSERT(shape->type == SHAPE_MESH); - pmesh = htable_mesh_find(&scn->meshes, &shape); - if(pmesh) { /* The shape mesh is cached into the scene */ + pmesh = htable_mesh_find(&scn->cached_meshes, &shape); + if(pmesh) { /* Remove the cached shape mesh */ struct mesh* mesh = *pmesh; if(mesh->geom.irtc != RTC_INVALID_GEOMETRY_ID) { rtcDeleteGeometry(scn->rtc_scn, mesh->geom.irtc); mesh->geom.irtc = RTC_INVALID_GEOMETRY_ID; } mesh_ref_put(mesh); - htable_mesh_erase(&scn->meshes, &shape); + htable_mesh_erase(&scn->cached_meshes, &shape); } list_del(&shape->scene_attachment); S3D(shape_ref_put(shape)); @@ -337,15 +337,15 @@ scene_detach_shape_instance(struct s3d_scene* scn, struct s3d_shape* shape) ASSERT(scn && shape && !is_list_empty(&shape->scene_attachment)); ASSERT(shape->type == SHAPE_INSTANCE); - pinst = htable_inst_find(&scn->instances, &shape); - if(pinst) { /* The shape instance is cached into the scene */ + pinst = htable_inst_find(&scn->cached_instances, &shape); + if(pinst) { /* Remove the cached shape instance */ struct instance* inst = *pinst; if(inst->geom.irtc != RTC_INVALID_GEOMETRY_ID) { rtcDeleteGeometry(scn->rtc_scn, inst->geom.irtc); inst->geom.irtc = RTC_INVALID_GEOMETRY_ID; } instance_ref_put(inst); - htable_inst_erase(&scn->instances, &shape); + htable_inst_erase(&scn->cached_instances, &shape); } list_del(&shape->scene_attachment); S3D(shape_ref_put(shape)); @@ -407,10 +407,10 @@ scene_release(ref_T* ref) dev = scn->dev; scene_build_clear(scn); if(scn->rtc_scn) rtcDeleteScene(scn->rtc_scn); - htable_mesh_release(&scn->meshes); - htable_inst_release(&scn->instances); - darray_geom2mesh_release(&scn->geom2mesh); - darray_geom2inst_release(&scn->geom2inst); + htable_mesh_release(&scn->cached_meshes); + htable_inst_release(&scn->cached_instances); + darray_mesh_release(&scn->meshes); + darray_inst_release(&scn->instances); MEM_FREE(dev->allocator, scn); S3D(device_ref_put(dev)); } @@ -435,10 +435,10 @@ s3d_scene_create(struct s3d_device* dev, struct s3d_scene** out_scn) goto error; } list_init(&scn->shapes); - htable_mesh_init(dev->allocator, &scn->meshes); - htable_inst_init(dev->allocator, &scn->instances); - darray_geom2mesh_init(dev->allocator, &scn->geom2mesh); - darray_geom2inst_init(dev->allocator, &scn->geom2inst); + htable_mesh_init(dev->allocator, &scn->cached_meshes); + htable_inst_init(dev->allocator, &scn->cached_instances); + darray_mesh_init(dev->allocator, &scn->meshes); + darray_inst_init(dev->allocator, &scn->instances); ref_init(&scn->ref); S3D(device_ref_get(dev)); scn->dev = dev; @@ -635,14 +635,14 @@ s3d_scene_trace_ray hit->uv[0] = w; if((unsigned)ray.instID == RTC_INVALID_GEOMETRY_ID) { - ASSERT((unsigned)ray.geomID < darray_geom2mesh_size_get(&scn->geom2mesh)); - hit->prim.ptr__ = darray_geom2mesh_data_get(&scn->geom2mesh)[ray.geomID]; + ASSERT((unsigned)ray.geomID < darray_mesh_size_get(&scn->meshes)); + hit->prim.ptr__ = darray_mesh_data_get(&scn->meshes)[ray.geomID]; hit->prim.iprim__ = ray.primID; hit->prim.igeom__ = RTC_INVALID_GEOMETRY_ID; } else { /* The hit shape is instantiated */ /* Retrieve the hit instance */ - ASSERT((unsigned)ray.instID < darray_geom2inst_size_get(&scn->geom2inst)); - hit->prim.ptr__ = darray_geom2inst_data_get(&scn->geom2inst)[ray.instID]; + ASSERT((unsigned)ray.instID < darray_inst_size_get(&scn->instances)); + hit->prim.ptr__ = darray_inst_data_get(&scn->instances)[ray.instID]; hit->prim.igeom__ = ray.geomID; hit->prim.iprim__ = ray.primID; } diff --git a/src/s3d_scene_c.h b/src/s3d_scene_c.h @@ -40,19 +40,23 @@ #include <rsys/list.h> #include <rsys/ref_count.h> -#define DARRAY_NAME geom2mesh +/* Generate the darray_mesh dynamic array */ +#define DARRAY_NAME mesh #define DARRAY_DATA struct mesh* #include <rsys/dynamic_array.h> -#define DARRAY_NAME geom2inst +/* Generate the darray_inst dynamic array */ +#define DARRAY_NAME inst #define DARRAY_DATA struct instance* #include <rsys/dynamic_array.h> +/* Generate the htable_mesh hash table */ #define HTABLE_NAME mesh #define HTABLE_DATA struct mesh* #define HTABLE_KEY struct s3d_shape* #include <rsys/hash_table.h> +/* Generate the htable_instance hash table */ #define HTABLE_NAME inst #define HTABLE_DATA struct instance* #define HTABLE_KEY struct s3d_shape* @@ -66,10 +70,13 @@ enum build_type { struct s3d_scene { struct list_node shapes; /* List of attached shapes */ - struct htable_mesh meshes; /* List of meshes associated to a shape */ - struct htable_inst instances; /* List of instances associated to a shape */ - struct darray_geom2mesh geom2mesh; /* Map an Embree geometry to a mesh */ - struct darray_geom2inst geom2inst; /* Map an Embree geometry to an instance */ + struct htable_mesh cached_meshes; /* Cached shape meshes */ + struct htable_inst cached_instances; /* Cached shape instances */ + + /* Active geometry. Indexed by the Embree identifier */ + struct darray_mesh meshes; + struct darray_inst instances; + RTCScene rtc_scn; char is_rtc_scn_outdated; @@ -84,8 +91,8 @@ scene_get_mesh(struct s3d_scene* scn, const unsigned igeom) { struct mesh* mesh; ASSERT(scn && igeom != RTC_INVALID_GEOMETRY_ID); - ASSERT(igeom < darray_geom2mesh_size_get(&scn->geom2mesh)); - mesh = darray_geom2mesh_data_get(&scn->geom2mesh)[igeom]; + ASSERT(igeom < darray_mesh_size_get(&scn->meshes)); + mesh = darray_mesh_data_get(&scn->meshes)[igeom]; ASSERT(mesh); return mesh; }