commit 4202e4dc49a3d0ebe652afd36b6af35d36ac6c00
parent 075fc57755d581e2d250bce07caf61435681af7d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 20 Mar 2015 12:03:48 +0100
Clean up the s3d API
Diffstat:
4 files changed, 72 insertions(+), 78 deletions(-)
diff --git a/src/s3d.h b/src/s3d.h
@@ -277,7 +277,7 @@ s3d_shape_sample
/* Set/update the data of the triangular meshes. Can be invoked only on shape
* created with the s3d_shape_create_mesh function */
S3D_API res_T
-s3d_shape_mesh_setup_indexed_vertices
+s3d_mesh_setup_indexed_vertices
(struct s3d_shape* shape,
const unsigned ntris,
void (*get_indices) /* May be S3D_KEEP, i.e. do not update the indices */
@@ -289,21 +289,15 @@ s3d_shape_mesh_setup_indexed_vertices
struct s3d_vertex_data attribs[],
void* data); /* Client data set as the last param of the vertex callbacks */
-/* Setup the shape from a scene. Actually the resulting shape is an instance of
- * the scene. Can be invoked only on a shape created with the
- * s3d_shape_create_group function */
+/* Can be invoked only on a shape instantioed with s3d_scene_instantiate */
S3D_API res_T
-s3d_shape_instance_setup_scene
- (struct s3d_shape* shape,
- struct s3d_scene* scene);
-
-S3D_API res_T
-s3d_shape_instance_set_position
+s3d_instance_set_position
(struct s3d_shape* shape,
const float position[3]);
+/* Can be invoked only on a shape instantioed with s3d_scene_instantiate */
S3D_API res_T
-s3d_shape_instance_translate
+s3d_instance_translate
(struct s3d_shape* shape,
const enum s3d_transform_space space,
const float translation[3]);
diff --git a/src/s3d_shape.c b/src/s3d_shape.c
@@ -378,7 +378,7 @@ s3d_shape_detach(struct s3d_shape* shape)
}
res_T
-s3d_shape_instance_set_position
+s3d_instance_set_position
(struct s3d_shape* shape, const float position[3])
{
float axis[3];
@@ -399,7 +399,7 @@ s3d_shape_instance_set_position
}
res_T
-s3d_shape_instance_translate
+s3d_instance_translate
(struct s3d_shape* shape,
const enum s3d_transform_space space,
const float translation[3])
@@ -433,7 +433,7 @@ s3d_shape_instance_translate
}
res_T
-s3d_shape_mesh_setup_indexed_vertices
+s3d_mesh_setup_indexed_vertices
(struct s3d_shape* shape,
const unsigned ntris,
void (*get_indices)(const unsigned itri, unsigned ids[3], void* ctx),
diff --git a/src/test_s3d_shape.c b/src/test_s3d_shape.c
@@ -83,144 +83,144 @@ main(int argc, char** argv)
attribs[0].usage = S3D_POSITION;
attribs[0].get = cbox_get_position;
attribs[1] = S3D_VERTEX_DATA_NULL;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, NULL, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, NULL, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, NULL, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, NULL, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, cbox_get_ids, 0, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, NULL, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, cbox_get_ids, cbox_nverts, NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, NULL, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, NULL, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, NULL, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, NULL, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, cbox_get_ids, 0, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, NULL, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, 0, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 0, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(NULL, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_OK);
attribs[0] = S3D_VERTEX_DATA_NULL;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_BAD_ARG);
attribs[0].type = S3D_FLOAT3;
attribs[0].usage = S3D_POSITION;
attribs[0].get = S3D_KEEP;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_OK);
attribs[0].get = cbox_get_position;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
attribs[0].type = S3D_FLOAT3;
attribs[0].usage = S3D_ATTRIB_0;
attribs[0].get = cbox_get_normal;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_BAD_ARG);
attribs[1].type = S3D_FLOAT3;
attribs[1].usage = S3D_POSITION;
attribs[1].get = S3D_KEEP;
attribs[2] = S3D_VERTEX_DATA_NULL;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
attribs[2].type = S3D_FLOAT2;
attribs[2].usage = S3D_ATTRIB_2;
attribs[2].get = cbox_get_uv;
attribs[3] = S3D_VERTEX_DATA_NULL;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
attribs[0].get = S3D_KEEP;
attribs[1].get = S3D_KEEP;
attribs[2].get = S3D_KEEP;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, 2, S3D_KEEP, cbox_nverts, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts+1, attribs, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
attribs[2].type = S3D_FLOAT3;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_BAD_ARG);
attribs[0].get = cbox_get_position;
attribs[2] = S3D_VERTEX_DATA_NULL;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, S3D_KEEP, cbox_nverts, attribs, NULL), RES_OK);
CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
CHECK(s3d_scene_instantiate(scn, &inst), RES_OK);
- CHECK(s3d_shape_instance_set_position(NULL, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_instance_set_position(inst, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_instance_set_position(NULL, pos), RES_BAD_ARG);
- CHECK(s3d_shape_instance_set_position(inst, pos), RES_OK);
- CHECK(s3d_shape_instance_set_position(shape, pos), RES_BAD_ARG);
-
- CHECK(s3d_shape_instance_translate(NULL, -1, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_instance_translate(inst, -1, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_instance_translate(NULL, S3D_LOCAL_TRANSFORM, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_instance_translate(inst, S3D_LOCAL_TRANSFORM, NULL), RES_BAD_ARG);
- CHECK(s3d_shape_instance_translate(NULL, -1, pos), RES_BAD_ARG);
- CHECK(s3d_shape_instance_translate(inst, -1, pos), RES_BAD_ARG);
- CHECK(s3d_shape_instance_translate(NULL, S3D_LOCAL_TRANSFORM, pos), RES_BAD_ARG);
- CHECK(s3d_shape_instance_translate(inst, S3D_LOCAL_TRANSFORM, pos), RES_OK);
- CHECK(s3d_shape_instance_translate(inst, S3D_WORLD_TRANSFORM, pos), RES_OK);
- CHECK(s3d_shape_instance_translate(shape, S3D_WORLD_TRANSFORM, pos), RES_BAD_ARG);
+ CHECK(s3d_instance_set_position(NULL, NULL), RES_BAD_ARG);
+ CHECK(s3d_instance_set_position(inst, NULL), RES_BAD_ARG);
+ CHECK(s3d_instance_set_position(NULL, pos), RES_BAD_ARG);
+ CHECK(s3d_instance_set_position(inst, pos), RES_OK);
+ CHECK(s3d_instance_set_position(shape, pos), RES_BAD_ARG);
+
+ CHECK(s3d_instance_translate(NULL, -1, NULL), RES_BAD_ARG);
+ CHECK(s3d_instance_translate(inst, -1, NULL), RES_BAD_ARG);
+ CHECK(s3d_instance_translate(NULL, S3D_LOCAL_TRANSFORM, NULL), RES_BAD_ARG);
+ CHECK(s3d_instance_translate(inst, S3D_LOCAL_TRANSFORM, NULL), RES_BAD_ARG);
+ CHECK(s3d_instance_translate(NULL, -1, pos), RES_BAD_ARG);
+ CHECK(s3d_instance_translate(inst, -1, pos), RES_BAD_ARG);
+ CHECK(s3d_instance_translate(NULL, S3D_LOCAL_TRANSFORM, pos), RES_BAD_ARG);
+ CHECK(s3d_instance_translate(inst, S3D_LOCAL_TRANSFORM, pos), RES_OK);
+ CHECK(s3d_instance_translate(inst, S3D_WORLD_TRANSFORM, pos), RES_OK);
+ CHECK(s3d_instance_translate(shape, S3D_WORLD_TRANSFORM, pos), RES_BAD_ARG);
CHECK(s3d_shape_ref_get(NULL), RES_BAD_ARG);
CHECK(s3d_shape_ref_get(shape), RES_OK);
diff --git a/src/test_s3d_trace_ray.c b/src/test_s3d_trace_ray.c
@@ -115,7 +115,7 @@ main(int argc, char** argv)
attribs[0].get = cbox_get_position;
attribs[1] = S3D_VERTEX_DATA_NULL;
- CHECK(s3d_shape_mesh_setup_indexed_vertices
+ CHECK(s3d_mesh_setup_indexed_vertices
(shape, cbox_ntris, cbox_get_ids, cbox_nverts, attribs, NULL), RES_OK);
CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
@@ -163,25 +163,25 @@ main(int argc, char** argv)
CHECK(s3d_shape_ref_put(shape), RES_OK);
CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
- CHECK(s3d_shape_instance_set_position(shape, org), RES_OK);
+ CHECK(s3d_instance_set_position(shape, org), RES_OK);
f3(org, 3.f, 0.f, -551.f);
CHECK(s3d_shape_ref_put(shape), RES_OK);
CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
- CHECK(s3d_shape_instance_set_position(shape, org), RES_OK);
+ CHECK(s3d_instance_set_position(shape, org), RES_OK);
f3(org, -555.f, 0.f, 3.f);
CHECK(s3d_shape_ref_put(shape), RES_OK);
CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
- CHECK(s3d_shape_instance_set_position(shape, org), RES_OK);
+ CHECK(s3d_instance_set_position(shape, org), RES_OK);
f3(org, 3.f, 0.f, 3.f);
CHECK(s3d_shape_ref_put(shape), RES_OK);
CHECK(s3d_scene_instantiate(scn, &shape), RES_OK);
CHECK(s3d_scene_attach_shape(scn2, shape), RES_OK);
- CHECK(s3d_shape_instance_set_position(shape, org), RES_OK);
+ CHECK(s3d_instance_set_position(shape, org), RES_OK);
CHECK(s3d_scene_build(scn2), RES_OK);