commit 2414d2303f186b0d7d57ca37bb2cb90ea29a701b
parent bded6edefa46e89034f766c97170ff954589cee4
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 24 Aug 2016 14:20:01 +0200
Rename file to prepare for different test geometries
Diffstat:
5 files changed, 140 insertions(+), 111 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -118,7 +118,7 @@ if(NOT NO_TEST)
function(build_test _name)
add_executable(${_name}
${SSOL_SOURCE_DIR}/test_ssol_utils.h
- ${SSOL_SOURCE_DIR}/test_ssol_box.h
+ ${SSOL_SOURCE_DIR}/test_ssol_geometries.h
${SSOL_SOURCE_DIR}/${_name}.c)
target_link_libraries(${_name} solstice-solver RSys Star3D StarSP)
set(_libraries ${ARGN})
diff --git a/src/test_ssol_box.h b/src/test_ssol_box.h
@@ -1,99 +0,0 @@
-/* Copyright (C) CNRS 2016
- *
- * 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 TEST_SSOL_BOX_H
-#define TEST_SSOL_BOX_H
-
- /*******************************************************************************
- * Box
- ******************************************************************************/
-struct desc {
- const float* vertices;
- const unsigned* indices;
-};
-
-static const float walls [] = {
- 552.f, 0.f, 0.f,
- 0.f, 0.f, 0.f,
- 0.f, 559.f, 0.f,
- 552.f, 559.f, 0.f,
- 552.f, 0.f, 548.f,
- 0.f, 0.f, 548.f,
- 0.f, 559.f, 548.f,
- 552.f, 559.f, 548.f
-};
-const unsigned walls_nverts = sizeof(walls) / sizeof(float[3]);
-
-const unsigned walls_ids [] = {
- 0, 1, 2, 2, 3, 0, /* Bottom */
- 4, 5, 6, 6, 7, 4, /* Top */
- 1, 2, 6, 6, 5, 1, /* Left */
- 0, 3, 7, 7, 4, 0, /* Right */
- 2, 3, 7, 7, 6, 2 /* Back */
-};
-const unsigned walls_ntris = sizeof(walls_ids) / sizeof(unsigned[3]);
-
-static const struct desc walls_desc = { walls, walls_ids };
-
-/*******************************************************************************
-* Callbacks
-******************************************************************************/
-static INLINE void
-get_ids(const unsigned itri, unsigned ids[3], void* data)
-{
- const unsigned id = itri * 3;
- struct desc* desc = data;
- NCHECK(desc, NULL);
- ids[0] = desc->indices[id + 0];
- ids[1] = desc->indices[id + 1];
- ids[2] = desc->indices[id + 2];
-}
-
-static INLINE void
-get_position(const unsigned ivert, float position[3], void* data)
-{
- struct desc* desc = data;
- NCHECK(desc, NULL);
- position[0] = desc->vertices[ivert * 3 + 0];
- position[1] = desc->vertices[ivert * 3 + 1];
- position[2] = desc->vertices[ivert * 3 + 2];
-}
-
-static INLINE void
-get_normal(const unsigned ivert, float normal[3], void* data)
-{
- (void) ivert, (void) data;
- normal[0] = 1.f;
- normal[1] = 0.f;
- normal[2] = 0.f;
-}
-
-static INLINE void
-get_uv(const unsigned ivert, float uv[2], void* data)
-{
- (void) ivert, (void) data;
- uv[0] = -1.f;
- uv[1] = 1.f;
-}
-
-static INLINE void
-get_polygon_vertices(const size_t ivert, double position[2], void* ctx)
-{
- (void) ivert, (void) ctx;
- position[0] = -1.f;
- position[1] = 1.f;
-}
-
-#endif /* TEST_SSOL_BOX_H */
diff --git a/src/test_ssol_geometries.h b/src/test_ssol_geometries.h
@@ -0,0 +1,100 @@
+/* Copyright (C) CNRS 2016
+ *
+ * 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 TEST_SSOL_GEOMETRIES_H
+#define TEST_SSOL_GEOMETRIES_H
+
+struct desc {
+ const float* vertices;
+ const unsigned* indices;
+};
+
+ /*******************************************************************************
+ * Box
+ ******************************************************************************/
+
+static const float box_walls [] = {
+ 552.f, 0.f, 0.f,
+ 0.f, 0.f, 0.f,
+ 0.f, 559.f, 0.f,
+ 552.f, 559.f, 0.f,
+ 552.f, 0.f, 548.f,
+ 0.f, 0.f, 548.f,
+ 0.f, 559.f, 548.f,
+ 552.f, 559.f, 548.f
+};
+const unsigned box_walls_nverts = sizeof(box_walls) / sizeof(float[3]);
+
+const unsigned box_walls_ids [] = {
+ 0, 1, 2, 2, 3, 0, /* Bottom */
+ 4, 5, 6, 6, 7, 4, /* Top */
+ 1, 2, 6, 6, 5, 1, /* Left */
+ 0, 3, 7, 7, 4, 0, /* Right */
+ 2, 3, 7, 7, 6, 2 /* Back */
+};
+const unsigned box_walls_ntris = sizeof(box_walls_ids) / sizeof(unsigned[3]);
+
+static struct desc box_walls_desc = { box_walls, box_walls_ids };
+
+/*******************************************************************************
+* Callbacks
+******************************************************************************/
+static INLINE void
+get_ids(const unsigned itri, unsigned ids[3], void* data)
+{
+ const unsigned id = itri * 3;
+ struct desc* desc = data;
+ NCHECK(desc, NULL);
+ ids[0] = desc->indices[id + 0];
+ ids[1] = desc->indices[id + 1];
+ ids[2] = desc->indices[id + 2];
+}
+
+static INLINE void
+get_position(const unsigned ivert, float position[3], void* data)
+{
+ struct desc* desc = data;
+ NCHECK(desc, NULL);
+ position[0] = desc->vertices[ivert * 3 + 0];
+ position[1] = desc->vertices[ivert * 3 + 1];
+ position[2] = desc->vertices[ivert * 3 + 2];
+}
+
+static INLINE void
+get_normal(const unsigned ivert, float normal[3], void* data)
+{
+ (void) ivert, (void) data;
+ normal[0] = 1.f;
+ normal[1] = 0.f;
+ normal[2] = 0.f;
+}
+
+static INLINE void
+get_uv(const unsigned ivert, float uv[2], void* data)
+{
+ (void) ivert, (void) data;
+ uv[0] = -1.f;
+ uv[1] = 1.f;
+}
+
+static INLINE void
+get_polygon_vertices(const size_t ivert, double position[2], void* ctx)
+{
+ (void) ivert, (void) ctx;
+ position[0] = -1.f;
+ position[1] = 1.f;
+}
+
+#endif /* TEST_SSOL_GEOMETRIES_H */
diff --git a/src/test_ssol_shape.c b/src/test_ssol_shape.c
@@ -15,7 +15,7 @@
#include "ssol.h"
#include "test_ssol_utils.h"
-#include "test_ssol_box.h"
+#include "test_ssol_geometries.h"
#include <rsys/logger.h>
@@ -30,7 +30,6 @@ main(int argc, char** argv)
struct ssol_device* dev;
struct ssol_shape* shape;
struct ssol_vertex_data attribs[3];
- void* data = (void*) &walls_desc;
struct ssol_punched_surface punched_surface;
struct ssol_carving carving;
struct ssol_quadric quadric;
@@ -64,19 +63,19 @@ main(int argc, char** argv)
attribs[2].get = get_uv;
CHECK(ssol_mesh_setup
- (NULL, walls_ntris, get_ids, walls_nverts, attribs, 1, data), RES_BAD_ARG);
+ (NULL, box_walls_ntris, get_ids, box_walls_nverts, attribs, 1, &box_walls_desc), RES_BAD_ARG);
CHECK(ssol_mesh_setup
- (shape, 0, get_ids, walls_nverts, attribs, 1, data), RES_BAD_ARG);
+ (shape, 0, get_ids, box_walls_nverts, attribs, 1, &box_walls_desc), RES_BAD_ARG);
CHECK(ssol_mesh_setup
- (shape, walls_ntris, NULL, walls_nverts, attribs, 1, data), RES_BAD_ARG);
+ (shape, box_walls_ntris, NULL, box_walls_nverts, attribs, 1, &box_walls_desc), RES_BAD_ARG);
CHECK(ssol_mesh_setup
- (shape, walls_ntris, get_ids, 0, attribs, 1, data), RES_BAD_ARG);
+ (shape, box_walls_ntris, get_ids, 0, attribs, 1, &box_walls_desc), RES_BAD_ARG);
CHECK(ssol_mesh_setup
- (shape, walls_ntris, get_ids, walls_nverts, NULL, 1, data), RES_BAD_ARG);
+ (shape, box_walls_ntris, get_ids, box_walls_nverts, NULL, 1, &box_walls_desc), RES_BAD_ARG);
CHECK(ssol_mesh_setup
- (shape, walls_ntris, get_ids, walls_nverts, attribs, 0, data), RES_BAD_ARG);
+ (shape, box_walls_ntris, get_ids, box_walls_nverts, attribs, 0, &box_walls_desc), RES_BAD_ARG);
CHECK(ssol_mesh_setup
- (shape, walls_ntris, get_ids, walls_nverts, attribs, 3, data), RES_OK);
+ (shape, box_walls_ntris, get_ids, box_walls_nverts, attribs, 3, &box_walls_desc), RES_OK);
CHECK(ssol_shape_ref_put(shape), RES_OK);
diff --git a/src/test_ssol_solver.c b/src/test_ssol_solver.c
@@ -15,6 +15,7 @@
#include "ssol.h"
#include "test_ssol_utils.h"
+#include "test_ssol_geometries.h"
#include "ssol_solver_c.h"
@@ -34,6 +35,12 @@ main(int argc, char** argv)
struct ssol_device* dev;
struct ssp_rng* rng;
struct ssol_scene* scene;
+ struct ssol_shape* shape;
+ struct ssol_vertex_data attribs[3];
+ struct ssol_material* material;
+ struct ssol_mirror_shader shader;
+ struct ssol_object* object;
+ struct ssol_object_instance* instance;
struct ssol_sun* sun;
struct ssol_spectrum* spectrum;
double dir[3];
@@ -59,15 +66,37 @@ main(int argc, char** argv)
CHECK(ssol_sun_set_dni(sun, 1000), RES_OK);
CHECK(ssol_scene_create(dev, &scene), RES_OK);
CHECK(ssol_scene_attach_sun(scene, sun), RES_OK);
-
- /* TODO: create a scene */
CHECK(ssol_solve(NULL, rng, 10, stdout), RES_BAD_ARG);
CHECK(ssol_solve(scene, NULL, 10, stdout), RES_BAD_ARG);
CHECK(ssol_solve(scene, rng, 0, stdout), RES_BAD_ARG);
CHECK(ssol_solve(scene, rng, 10, NULL), RES_BAD_ARG);
+ CHECK(ssol_solve(scene, rng, 10, stdout), RES_BAD_ARG); /* no geometry */
+
+ /* create scene content */
+ CHECK(ssol_shape_create_mesh(dev, &shape), RES_OK);
+ attribs[0].usage = SSOL_POSITION;
+ attribs[0].get = get_position;
+ attribs[1].usage = SSOL_NORMAL;
+ attribs[1].get = get_normal;
+ attribs[2].usage = SSOL_TEXCOORD;
+ attribs[2].get = get_uv;
+ CHECK(ssol_mesh_setup
+ (shape, box_walls_ntris, get_ids, box_walls_nverts, attribs, 3, &box_walls_desc), RES_OK);
+ CHECK(ssol_material_create_mirror(dev, &material), RES_OK);
+ CHECK(ssol_mirror_set_shader(material, &shader), RES_OK);
+ CHECK(ssol_object_create(dev, shape, material, &object), RES_OK);
+ CHECK(ssol_object_instantiate(object, &instance), RES_OK);
+ CHECK(ssol_scene_attach_object_instance(scene, instance), RES_OK);
+
CHECK(ssol_solve(scene, rng, 10, stdout), RES_OK);
+ CHECK(ssol_scene_detach_object_instance(scene, instance), RES_OK);
+
+ CHECK(ssol_object_instance_ref_put(instance), RES_OK);
+ CHECK(ssol_object_ref_put(object), RES_OK);
+ CHECK(ssol_shape_ref_put(shape), RES_OK);
+ CHECK(ssol_material_ref_put(material), RES_OK);
CHECK(ssol_device_ref_put(dev), RES_OK);
CHECK(ssol_scene_clear(scene), RES_OK);
CHECK(ssp_rng_ref_put(rng), RES_OK);