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 603200b99ce82ab9e80a3c2e7bd7e6348cf88065
parent c996e621aeec7c95b8bbe9df0c041f7f3f4a8436
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 29 Jun 2015 10:41:39 +0200

The sampler handles the shape `enable' state

Disabled shapes are no more sampled. Furthermore, if no shape is enabled,
the s3d_sample_begin function returns a RES_BAD_ARG error and print a
message if the verbose mode is enabled.

Diffstat:
Msrc/s3d_sampler.c | 41++++++++++++++++++++++++++++++++++++-----
Msrc/test_s3d_sampler.c | 12+++++++++++-
2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/src/s3d_sampler.c b/src/s3d_sampler.c @@ -37,6 +37,7 @@ #include <rsys/dynamic_array_float.h> #include <rsys/dynamic_array_size_t.h> #include <rsys/float33.h> +#include <rsys/logger.h> #include <algorithm> @@ -247,6 +248,7 @@ static res_T sampler_cache_mesh(struct s3d_sampler* sampler, char* upd_geom) { struct mesh* mesh; + char is_enabled; res_T res = RES_OK; ASSERT(sampler && sampler->shape->type == SHAPE_MESH && upd_geom); @@ -256,6 +258,15 @@ sampler_cache_mesh(struct s3d_sampler* sampler, char* upd_geom) goto error; } + if(!(S3D(shape_is_enabled(sampler->shape, &is_enabled)), is_enabled)) { + if(sampler->shape->dev->verbose) { + logger_print(sampler->shape->dev->logger, LOG_ERROR, + "Couldn't sample anything. The mesh to sample is disabled\n"); + } + res = RES_BAD_ARG; + goto error; + } + if(darray_mesh_size_get(&sampler->cached_meshes)) { /* Fetch the cached entry */ mesh = darray_mesh_data_get(&sampler->cached_meshes)[0]; @@ -287,6 +298,16 @@ sampler_cache_instance(struct s3d_sampler* sampler, char* upd_geom) res_T res = RES_OK; ASSERT(sampler && sampler->shape->type == SHAPE_INSTANCE && upd_geom); + /* Check that the instance is ready to be sampled, i.e. it is enabled */ + if(!sampler->shape->data.instance->geom.is_enabled) { + if(sampler->shape->dev->verbose) { + logger_print(sampler->shape->dev->logger, LOG_ERROR, + "Couldn't sample anything. The instance to sample is disabled\n"); + } + res = RES_BAD_ARG; + goto error; + } + f33_set /* Cache the instance rotation */ (sampler->cached_instance->transform, sampler->shape->data.instance->transform); @@ -295,10 +316,15 @@ sampler_cache_instance(struct s3d_sampler* sampler, char* upd_geom) sampler->shape->data.instance->transform + 9); LIST_FOR_EACH(node, &sampler->shape->data.instance->scene->shapes) { + char is_enabled; struct s3d_shape* shape = CONTAINER_OF (node, struct s3d_shape, scene_attachment); ASSERT(shape->type == SHAPE_MESH); + /* Discard disabled shapes */ + if(!(S3D(shape_is_enabled(shape, &is_enabled)), is_enabled)) + continue; + /* Discard shapes with no geometry */ if(!shape->data.mesh->indices || !shape->data.mesh->attribs[S3D_POSITION]) @@ -320,16 +346,21 @@ sampler_cache_instance(struct s3d_sampler* sampler, char* upd_geom) } nshapes = ishape; - /* Flush the "no more in use" cache entries */ - FOR_EACH(ishape, ishape, darray_mesh_size_get(&sampler->cached_meshes)) - mesh_ref_put(darray_mesh_data_get(&sampler->cached_meshes)[ishape]); - darray_mesh_resize(&sampler->cached_meshes, nshapes); - if(!nshapes) { + if(sampler->shape->dev->verbose) { + logger_print(sampler->shape->dev->logger, LOG_ERROR, + "Couldn't sample anything. " + "All instantiated shapes to sample are disabled\n"); + } res = RES_BAD_ARG; goto error; } + /* Flush the "no more in use" cache entries */ + FOR_EACH(ishape, ishape, darray_mesh_size_get(&sampler->cached_meshes)) + mesh_ref_put(darray_mesh_data_get(&sampler->cached_meshes)[ishape]); + darray_mesh_resize(&sampler->cached_meshes, nshapes); + /* TODO take into account the scale transformation in the upd_geom flag */ *upd_geom = *upd_geom || (nshapes != ishape); diff --git a/src/test_s3d_sampler.c b/src/test_s3d_sampler.c @@ -68,7 +68,7 @@ main(int argc, char** argv) mem_init_proxy_allocator(&allocator, &mem_default_allocator); - CHECK(s3d_device_create(NULL, &allocator, 0, &dev), RES_OK); + CHECK(s3d_device_create(NULL, &allocator, 1, &dev), RES_OK); CHECK(s3d_scene_create(dev, &scn), RES_OK); CHECK(s3d_scene_instantiate(scn, &cbox), RES_OK); CHECK(s3d_shape_create_mesh(dev, &walls), RES_OK); @@ -128,6 +128,13 @@ main(int argc, char** argv) CHECK(s3d_sampler_end_sampling(NULL), RES_BAD_ARG); CHECK(s3d_sampler_end_sampling(sampler), RES_OK); + + CHECK(s3d_shape_enable(walls, 0), RES_OK); + CHECK(s3d_sampler_begin_sampling(sampler), RES_BAD_ARG); + CHECK(s3d_shape_enable(walls, 1), RES_OK); + CHECK(s3d_sampler_begin_sampling(sampler), RES_OK); + CHECK(s3d_sampler_end_sampling(sampler), RES_OK); + CHECK(s3d_sampler_end_sampling(sampler), RES_BAD_OP); CHECK(s3d_sampler_get(sampler, 0.5f, 0.5f, 0.5f, &prim, uv), RES_BAD_OP); @@ -168,6 +175,9 @@ main(int argc, char** argv) NCHECK(f3_eq_eps(attr0.value, attr1.value, 1.e-6f), 1); CHECK(s3d_sampler_end_sampling(sampler), RES_OK); + CHECK(s3d_shape_enable(cbox, 0), RES_OK); + CHECK(s3d_sampler_begin_sampling(sampler), RES_BAD_ARG); + CHECK(s3d_shape_enable(cbox, 1), RES_OK); CHECK(s3d_sampler_begin_sampling(sampler), RES_OK); FOR_EACH(i, 0, NSAMPS) { const float u = rand_canonic();