commit 20bc8f1d138782a48a2dc41f047a293d9d7c6c16
parent 1d52623d71d06baaff9c5bc182db71c6ab75e6c6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 27 Mar 2015 14:57:15 +0100
Implement and test the s3d_shape_<enable|is_enabled> functions
Diffstat:
9 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/src/s3d.h b/src/s3d.h
@@ -263,6 +263,12 @@ s3d_shape_enable
(struct s3d_shape* shape,
const char enable);
+/* Return whether or not the shape is enabled, i.e. ray-traced. Default is 1 */
+S3D_API res_T
+s3d_shape_is_enabled
+ (struct s3d_shape* shape,
+ char* is_enabled);
+
/* Define whether the shape is attached or not */
S3D_API res_T
s3d_shape_is_attached
diff --git a/src/s3d_instance.c b/src/s3d_instance.c
@@ -75,6 +75,7 @@ instance_create
f33_set_identity(inst->transform); /* rotation */
f3_splat(inst->transform + 9, 0.f); /* Translation */
inst->update_transform = 0;
+ inst->is_enabled = 1;
inst->rtc_geom = RTC_INVALID_GEOMETRY_ID;
ref_init(&inst->ref);
S3D(scene_ref_get(scn));
diff --git a/src/s3d_instance.h b/src/s3d_instance.h
@@ -39,6 +39,7 @@ struct instance {
float transform[12]; /* local to world 3x4 column major matrix */
char update_transform;
+ char is_enabled;
unsigned rtc_geom;
struct s3d_scene* scene;
diff --git a/src/s3d_mesh.c b/src/s3d_mesh.c
@@ -236,6 +236,7 @@ mesh_create(struct s3d_device* dev, struct mesh** out_mesh)
goto error;
}
mesh->rtc_geom = RTC_INVALID_GEOMETRY_ID;
+ mesh->is_enabled = 1;
ref_init(&mesh->ref);
S3D(device_ref_get(dev));
mesh->dev = dev;
diff --git a/src/s3d_mesh.h b/src/s3d_mesh.h
@@ -64,6 +64,7 @@ struct mesh { /* Triangular mesh */
int resize_mask; /* Combination of buffer_type */
int update_mask; /* Combination of buffer_type */
+ char is_enabled;
unsigned rtc_geom; /* Embree geometry */
struct s3d_device* dev;
diff --git a/src/s3d_scene.c b/src/s3d_scene.c
@@ -221,6 +221,17 @@ scene_setup_shape_mesh
scn->is_rtc_scn_outdated = 1;
}
+ /* Setup the is_enabled state */
+ if(mesh->is_enabled != shape->data.mesh->is_enabled) {
+ mesh->is_enabled = shape->data.mesh->is_enabled;
+ if(shape->data.mesh->is_enabled) {
+ rtcEnable(scn->rtc_scn, mesh->rtc_geom);
+ } else {
+ rtcDisable(scn->rtc_scn, mesh->rtc_geom);
+ }
+ scn->is_rtc_scn_outdated = 1;
+ }
+
/* Flush the shape mesh states */
shape->data.mesh->resize_mask = 0;
shape->data.mesh->update_mask = 0;
@@ -278,6 +289,17 @@ scene_setup_shape_instance(struct s3d_scene* scn, struct s3d_shape* shape)
scn->is_rtc_scn_outdated = 1;
}
+ /* Setup the is_enabled state */
+ if(inst->is_enabled != shape->data.instance->is_enabled) {
+ inst->is_enabled = shape->data.instance->is_enabled;
+ if(shape->data.instance->is_enabled) {
+ rtcEnable(scn->rtc_scn, inst->rtc_geom);
+ } else {
+ rtcDisable(scn->rtc_scn, inst->rtc_geom);
+ }
+ scn->is_rtc_scn_outdated = 1;
+ }
+
shape->data.instance->update_transform = 0; /* Flush instance state */
exit:
diff --git a/src/s3d_shape.c b/src/s3d_shape.c
@@ -165,6 +165,30 @@ s3d_shape_ref_put(struct s3d_shape* shape)
}
res_T
+s3d_shape_enable(struct s3d_shape* shape, const char enable)
+{
+ if(!shape) return RES_BAD_ARG;
+ switch(shape->type) {
+ case SHAPE_MESH: shape->data.mesh->is_enabled = enable; break;
+ case SHAPE_INSTANCE: shape->data.instance->is_enabled = enable; break;
+ default: FATAL("Unreachable code\n"); break;
+ }
+ return RES_OK;
+}
+
+res_T
+s3d_shape_is_enabled(struct s3d_shape* shape, char* is_enabled)
+{
+ if(!shape || !is_enabled) return RES_BAD_ARG;
+ switch(shape->type) {
+ case SHAPE_MESH: *is_enabled = shape->data.mesh->is_enabled; break;
+ case SHAPE_INSTANCE: *is_enabled = shape->data.instance->is_enabled; break;
+ default: FATAL("Unreachable code\n"); break;
+ }
+ return RES_OK;
+}
+
+res_T
s3d_shape_is_attached(struct s3d_shape* shape, char* is_attached)
{
if(!shape || !is_attached)
@@ -184,6 +208,7 @@ s3d_shape_sample
return RES_BAD_ARG;
/* TODO */
(void)u, (void)v, (void)w;
+ ASSERT(0);
return RES_OK;
}
diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c
@@ -202,6 +202,17 @@ main(int argc, char** argv)
CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, data), RES_OK);
+ CHECK(s3d_shape_is_enabled(NULL, NULL), RES_BAD_ARG);
+ CHECK(s3d_shape_is_enabled(shape, NULL), RES_BAD_ARG);
+ CHECK(s3d_shape_is_enabled(NULL, &c), RES_BAD_ARG);
+ CHECK(s3d_shape_is_enabled(shape, &c), RES_OK);
+ NCHECK(c, 0);
+
+ CHECK(s3d_shape_enable(NULL, 0), RES_BAD_ARG);
+ CHECK(s3d_shape_enable(shape, 0), RES_OK);
+ CHECK(s3d_shape_is_enabled(shape, &c), RES_OK);
+ CHECK(c, 0);
+
CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
CHECK(s3d_scene_instantiate(scn, &inst), RES_OK);
diff --git a/src/test_s3d_trace_ray.c b/src/test_s3d_trace_ray.c
@@ -208,6 +208,8 @@ main(int argc, char** argv)
CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
CHECK(s3d_instance_set_position(shape, org), RES_OK);
+ CHECK(s3d_shape_enable(shape, 0), RES_OK);
+
CHECK(s3d_scene_begin_trace(scn), RES_OK);
CHECK(s3d_scene_begin_trace(scn2), RES_BAD_OP);
CHECK(s3d_scene_end_trace(scn), RES_OK);
@@ -215,6 +217,10 @@ main(int argc, char** argv)
CHECK(s3d_scene_begin_trace(scn), RES_BAD_OP);
CHECK(s3d_scene_end_trace(scn), RES_BAD_OP);
+ CHECK(s3d_scene_end_trace(scn2), RES_OK);
+ CHECK(s3d_shape_enable(shape, 1), RES_OK);
+ CHECK(s3d_scene_begin_trace(scn2), RES_OK);
+
camera_init(&cam);
FOR_EACH(iy, 0, IMG_HEIGHT) {
float pixel[2];