solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 1552e43034d631aa255b519b7e10bfa03a549e60
parent 1ccc9fb447914e2f9c28062687c625f5baa19764
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 18 Jul 2016 14:50:15 +0200

Update the management of Star-3D resources

The shape owns only the Star-3D shape. The object instance defines a
Star-3D shape instantiated the Star-3D scene of the object in which
the Star-3D shape of the shape is attached.

Diffstat:
Msrc/ssol_object.c | 13++++++++++---
Msrc/ssol_object_c.h | 2++
Msrc/ssol_object_instance.c | 23++++++++++++++++++++++-
Msrc/ssol_object_instance_c.h | 6++++++
Msrc/ssol_shape.c | 19+++++++------------
Msrc/ssol_shape_c.h | 10++++++++--
Msrc/ssol_solver.c | 6++++--
Msrc/ssol_solver_c.h | 2++
8 files changed, 61 insertions(+), 20 deletions(-)

diff --git a/src/ssol_object.c b/src/ssol_object.c @@ -14,8 +14,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "ssol.h" -#include "ssol_object_c.h" #include "ssol_device_c.h" +#include "ssol_object_c.h" +#include "ssol_shape_c.h" #include <rsys/rsys.h> #include <rsys/mem_allocator.h> @@ -34,6 +35,7 @@ object_release(ref_T* ref) ASSERT(dev && dev->allocator); SSOL(shape_ref_put(object->shape)); SSOL(material_ref_put(object->material)); + if(object->s3d_scn) S3D(scene_ref_put(object->s3d_scn)); MEM_RM(dev->allocator, object); SSOL(device_ref_put(dev)); } @@ -70,9 +72,7 @@ ssol_object_create res = RES_MEM_ERR; goto error; } - /* Check if material/shape association is legit: TODO */ - SSOL(shape_ref_get(shape)); SSOL(material_ref_get(material)); SSOL(device_ref_get(dev)); @@ -81,6 +81,13 @@ ssol_object_create object->material = material; ref_init(&object->ref); + /* Create the Star-3D scene to instantiate through the object instance */ + res = s3d_scene_create(dev->s3d, &object->s3d_scn); + if(res != RES_OK) goto error; + res = s3d_scene_attach_shape + (object->s3d_scn, shape_get_s3d_shape(object->shape)); + if(res != RES_OK) goto error; + exit: if (out_object) *out_object = object; return res; diff --git a/src/ssol_object_c.h b/src/ssol_object_c.h @@ -22,6 +22,8 @@ struct ssol_object { struct ssol_shape* shape; struct ssol_material* material; + struct s3d_scene* s3d_scn; /* Scene to instantiate */ + struct ssol_device* dev; ref_T ref; }; diff --git a/src/ssol_object_instance.c b/src/ssol_object_instance.c @@ -38,6 +38,7 @@ object_instance_release(ref_T* ref) dev = instance->dev; ASSERT(dev && dev->allocator); SSOL(object_ref_put(instance->object)); + if(instance->shape) S3D(shape_ref_put(instance->shape)); MEM_RM(dev->allocator, instance->receiver_name); MEM_RM(dev->allocator, instance); SSOL(device_ref_put(dev)); @@ -53,6 +54,8 @@ ssol_object_instantiate { struct ssol_object_instance* instance = NULL; struct ssol_device* dev; + struct s3d_scene* scn = NULL; + res_T res = RES_OK; if (!object || !out_instance) { res = RES_BAD_ARG; @@ -75,8 +78,13 @@ ssol_object_instantiate SSOL(device_ref_get(dev)); ref_init(&instance->ref); + /* Create the Star-3D instance */ + res = s3d_scene_instantiate(object->s3d_scn, &instance->shape); + if(res != RES_OK) goto error; + exit: - if (out_instance) *out_instance = instance; + if(scn) S3D(scene_ref_put(scn)); + if(out_instance) *out_instance = instance; return res; error: if (instance) { @@ -144,3 +152,16 @@ ssol_object_instance_is_attached return RES_OK; } + +/******************************************************************************* + * Local functions + ******************************************************************************/ +unsigned +object_instance_get_s3d_id(const struct ssol_object_instance* instance) +{ + unsigned id; + ASSERT(instance); + S3D(shape_get_id(instance->shape, &id)); + return id; +} + diff --git a/src/ssol_object_instance_c.h b/src/ssol_object_instance_c.h @@ -22,6 +22,7 @@ struct ssol_object_instance { struct ssol_object* object; /* Instantiated object */ double transform[12]; /* Object to world 3x4 column major affine transform */ + struct s3d_shape* shape; /* Instantiated Star-3D shape */ struct list_node scene_attachment; char* receiver_name; /* NULL if not a receiver */ @@ -30,4 +31,9 @@ struct ssol_object_instance { ref_T ref; }; +/* Return the Star-3D identifier of the object instance */ +extern LOCAL_SYM unsigned +object_instance_get_s3d_id + (const struct ssol_object_instance* instance); + #endif /* SSOL_OBJECT_INSTANCE_C_H */ diff --git a/src/ssol_shape.c b/src/ssol_shape.c @@ -33,8 +33,7 @@ shape_release(ref_T* ref) ASSERT(ref); dev = shape->dev; ASSERT(dev && dev->allocator); - S3D(shape_ref_put(shape->shape)); - S3D(scene_ref_put(shape->scene)); + if(shape->s3d_shape) S3D(shape_ref_put(shape->s3d_shape)); MEM_RM(dev->allocator, shape->quadric); MEM_RM(dev->allocator, shape); SSOL(device_ref_put(dev)); @@ -152,7 +151,6 @@ shape_ok(const struct ssol_shape* shape) { if(!shape || !shape->dev - || !shape->scene || SHAPE_FIRST_TYPE > shape->type || shape->type > SHAPE_LAST_TYPE) return RES_BAD_ARG; @@ -186,12 +184,9 @@ shape_create } /* create a s3d_scene to hold a mesh */ - res = s3d_shape_create_mesh(dev->s3d, &shape->shape); - if (res != RES_OK) goto error; - res = s3d_scene_create(dev->s3d, &shape->scene); - if (res != RES_OK) goto error; - res = s3d_scene_attach_shape(shape->scene, shape->shape); - + res = s3d_shape_create_mesh(dev->s3d, &shape->s3d_shape); + if(res != RES_OK) goto error; + SSOL(device_ref_get(dev)); shape->dev = dev; ref_init(&shape->ref); @@ -258,7 +253,7 @@ ssol_punched_surface_setup if(shape->type != SHAPE_PUNCHED) return RES_BAD_ARG; ASSERT(shape->ref); - ASSERT(shape->dev && shape->dev->allocator && shape->scene); + ASSERT(shape->dev && shape->dev->allocator); /* save quadric for further object instancing */ MEM_RM(shape->dev->allocator, shape->quadric); @@ -294,7 +289,7 @@ ssol_mesh_setup return RES_BAD_ARG; } ASSERT(shape->ref); - ASSERT(shape->dev && shape->dev->allocator && shape->scene); + ASSERT(shape->dev && shape->dev->allocator); attrib3 = (struct s3d_vertex_data*)MEM_CALLOC (shape->dev->allocator, nattribs, sizeof(struct s3d_vertex_data)); @@ -323,7 +318,7 @@ ssol_mesh_setup } } res = s3d_mesh_setup_indexed_vertices - (shape->shape, ntris, get_indices, nverts, attrib3, nattribs, data); + (shape->s3d_shape, ntris, get_indices, nverts, attrib3, nattribs, data); MEM_RM(shape->dev->allocator, attrib3); return res; } diff --git a/src/ssol_shape_c.h b/src/ssol_shape_c.h @@ -29,12 +29,18 @@ enum shape_type { struct ssol_shape { enum shape_type type; - struct s3d_shape* shape; /* 3D shape for the mesh */ - struct s3d_scene* scene; /* 3D scene for shape instantiation */ + struct s3d_shape* s3d_shape; /* 3D shape for the mesh */ struct ssol_quadric* quadric; /* NULL if type != SHAPE_PUNCHED */ struct ssol_device* dev; ref_T ref; }; +static FINLINE struct s3d_shape* +shape_get_s3d_shape(struct ssol_shape* shape) +{ + ASSERT(shape); + return shape->s3d_shape; +} + #endif /* SSOL_SHAPE_C_H */ diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -116,6 +116,8 @@ is_instance_punched return instance->object->shape->type == SHAPE_PUNCHED; } +/* FIXME Dead code. Remove it? */ +#if 0 static const struct ssol_quadric* get_quadric (const struct ssol_object_instance* instance) { @@ -137,8 +139,6 @@ get_transform(const struct ssol_object_instance* instance) return instance->transform; } -/* FIXME Dead code. Remove it? */ -#if 0 static res_T init_solver_data (struct solver_data* data, @@ -288,6 +288,7 @@ quadric_transform return RES_OK; } +#if 0 res_T process_instances (const struct ssol_scene* scene, @@ -341,3 +342,4 @@ error: S3D(scene_ref_put(data->scene)); goto exit; } +#endif diff --git a/src/ssol_solver_c.h b/src/ssol_solver_c.h @@ -49,10 +49,12 @@ set_sun_distributions (const struct ssol_sun* sun, struct solver_data* data); +#if 0 extern LOCAL_SYM res_T process_instances (const struct ssol_scene* scene, struct solver_data* data); +#endif /* transform a single quadric in world space */ extern LOCAL_SYM res_T