commit 6173ec407affbda1fde1c2f1637835816e9105db
parent daa63012d87aa757494fb0a3ab531329697fc009
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 16 Feb 2018 16:10:44 +0100
Add a new test with 3M+ trg.
Diffstat:
2 files changed, 125 insertions(+), 1 deletion(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -29,6 +29,7 @@ find_package(RSys 0.6.1 REQUIRED)
if(NOT NO_TEST)
find_package(StarSP 0.7 REQUIRED)
+find_package(Star3DUT 0.3.1 REQUIRED)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
@@ -116,11 +117,14 @@ if(NOT NO_TEST)
new_test(test_senc_descriptor)
new_test(test_senc_device)
new_test(test_senc_enclosure)
+ new_test(test_senc_many_triangles)
new_test(test_senc_sample_enclosure)
new_test(test_senc_scene)
-
+
target_link_libraries(test_senc_sample_enclosure StarSP)
+ target_link_libraries(test_senc_many_triangles Star3DUT)
rcmake_copy_runtime_libraries(test_senc_sample_enclosure)
+ rcmake_copy_runtime_libraries(test_senc_many_triangles)
endif()
################################################################################
diff --git a/src/test_senc_many_triangles.c b/src/test_senc_many_triangles.c
@@ -0,0 +1,120 @@
+/* Copyright (C) |Meso|Star> 2016-2018 (contact@meso-star.com)
+*
+* 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 "senc.h"
+#include "test_senc_utils.h"
+
+#include <star/s3dut.h>
+
+#include <rsys/double3.h>
+
+struct s3dut_context {
+ struct s3dut_mesh_data data;
+ struct context ctx;
+};
+
+static void
+get_s3dut_indices(const unsigned itri, unsigned ids[3], void* context)
+{
+ struct s3dut_context* ctx = context;
+ ASSERT(ids && ctx);
+ ASSERT(itri < ctx->data.nprimitives);
+ ASSERT(ctx->data.indices[itri * 3 + 0] < UINT_MAX
+ && ctx->data.indices[itri * 3 + 1] < UINT_MAX
+ && ctx->data.indices[itri * 3 + 2] < UINT_MAX);
+ ids[0] = (unsigned) ctx->data.indices[itri * 3 + 0];
+ ids[ctx->ctx.reverse_vrtx ? 2 : 1] = (unsigned) ctx->data.indices[itri * 3 + 1];
+ ids[ctx->ctx.reverse_vrtx ? 1 : 2] = (unsigned) ctx->data.indices[itri * 3 + 2];
+}
+
+static void
+get_s3dut_position(const unsigned ivert, double pos[3], void* context)
+{
+ struct s3dut_context* ctx = context;
+ ASSERT(pos && ctx);
+ ASSERT(ivert < ctx->data.nvertices);
+ pos[0] = ctx->data.positions[ivert * 3 + 0] * ctx->ctx.scale + ctx->ctx.offset[0];
+ pos[1] = ctx->data.positions[ivert * 3 + 1] * ctx->ctx.scale + ctx->ctx.offset[1];
+ pos[2] = ctx->data.positions[ivert * 3 + 2] * ctx->ctx.scale + ctx->ctx.offset[2];
+}
+
+static void
+get_s3dut_media(const unsigned itri, unsigned medium[2], void* context)
+{
+ struct s3dut_context* ctx = context;
+ (void) itri;
+ ASSERT(medium && ctx);
+ medium[ctx->ctx.reverse_med ? 1 : 0] = ctx->ctx.front_media[0];
+ medium[ctx->ctx.reverse_med ? 0 : 1] = ctx->ctx.back_media[1];
+}
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct senc_descriptor* desc = NULL;
+ struct senc_device* dev = NULL;
+ struct senc_scene* scn = NULL;
+ struct s3dut_mesh* cyl = NULL;
+ struct s3dut_context ctx;
+ unsigned count;
+ unsigned cyl_trg_count, cyl_vrtx_count;
+ int i;
+ (void) argc, (void) argv;
+
+ CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
+ CHK(senc_device_create
+ (NULL, &allocator, SENC_NTHREADS_DEFAULT, 1, &dev) == RES_OK);
+
+ /* Create the scene */
+ CHK(senc_scene_create(dev, 2, &scn) == RES_OK);
+
+ ctx.ctx.positions = NULL;
+ ctx.ctx.indices = NULL;
+ ctx.ctx.scale = 1;
+ ctx.ctx.reverse_vrtx = 0;
+ ctx.ctx.reverse_med = 0;
+ ctx.ctx.front_media = medium0;
+ ctx.ctx.back_media = medium1;
+ /* Create a cylinder (320 K trg, 160 K vrtx). */
+ CHK(s3dut_create_cylinder(&allocator, 1, 2, 400, 400, &cyl) == RES_OK);
+ S3DUT(mesh_get_data(cyl, &ctx.data));
+ ASSERT(ctx.data.nprimitives < UINT_MAX);
+ ASSERT(ctx.data.nvertices < UINT_MAX);
+ cyl_trg_count = (unsigned)ctx.data.nprimitives;
+ cyl_vrtx_count = (unsigned)ctx.data.nvertices;
+#define NB_CYL 10
+ FOR_EACH(i, 0, NB_CYL) {
+ d3(ctx.ctx.offset, 0, 0, i * 10);
+ CHK(senc_scene_add_geometry(scn, cyl_trg_count, get_s3dut_indices,
+ get_s3dut_media, cyl_vrtx_count, get_s3dut_position, &ctx) == RES_OK);
+ }
+ S3DUT(mesh_ref_put(cyl));
+ CHK(senc_scene_analyze(scn, &desc) == RES_OK);
+
+ CHK(senc_descriptor_get_global_vertices_count(desc, &count) == RES_OK);
+ CHK(count == NB_CYL * cyl_vrtx_count);
+ CHK(senc_descriptor_get_global_triangles_count(desc, &count) == RES_OK);
+ CHK(count == NB_CYL * cyl_trg_count);
+
+ CHK(senc_scene_ref_put(scn) == RES_OK);
+ CHK(senc_device_ref_put(dev) == RES_OK);
+ CHK(senc_descriptor_ref_put(desc) == RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}