commit f81164c51be1cdf0c2ca5190235f566aff9a41a4
parent 2e713d35bd0a515428e003fee7768d11a87a91dc
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 14 Apr 2016 11:02:06 +0200
Add the s3daw_<attach|detach>_shapes_<to|from>_scene functions
Diffstat:
3 files changed, 79 insertions(+), 4 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -56,8 +56,8 @@ include(rcmake_runtime)
# Configure and define targets
################################################################################
set(VERSION_MAJOR 0)
-set(VERSION_MINOR 1)
-set(VERSION_PATCH 2)
+set(VERSION_MINOR 3)
+set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(S3DAW_FILES_SRC s3daw.c)
diff --git a/src/s3daw.c b/src/s3daw.c
@@ -337,7 +337,7 @@ shapes_create(struct s3daw* s3daw, const char* filename)
} else {
size_t imtllib;
size_t dirname_len;
-
+
/* Setup the `mtllib' buffer with the directory of the filename */
res = get_dirname(filename, &s3daw->mtllib);
if(res != RES_OK) goto error;
@@ -583,3 +583,65 @@ s3daw_get_shape(struct s3daw* s3daw, const size_t ishape, struct s3d_shape** sha
return RES_OK;
}
+res_T
+s3daw_attach_shapes_to_scene(struct s3daw* s3daw, struct s3d_scene* scene)
+{
+ struct s3d_shape* shape = NULL;
+ size_t i=0, n=0;
+ res_T res = RES_OK;
+
+ if(!s3daw) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ S3DAW(get_shapes_count(s3daw, &n));
+ FOR_EACH(i, 0, n) {
+ S3DAW(get_shape(s3daw, i, &shape));
+ res = s3d_scene_attach_shape(scene, shape);
+ if(res != RES_OK) goto error;
+ }
+
+exit:
+ return res;
+error:
+ /* Rollback the attachments */
+ n = i;
+ FOR_EACH(i, 0, n) {
+ S3DAW(get_shape(s3daw, i, &shape));
+ S3D(scene_detach_shape(scene, shape));
+ }
+ goto exit;
+}
+
+res_T
+s3daw_detach_shapes_from_scene(struct s3daw* s3daw, struct s3d_scene* scene)
+{
+ struct s3d_shape* shape = NULL;
+ size_t i=0, n=0;
+ res_T res = RES_OK;
+
+ if(!s3daw) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ S3DAW(get_shapes_count(s3daw, &n));
+ FOR_EACH(i, 0, n) {
+ S3DAW(get_shape(s3daw, i, &shape));
+ res = s3d_scene_detach_shape(scene, shape);
+ if(res != RES_OK) goto error;
+ }
+
+exit:
+ return res;
+error:
+ /* Rollback the detachments */
+ n = i;
+ FOR_EACH(i, 0, n) {
+ S3DAW(get_shape(s3daw, i, &shape));
+ S3D(scene_attach_shape(scene, shape));
+ }
+ goto exit;
+}
+
diff --git a/src/s3daw.h b/src/s3daw.h
@@ -40,7 +40,7 @@
#define S3DAW_API extern IMPORT_SYM
#endif
-/* Helper macro that asserts if the invocation of the srdr function `Func'
+/* Helper macro that asserts if the invocation of the s3daw function `Func'
* returns an error. One should use this macro on smc function calls for which
* no explicit error checking is performed */
#ifndef NDEBUG
@@ -56,6 +56,7 @@ struct logger;
struct mem_allocator;
struct s3d_device;
struct s3d_shape;
+struct s3d_scene;
/* Forward declaration *of opaque s3daw types */
struct s3daw;
@@ -115,6 +116,18 @@ s3daw_get_shape
const size_t ishape, /* in [0, s3d_get_shapes_count) */
struct s3d_shape** shape);
+/* Attach the loaded s3d shapes to the submitted scene. */
+S3DAW_API res_T
+s3daw_attach_shapes_to_scene
+ (struct s3daw* s3daw,
+ struct s3d_scene* scene);
+
+/* Detach the loaded s3d shapes from the submitted scene. */
+S3DAW_API res_T
+s3daw_detach_shapes_from_scene
+ (struct s3daw* s3daw,
+ struct s3d_scene* scene);
+
END_DECLS
#endif /* S3DAW_H */