commit 9bccc772b1e8ec590b3063c3d455605ca3243942
parent d11fb15b71b267eb97a793d17c33f6db492d4538
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 19 Oct 2016 11:27:27 +0200
Remove the SGF shape data type
The scene geometry is directly defined through the SGF scene API as a
triangle soup.
Diffstat:
7 files changed, 212 insertions(+), 515 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -50,8 +50,7 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(SGF_FILES_SRC
sgf_device.c
sgf_estimator.c
- sgf_scene.c
- sgf_shape.c)
+ sgf_scene.c)
set(SGF_FILES_INC_API sgf.h)
set(SGF_FILES_INC
sgf_device_c.h
@@ -90,7 +89,6 @@ if(NOT NO_TEST)
new_test(test_sgf_device)
new_test(test_sgf_estimator)
new_test(test_sgf_scene3d)
- new_test(test_sgf_shape3d)
new_test(test_sgf_square)
new_test(test_sgf_tetrahedron)
rcmake_copy_runtime_libraries(test_sgf_tetrahedron)
diff --git a/src/sgf.h b/src/sgf.h
@@ -80,7 +80,7 @@ static const struct sgf_scene_desc SGF_SCENE_DESC_NULL = {
NULL, NULL, 0, 0, SGF_3D, { NULL }
};
-struct sgf_shape3d_desc {
+struct sgf_scene3d_desc {
void (*get_indices)(const unsigned itri, unsigned ids[3], void* ctx);
void (*get_position)(const unsigned ivert, float pos[3], void* ctx);
@@ -94,13 +94,13 @@ struct sgf_shape3d_desc {
(const unsigned itri, const unsigned iband, void* ctx);
void* context; /* User defined data */
- unsigned ntris; /* #triangles */
+ unsigned nprims; /* #primitives */
unsigned nverts; /* #vertices */
unsigned nbands; /* #spectral bands */
};
-#define SGF_SHAPE3D_DESC_NULL__ { 0 }
-static const struct sgf_shape3d_desc SGF_SHAPE3D_DESC_NULL =
- SGF_SHAPE3D_DESC_NULL__;
+#define SGF_SCENE3D_DESC_NULL__ { 0 }
+static const struct sgf_scene3d_desc SGF_SCENE3D_DESC_NULL =
+ SGF_SCENE3D_DESC_NULL__;
/* Estimated Gebart Factor between 2 faces */
struct sgf_status {
@@ -113,7 +113,6 @@ struct sgf_status {
/* Opaque types */
struct sgf_device;
struct sgf_estimator;
-struct sgf_shape;
struct sgf_scene;
/*******************************************************************************
@@ -137,27 +136,6 @@ sgf_device_ref_put
(struct sgf_device* dev);
/*******************************************************************************
- * Shape API
- ******************************************************************************/
-SGF_API res_T
-sgf_shape3d_create
- (struct sgf_device* device,
- struct sgf_shape** shape);
-
-SGF_API res_T
-sgf_shape_ref_get
- (struct sgf_shape* shape);
-
-SGF_API res_T
-sgf_shape_ref_put
- (struct sgf_shape* shape);
-
-SGF_API res_T
-sgf_shape3d_setup
- (struct sgf_shape* shape,
- const struct sgf_shape3d_desc* desc);
-
-/*******************************************************************************
* Scene API
******************************************************************************/
SGF_API res_T
@@ -174,18 +152,9 @@ sgf_scene_ref_put
(struct sgf_scene* scn);
SGF_API res_T
-sgf_scene_attach_shape
- (struct sgf_scene* scn,
- struct sgf_shape* shape);
-
-SGF_API res_T
-sgf_scene_detach_shape
+sgf_scene3d_setup
(struct sgf_scene* scn,
- struct sgf_shape* shape);
-
-SGF_API res_T
-sgf_scene_clear
- (struct sgf_scene* scn);
+ const struct sgf_scene3d_desc* desc);
/*******************************************************************************
* Integration API
diff --git a/src/sgf_scene.c b/src/sgf_scene.c
@@ -15,22 +15,26 @@
#include "sgf.h"
#include "sgf_device_c.h"
-#include "sgf_shape_c.h"
-#include <rsys/hash_table.h>
+#include <rsys/dynamic_array_double.h>
#include <rsys/ref_count.h>
#include <star/s3d.h>
-/* Define the htable_shape data structure */
-#define HTABLE_NAME shape
-#define HTABLE_KEY unsigned /* S3D object instance identifier */
-#define HTABLE_DATA struct sgf_shape*
-#include <rsys/hash_table.h>
+struct ray_data {
+ struct s3d_primitive prim_from;
+};
struct sgf_scene {
struct s3d_scene* s3d_scn;
- struct htable_shape shapes; /* Map S3D shape id to its SGF shape */
+ struct s3d_shape* s3d_shape;
+
+ struct darray_double abs; /* Per primitive absorption */
+ struct darray_double emi; /* Per primitive emissivity */
+ struct darray_double refl; /* Per primitive reflectivity */
+ struct darray_double spec; /* Per primitive specularity */
+ size_t nprims; /* #primitives */
+ size_t nbands; /* #spectral bands */
ref_T ref;
struct sgf_device* dev;
@@ -39,6 +43,39 @@ struct sgf_scene {
/*******************************************************************************
* Helper functions
******************************************************************************/
+static int
+hit_filter
+ (const struct s3d_hit* hit,
+ const float org[3],
+ const float dir[3],
+ void* ray_data,
+ void* filter_data)
+{
+ struct ray_data* rdata = ray_data;
+ (void)org, (void)dir, (void)filter_data;
+
+ if(!ray_data) return 0;
+ /* Discard primitive from which the ray starts from */
+ if(S3D_PRIMITIVE_EQ(&rdata->prim_from, &hit->prim)) return 1;
+ /* Ray starts on an edge and intersect the neighbor triangle */
+ if(hit->distance <= 0) return 1;
+ return 0;
+}
+
+static FINLINE int
+check_scene3d_desc(const struct sgf_scene3d_desc* desc)
+{
+ return desc
+ && desc->get_indices
+ && desc->get_emissivity
+ && desc->get_reflectivity
+ && desc->get_specularity
+ && desc->get_position
+ && desc->nprims
+ && desc->nverts
+ && desc->nbands;
+}
+
static void
scene_release(ref_T* ref)
{
@@ -47,9 +84,12 @@ scene_release(ref_T* ref)
ASSERT(ref);
scn = CONTAINER_OF(ref, struct sgf_scene, ref);
dev = scn->dev;
- SGF(scene_clear(scn));
if(scn->s3d_scn) S3D(scene_ref_put(scn->s3d_scn));
- htable_shape_release(&scn->shapes);
+ if(scn->s3d_shape) S3D(shape_ref_put(scn->s3d_shape));
+ darray_double_release(&scn->abs);
+ darray_double_release(&scn->emi);
+ darray_double_release(&scn->refl);
+ darray_double_release(&scn->spec);
MEM_RM(dev->allocator, scn);
SGF(device_ref_put(dev));
}
@@ -76,10 +116,22 @@ sgf_scene3d_create(struct sgf_device* dev, struct sgf_scene** out_scn)
ref_init(&scn->ref);
SGF(device_ref_get(dev));
scn->dev = dev;
- htable_shape_init(dev->allocator, &scn->shapes);
+ /* Create Star-3D data structures */
res = s3d_scene_create(dev->s3d, &scn->s3d_scn);
if(res != RES_OK) goto error;
+ res = s3d_shape_create_mesh(dev->s3d, &scn->s3d_shape);
+ if(res != RES_OK) goto error;
+ res = s3d_mesh_set_hit_filter_function(scn->s3d_shape, &hit_filter, NULL);
+ if(res != RES_OK) goto error;
+ res = s3d_scene_attach_shape(scn->s3d_scn, scn->s3d_shape);
+ if(res != RES_OK) goto error;
+
+ /* Initialise the buffers of material properties */
+ darray_double_init(dev->allocator, &scn->abs);
+ darray_double_init(dev->allocator, &scn->emi);
+ darray_double_init(dev->allocator, &scn->refl);
+ darray_double_init(dev->allocator, &scn->spec);
exit:
if(out_scn) *out_scn = scn;
@@ -109,79 +161,82 @@ sgf_scene_ref_put(struct sgf_scene* scn)
}
res_T
-sgf_scene_attach_shape(struct sgf_scene* scn, struct sgf_shape* shape)
+sgf_scene3d_setup(struct sgf_scene* scn, const struct sgf_scene3d_desc* desc)
{
- unsigned id;
- struct sgf_shape** pshape;
+ struct s3d_vertex_data vdata;
+ unsigned iprim, iband, i;
+ double* abs, *emi, *refl, *spec;
res_T res = RES_OK;
- if(!scn || !shape) return RES_BAD_ARG;
-
- S3D(shape_get_id(shape->s3d_shape, &id));
- pshape = htable_shape_find(&scn->shapes, &id);
- if(pshape) { /* Already attached */
- ASSERT(*pshape == shape);
- log_warning(scn->dev,
- "%s: the shape is already attached to the scene.\n", FUNC_NAME);
- return RES_OK;
+ if(!scn || !check_scene3d_desc(desc)) {
+ res = RES_BAD_ARG;
+ goto error;
}
- res = s3d_scene_attach_shape(scn->s3d_scn, shape->s3d_shape);
- if(res != RES_OK) return res;
-
- res = htable_shape_set(&scn->shapes, &id, &shape);
+ /* Allocate the buffers of material attributes */
+ #define RESIZE(V, Name) { \
+ res = darray_double_resize(&(V), desc->nprims*desc->nbands); \
+ if(res != RES_OK) { \
+ log_error(scn->dev, \
+ "%s: couldn't allocate the "Name" buffer.", FUNC_NAME); \
+ goto error; \
+ } \
+ } (void)0
+ RESIZE(scn->emi, "emissivity");
+ RESIZE(scn->refl, "reflectivity");
+ RESIZE(scn->spec, "specularity");
+ if(desc->get_absorption) RESIZE(scn->abs, "absorption");
+ #undef RESIZE
+
+ /* Setup the material */
+ abs = desc->get_absorption ? darray_double_data_get(&scn->abs) : NULL;
+ emi = darray_double_data_get(&scn->emi);
+ refl = darray_double_data_get(&scn->refl);
+ spec = darray_double_data_get(&scn->spec);
+ i = 0;
+ FOR_EACH(iband, 0, desc->nbands) {
+ FOR_EACH(iprim, 0, desc->nprims) {
+ #define FETCH(Dst, Name, Low, Upp) { \
+ (Dst) = desc->get_##Name(iprim, iband, desc->context); \
+ if((Dst) < (Low) || (Dst) > (Upp)) { \
+ log_error(scn->dev, "%s: invalid "STR(Name)" `%g'.\n", \
+ FUNC_NAME, (Dst)); \
+ res = RES_BAD_ARG; \
+ goto error; \
+ } \
+ } (void) 0
+
+ if(abs) FETCH(abs[i], absorption, 0, DBL_MAX);
+ FETCH(emi[i], emissivity, 0, 1);
+ FETCH(refl[i], reflectivity, 0, 1);
+ FETCH(spec[i], specularity, 0, 1);
+ #undef FETCH
+ ++i;
+ }}
+
+ /* Setup the geometry */
+ vdata.usage = S3D_POSITION;
+ vdata.type = S3D_FLOAT3;
+ vdata.get = desc->get_position;
+ res = s3d_mesh_setup_indexed_vertices(scn->s3d_shape, desc->nprims,
+ desc->get_indices, desc->nverts, &vdata, 1, desc->context);
if(res != RES_OK) {
- S3D(scene_detach_shape(scn->s3d_scn, shape->s3d_shape));
- return res;
- }
- SGF(shape_ref_get(shape));
- return RES_OK;
-}
-
-res_T
-sgf_scene_detach_shape(struct sgf_scene* scn, struct sgf_shape* shape)
-{
- struct sgf_shape** pshape;
- unsigned id;
- size_t n;
- (void)n;
-
- if(!scn || !shape) return RES_BAD_ARG;
-
- /* Retrieve the shape identifier */
- S3D(shape_get_id(shape->s3d_shape, &id));
-
- /* Check that the shape is effectively attached to the scene */
- pshape = htable_shape_find(&scn->shapes, &id);
- if(!pshape) {
- log_error(scn->dev,
- "%s: the shape is not attached to the scene.\n", FUNC_NAME);
- return RES_BAD_ARG;
+ log_error(scn->dev, "%s: couldn't setup the geometry.\n", FUNC_NAME);
+ goto error;
}
- ASSERT(shape == *pshape);
- n = htable_shape_erase(&scn->shapes, &id);
- ASSERT(n == 1);
- S3D(scene_detach_shape(scn->s3d_scn, shape->s3d_shape));
- SGF(shape_ref_put(shape));
- return RES_OK;
-}
+ scn->nbands = desc->nbands;
+ scn->nprims = desc->nprims;
-res_T
-sgf_scene_clear(struct sgf_scene* scn)
-{
- struct htable_shape_iterator it, end;
- if(!scn) return RES_BAD_ARG;
-
- htable_shape_begin(&scn->shapes, &it);
- htable_shape_end(&scn->shapes, &end);
- while(!htable_shape_iterator_eq(&it, &end)) {
- struct sgf_shape* shape = *htable_shape_iterator_data_get(&it);
- SGF(shape_ref_put(shape));
- htable_shape_iterator_next(&it);
+exit:
+ return res;
+error:
+ if(scn) {
+ darray_double_clear(&scn->abs);
+ darray_double_clear(&scn->emi);
+ darray_double_clear(&scn->refl);
+ darray_double_clear(&scn->spec);
}
- htable_shape_clear(&scn->shapes);
- S3D(scene_clear(scn->s3d_scn));
- return RES_OK;
+ goto exit;
}
diff --git a/src/sgf_shape.c b/src/sgf_shape.c
@@ -1,212 +0,0 @@
-/* Copyright (C) 2015-2016 EDF S.A., France (syrthes-support@edf.fr)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "sgf.h"
-#include "sgf_device_c.h"
-#include "sgf_shape_c.h"
-
-#include <star/s3d.h>
-
-/*******************************************************************************
- * Local functions
- ******************************************************************************/
-static int
-hit_filter
- (const struct s3d_hit* hit,
- const float org[3],
- const float dir[3],
- void* ray_data,
- void* filter_data)
-{
- struct ray_data* rdata = ray_data;
- (void)org, (void)dir, (void)filter_data;
-
- if(!ray_data) return 0;
- /* Discard primitive from which the ray starts from */
- if(S3D_PRIMITIVE_EQ(&rdata->prim_from, &hit->prim)) return 1;
- /* Ray starts on an edge and intersect the neighbor triangle */
- if(hit->distance <= 0) return 1;
- return 0;
-}
-
-static FINLINE int
-check_shape3d_desc(const struct sgf_shape3d_desc* desc)
-{
- return desc
- && desc->get_indices
- && desc->get_emissivity
- && desc->get_reflectivity
- && desc->get_specularity
- && desc->get_position
- && desc->ntris
- && desc->nverts
- && desc->nbands;
-}
-
-static void
-shape_release(ref_T* ref)
-{
- struct sgf_device* dev;
- struct sgf_shape* shape;
- ASSERT(ref);
- shape = CONTAINER_OF(ref, struct sgf_shape, ref);
- dev = shape->dev;
- if(shape->s3d_shape) S3D(shape_ref_put(shape->s3d_shape));
- darray_double_release(&shape->abs);
- darray_double_release(&shape->emi);
- darray_double_release(&shape->refl);
- darray_double_release(&shape->spec);
- MEM_RM(dev->allocator, shape);
- SGF(device_ref_put(dev));
-}
-
-/*******************************************************************************
- * Exported functions
- ******************************************************************************/
-res_T
-sgf_shape3d_create(struct sgf_device* dev, struct sgf_shape** out_shape)
-{
- struct sgf_shape* shape = NULL;
- res_T res = RES_OK;
-
- if(!dev || !out_shape) {
- res = RES_BAD_ARG;
- goto error;
- }
-
- shape = MEM_CALLOC(dev->allocator, 1, sizeof(struct sgf_shape));
- if(!shape) {
- res = RES_MEM_ERR;
- goto error;
- }
- ref_init(&shape->ref);
- SGF(device_ref_get(dev));
- shape->dev = dev;
-
- res = s3d_shape_create_mesh(dev->s3d, &shape->s3d_shape);
- if(res != RES_OK) goto error;
- res = s3d_mesh_set_hit_filter_function(shape->s3d_shape, &hit_filter, NULL);
- if(res != RES_OK) goto error;
-
- darray_double_init(dev->allocator, &shape->abs);
- darray_double_init(dev->allocator, &shape->emi);
- darray_double_init(dev->allocator, &shape->refl);
- darray_double_init(dev->allocator, &shape->spec);
-
-exit:
- if(out_shape) *out_shape = shape;
- return res;
-error:
- if(shape) {
- SGF(shape_ref_put(shape));
- shape = NULL;
- }
- goto exit;
-}
-
-res_T
-sgf_shape_ref_get(struct sgf_shape* shape)
-{
- if(!shape) return RES_BAD_ARG;
- ref_get(&shape->ref);
- return RES_OK;
-}
-
-res_T
-sgf_shape_ref_put(struct sgf_shape* shape)
-{
- if(!shape) return RES_BAD_ARG;
- ref_put(&shape->ref, shape_release);
- return RES_OK;
-}
-
-res_T
-sgf_shape3d_setup
- (struct sgf_shape* shape, const struct sgf_shape3d_desc* desc)
-{
- struct s3d_vertex_data vdata;
- unsigned iprim, iband, i;
- double* abs, *emi, *refl, *spec;
- res_T res = RES_OK;
-
- if(!shape || !check_shape3d_desc(desc)) {
- res = RES_BAD_ARG;
- goto error;
- }
-
- /* Allocate the buffers of material attributes */
- #define RESIZE(V, Name) { \
- res = darray_double_resize(&(V), desc->ntris*desc->nbands); \
- if(res != RES_OK) { \
- log_error(shape->dev, \
- "%s: couldn't allocate the "Name" buffer.", FUNC_NAME); \
- goto error; \
- } \
- } (void)0
- RESIZE(shape->emi, "emissivity");
- RESIZE(shape->refl, "reflectivity");
- RESIZE(shape->spec, "specularity");
- if(desc->get_absorption) RESIZE(shape->abs, "absorption");
- #undef RESIZE
-
- /* Setup the material */
- abs = desc->get_absorption ? darray_double_data_get(&shape->abs) : NULL;
- emi = darray_double_data_get(&shape->emi);
- refl = darray_double_data_get(&shape->refl);
- spec = darray_double_data_get(&shape->spec);
- i = 0;
- FOR_EACH(iband, 0, desc->nbands) {
- FOR_EACH(iprim, 0, desc->ntris) {
- #define FETCH(Dst, Name, Low, Upp) { \
- (Dst) = desc->get_##Name(iprim, iband, desc->context); \
- if((Dst) < (Low) || (Dst) > (Upp)) { \
- log_error(shape->dev, "%s: invalid "STR(Name)" `%g'.\n", \
- FUNC_NAME, (Dst)); \
- res = RES_BAD_ARG; \
- goto error; \
- } \
- } (void) 0
-
- if(abs) FETCH(abs[i], absorption, 0, DBL_MAX);
- FETCH(emi[i], emissivity, 0, 1);
- FETCH(refl[i], reflectivity, 0, 1);
- FETCH(spec[i], specularity, 0, 1);
- #undef FETCH
- ++i;
- }}
-
- /* Setup the geometry */
- vdata.usage = S3D_POSITION;
- vdata.type = S3D_FLOAT3;
- vdata.get = desc->get_position;
- res = s3d_mesh_setup_indexed_vertices(shape->s3d_shape, desc->ntris,
- desc->get_indices, desc->nverts, &vdata, 1, desc->context);
- if(res != RES_OK) {
- log_error(shape->dev, "%s: couldn't setup the geometry.\n", FUNC_NAME);
- goto error;
- }
-
-exit:
- return res;
-error:
- if(shape) {
- darray_double_clear(&shape->abs);
- darray_double_clear(&shape->emi);
- darray_double_clear(&shape->refl);
- darray_double_clear(&shape->spec);
- }
- goto exit;
-}
-
diff --git a/src/sgf_shape_c.h b/src/sgf_shape_c.h
@@ -1,44 +0,0 @@
-/* Copyright (C) 2015-2016 EDF S.A., France (syrthes-support@edf.fr)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SGF_SHAPE_C_H
-#define SGF_SHAPE_C_H
-
-#include <rsys/dynamic_array_double.h>
-#include <rsys/ref_count.h>
-
-#include <star/s3d.h>
-
-struct s3d_shape;
-struct sgf_device;
-
-struct sgf_shape {
- struct s3d_shape* s3d_shape;
- struct darray_double abs; /* Per primitive absorption */
- struct darray_double emi; /* Per primitive emissivity */
- struct darray_double refl; /* Per primitive reflectivity */
- struct darray_double spec; /* Per primitive specularity */
- size_t nbands; /* #spectral bands */
-
- ref_T ref;
- struct sgf_device* dev;
-};
-
-struct ray_data {
- struct s3d_primitive prim_from;
-};
-
-#endif /* SGF_SHAPE_C_H */
-
diff --git a/src/test_sgf_scene3d.c b/src/test_sgf_scene3d.c
@@ -16,41 +16,99 @@
#include "sgf.h"
#include "test_sgf_utils.h"
+static const float vertices[] = {
+ 0.f, 0.f, 0.f,
+ 1.f, 0.f, 0.f,
+ 0.f, 1.f, 0.f,
+ 1.f, 1.f, 0.f,
+};
+static const size_t nvertices = sizeof(vertices) / sizeof(float[3]);
+
+static const unsigned indices[] = { 0, 2, 1, 1, 2, 3 };
+static const size_t nprims = (int)(sizeof(indices) / sizeof(unsigned[3]));
+static const double emissivity[] = { 0.6, 0.6 };
+static const double emissivity_bad[] = { 0.6, 1.1 };
+static const double specularity[] = { 0.0, 0.0 };
+static const double specularity_bad[] = { 1.1, 0.0 };
+static const double absorption[] = { 0.0, 0.0 };
+static const double absorption_bad[] = { -0.1, 0.0 };
+
int
main(int argc, char** argv)
{
struct mem_allocator allocator;
struct sgf_device* sgf;
- struct sgf_shape* shape;
struct sgf_scene* scn;
+ struct sgf_scene3d_desc desc = SGF_SCENE3D_DESC_NULL;
+ struct shape_context ctx;
(void)argc, (void)argv;
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
CHECK(sgf_device_create(NULL, &allocator, 1, &sgf), RES_OK);
- CHECK(sgf_shape3d_create(sgf, &shape), RES_OK);
CHECK(sgf_scene3d_create(NULL, NULL), RES_BAD_ARG);
CHECK(sgf_scene3d_create(sgf, NULL), RES_BAD_ARG);
CHECK(sgf_scene3d_create(NULL, &scn), RES_BAD_ARG);
CHECK(sgf_scene3d_create(sgf, &scn), RES_OK);
- CHECK(sgf_scene_attach_shape(NULL, NULL), RES_BAD_ARG);
- CHECK(sgf_scene_attach_shape(scn, NULL), RES_BAD_ARG);
- CHECK(sgf_scene_attach_shape(NULL, shape), RES_BAD_ARG);
- CHECK(sgf_scene_attach_shape(scn, shape), RES_OK);
- CHECK(sgf_scene_attach_shape(scn, shape), RES_OK);
+ ctx.emissivity = emissivity;
+ ctx.specularity = specularity;
+ ctx.vertices = vertices;
+ ctx.nvertices = nvertices;
+ ctx.indices = indices;
+ ctx.nprimitives = nprims;
+
+ desc.get_position = get_position;
+ desc.get_indices = get_indices;
+ desc.get_emissivity = get_emissivity;
+ desc.get_reflectivity = get_reflectivity;
+ desc.get_specularity = get_specularity;
+ desc.context = &ctx;
+ desc.nprims = (unsigned)nprims;
+ desc.nverts = (unsigned)nvertices;
+ desc.nbands = 1;
- CHECK(sgf_scene_detach_shape(NULL, NULL), RES_BAD_ARG);
- CHECK(sgf_scene_detach_shape(scn, NULL), RES_BAD_ARG);
- CHECK(sgf_scene_detach_shape(NULL, shape), RES_BAD_ARG);
- CHECK(sgf_scene_detach_shape(scn, shape), RES_OK);
- CHECK(sgf_scene_detach_shape(scn, shape), RES_BAD_ARG);
+ CHECK(sgf_scene3d_setup(NULL, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene3d_setup(scn, NULL), RES_BAD_ARG);
+ CHECK(sgf_scene3d_setup(NULL, &desc), RES_BAD_ARG);
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_OK);
- CHECK(sgf_scene_attach_shape(scn, shape), RES_OK);
- CHECK(sgf_scene_clear(NULL), RES_BAD_ARG);
- CHECK(sgf_scene_clear(scn), RES_OK);
- CHECK(sgf_scene_detach_shape(scn, shape), RES_BAD_ARG);
+ desc.get_position = NULL;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.get_position = get_pos;
+ desc.get_indices = NULL;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.get_indices = get_ids;
+ desc.get_emissivity = NULL;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.get_emissivity = get_emissivity;
+ desc.get_reflectivity = NULL;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.get_reflectivity = get_reflectivity;
+ desc.get_specularity = NULL;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.get_specularity = get_specularity;
+ desc.nprims = 0;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.nprims = (unsigned)nprims;
+ desc.nverts = 0;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.nverts = (unsigned)nvertices;
+ desc.nbands = 0;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ desc.nbands = 1;
+ ctx.emissivity = emissivity_bad;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ ctx.emissivity = emissivity;
+ ctx.specularity = specularity_bad;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
+ ctx.specularity = specularity;
+ desc.get_absorption = get_absorption;
+ ctx.absorption = absorption;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_OK);
+ ctx.absorption = absorption_bad;
+ CHECK(sgf_scene3d_setup(scn, &desc), RES_BAD_ARG);
CHECK(sgf_scene_ref_get(NULL), RES_BAD_ARG);
CHECK(sgf_scene_ref_get(scn), RES_OK);
@@ -58,7 +116,6 @@ main(int argc, char** argv)
CHECK(sgf_scene_ref_put(scn), RES_OK);
CHECK(sgf_scene_ref_put(scn), RES_OK);
- CHECK(sgf_shape_ref_put(shape), RES_OK);
CHECK(sgf_device_ref_put(sgf), RES_OK);
check_memory_allocator(&allocator);
diff --git a/src/test_sgf_shape3d.c b/src/test_sgf_shape3d.c
@@ -1,126 +0,0 @@
-/* Copyright (C) 2015-2016 EDF S.A., France (syrthes-support@edf.fr)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "sgf.h"
-#include "test_sgf_utils.h"
-
-static const float vertices[] = {
- 0.f, 0.f, 0.f,
- 1.f, 0.f, 0.f,
- 0.f, 1.f, 0.f,
- 1.f, 1.f, 0.f,
-};
-static const size_t nvertices = sizeof(vertices) / sizeof(float[3]);
-
-static const unsigned indices[] = { 0, 2, 1, 1, 2, 3 };
-static const size_t nprims = (int)(sizeof(indices) / sizeof(unsigned[3]));
-static const double emissivity[] = { 0.6, 0.6 };
-static const double emissivity_bad[] = { 0.6, 1.1 };
-static const double specularity[] = { 0.0, 0.0 };
-static const double specularity_bad[] = { 1.1, 0.0 };
-static const double absorption[] = { 0.0, 0.0 };
-static const double absorption_bad[] = { -0.1, 0.0 };
-
-int
-main(int argc, char** argv)
-{
- struct mem_allocator allocator;
- struct shape_context ctx;
- struct sgf_device* sgf;
- struct sgf_shape* shape;
- struct sgf_shape3d_desc desc = SGF_SHAPE3D_DESC_NULL;
- (void)argc, (void)argv;
-
- mem_init_proxy_allocator(&allocator, &mem_default_allocator);
-
- CHECK(sgf_device_create(NULL, &allocator, 1, &sgf), RES_OK);
-
- CHECK(sgf_shape3d_create(NULL, NULL), RES_BAD_ARG);
- CHECK(sgf_shape3d_create(sgf, NULL), RES_BAD_ARG);
- CHECK(sgf_shape3d_create(NULL, &shape), RES_BAD_ARG);
- CHECK(sgf_shape3d_create(sgf, &shape), RES_OK);
-
- ctx.emissivity = emissivity;
- ctx.specularity = specularity;
- ctx.vertices = vertices;
- ctx.nvertices = nvertices;
- ctx.indices = indices;
- ctx.nprimitives = nprims;
-
- desc.get_position = get_position;
- desc.get_indices = get_indices;
- desc.get_emissivity = get_emissivity;
- desc.get_reflectivity = get_reflectivity;
- desc.get_specularity = get_specularity;
- desc.context = &ctx;
- desc.ntris = (unsigned)nprims;
- desc.nverts = (unsigned)nvertices;
- desc.nbands = 1;
-
- CHECK(sgf_shape3d_setup(NULL, NULL), RES_BAD_ARG);
- CHECK(sgf_shape3d_setup(shape, NULL), RES_BAD_ARG);
- CHECK(sgf_shape3d_setup(NULL, &desc), RES_BAD_ARG);
- CHECK(sgf_shape3d_setup(shape, &desc), RES_OK);
-
- desc.get_position = NULL;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.get_position = get_pos;
- desc.get_indices = NULL;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.get_indices = get_ids;
- desc.get_emissivity = NULL;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.get_emissivity = get_emissivity;
- desc.get_reflectivity = NULL;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.get_reflectivity = get_reflectivity;
- desc.get_specularity = NULL;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.get_specularity = get_specularity;
- desc.ntris = 0;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.ntris = (unsigned)nprims;
- desc.nverts = 0;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.nverts = (unsigned)nvertices;
- desc.nbands = 0;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- desc.nbands = 1;
- ctx.emissivity = emissivity_bad;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- ctx.emissivity = emissivity;
- ctx.specularity = specularity_bad;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
- ctx.specularity = specularity;
- desc.get_absorption = get_absorption;
- ctx.absorption = absorption;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_OK);
- ctx.absorption = absorption_bad;
- CHECK(sgf_shape3d_setup(shape, &desc), RES_BAD_ARG);
-
- CHECK(sgf_shape_ref_get(NULL), RES_BAD_ARG);
- CHECK(sgf_shape_ref_get(shape), RES_OK);
- CHECK(sgf_shape_ref_put(NULL), RES_BAD_ARG);
- CHECK(sgf_shape_ref_put(shape), RES_OK);
- CHECK(sgf_shape_ref_put(shape), RES_OK);
-
- CHECK(sgf_device_ref_put(sgf), RES_OK);
-
- check_memory_allocator(&allocator);
- mem_shutdown_proxy_allocator(&allocator);
- CHECK(mem_allocated_size(), 0);
- return RES_OK;
-}
-