commit 69a0937bb6ce7863e4587082bb96d9e999cda09d
parent d17e62511daee8ebc6b7ee8e48de9674d03f465d
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 15 Oct 2019 11:13:23 +0200
Fix a test and some warnings
Diffstat:
4 files changed, 54 insertions(+), 34 deletions(-)
diff --git a/src/senc.h b/src/senc.h
@@ -18,6 +18,8 @@
#include <rsys/rsys.h>
+#include <limits.h>
+
/* Library symbol management */
#if defined(SENC_SHARED_BUILD)
#define SENC_API extern EXPORT_SYM
@@ -206,7 +208,7 @@ senc_scene_add_geometry_attr
void* context),
void* context);
-SENC_API INLINE res_T
+static INLINE res_T
senc_scene_add_geometry
(struct senc_scene* scene,
/* Number of added triangles */
diff --git a/src/test_senc_undefined_medium.c b/src/test_senc_undefined_medium.c
@@ -34,13 +34,9 @@ test(int convention)
unsigned gid;
struct context ctx;
unsigned i, t, ecount, vcount, tcount, scount;
- int is_front, is_in;
unsigned media[12];
unsigned rev_box_indices[sizeof(box_indices) / sizeof(*box_indices)];
- int conv_front, conv_in;
-
- conv_front = (convention & SENC_CONVENTION_NORMAL_FRONT) != 0;
- conv_in = (convention & SENC_CONVENTION_NORMAL_INSIDE) != 0;
+ int conv_front = (convention & SENC_CONVENTION_NORMAL_FRONT) != 0;
/* Create a box with reversed triangles */
FOR_EACH(i, 0, sizeof(rev_box_indices) / sizeof(*rev_box_indices)) {
@@ -54,8 +50,6 @@ test(int convention)
OK(senc_device_create(NULL, &allocator, SENC_NTHREADS_DEFAULT, 1, &dev));
OK(senc_scene_create(dev, convention, &scn));
- is_front = (convention & SENC_CONVENTION_NORMAL_FRONT) != 0;
- is_in = (convention & SENC_CONVENTION_NORMAL_INSIDE) != 0;
/* A 3D cube.
* 2 enclosures (inside, outside) sharing the same triangles,
@@ -241,7 +235,7 @@ test(int convention)
/* Geometrical normals point outside the cube in input triangles:
* if convention is front, front medium (0) is outside,
* that is medium 0's enclosure is infinite */
- CHK(is_front == ((medium == 0) == header.is_infinite));
+ CHK(conv_front == ((medium == 0) == header.is_infinite));
CHK(header.triangle_count == ntriangles);
CHK(header.unique_triangle_count == ntriangles);
CHK(header.vertices_count == nvertices);
diff --git a/src/test_senc_undefined_medium_attr.c b/src/test_senc_undefined_medium_attr.c
@@ -17,18 +17,34 @@
#include "senc_s3d_wrapper.h"
#include "test_senc_utils.h"
-#include <rsys/dynamic_array_uint.h>
#include <rsys/double3.h>
-
#include <star/s3d.h>
+#include <limits.h>
+
+#define INVALID_INTFACE_ID UINT_MAX
+
+static FINLINE void
+set_null_id(struct mem_allocator* alloc, unsigned* data)
+{
+ ASSERT(data); (void)alloc;
+ *data = INVALID_INTFACE_ID;
+}
+
+#include <rsys/dynamic_array.h>
+#define DARRAY_NAME intface_id
+#define DARRAY_FUNCTOR_INIT set_null_id
+#define DARRAY_DATA unsigned
+#include <rsys/dynamic_array.h>
+
/* Manage interface properties */
struct merge_ctx {
- struct darray_uint global_interf_data;
+ struct darray_intface_id global_interf_data;
const unsigned* current_add_interf_data;
};
-res_T add_trg
+static res_T
+add_trg
(const unsigned global_id,
const unsigned itri,
void* context)
@@ -42,29 +58,43 @@ res_T add_trg
/* Get interface information from ctx */
interf = merge_ctx->current_add_interf_data[itri];
/* Keep data */
- res = darray_uint_resize(&merge_ctx->global_interf_data, global_id + 1);
+ res = darray_intface_id_resize(&merge_ctx->global_interf_data, global_id + 1);
if(res != RES_OK) return res;
- darray_uint_data_get(&merge_ctx->global_interf_data)[global_id] = interf;
+ darray_intface_id_data_get(&merge_ctx->global_interf_data)[global_id] = interf;
return res;
}
-res_T merge_trg
+static res_T
+merge_trg
(const unsigned global_id,
const unsigned itri,
const int reversed_triangle,
void* context)
{
+ res_T res = RES_OK;
struct context* ctx = context;
struct merge_ctx* merge_ctx;
+ int need_merge;
unsigned interf;
+ unsigned* interf_data;
ASSERT(ctx); (void)reversed_triangle;
merge_ctx = ctx->custom;
+ res = darray_intface_id_resize(&merge_ctx->global_interf_data, global_id + 1);
+ if(res != RES_OK) return res;
/* Get interface information from ctx */
interf = merge_ctx->current_add_interf_data[itri];
- if(darray_uint_data_get(&merge_ctx->global_interf_data)[global_id] != interf)
- /* Previous interface id is different: no possible merge */
- return RES_BAD_ARG;
- /* Same data: no merge needed */
+
+ interf_data = darray_intface_id_data_get(&merge_ctx->global_interf_data);
+
+ need_merge = (interf_data[global_id] != INVALID_INTFACE_ID);
+ if (need_merge) {
+ if (interf_data[global_id] != interf)
+ /* Previous interface id is different: no possible merge */
+ return RES_BAD_ARG;
+ } else {
+ /* Triangle is known, but without interface information: create */
+ interf_data[global_id] = interf;
+ }
return RES_OK;
}
@@ -81,18 +111,14 @@ test(int convention)
unsigned gid;
struct context ctx;
unsigned i, t, ecount, vcount, tcount, scount;
- int is_front, is_in;
unsigned media[12], interface_ids[12] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
unsigned rev_box_indices[sizeof(box_indices) / sizeof(*box_indices)];
- int conv_front, conv_in;
struct merge_ctx merge_ctx;
+ int conv_front = (convention & SENC_CONVENTION_NORMAL_FRONT) != 0;
- darray_uint_init(&allocator, &merge_ctx.global_interf_data);
+ darray_intface_id_init(&allocator, &merge_ctx.global_interf_data);
merge_ctx.current_add_interf_data = interface_ids;
- conv_front = (convention & SENC_CONVENTION_NORMAL_FRONT) != 0;
- conv_in = (convention & SENC_CONVENTION_NORMAL_INSIDE) != 0;
-
/* Create a box with reversed triangles */
FOR_EACH(i, 0, sizeof(rev_box_indices) / sizeof(*rev_box_indices)) {
switch (i % 3) {
@@ -105,8 +131,6 @@ test(int convention)
OK(senc_device_create(NULL, &allocator, SENC_NTHREADS_DEFAULT, 1, &dev));
OK(senc_scene_create(dev, convention, &scn));
- is_front = (convention & SENC_CONVENTION_NORMAL_FRONT) != 0;
- is_in = (convention & SENC_CONVENTION_NORMAL_INSIDE) != 0;
/* A 3D cube.
* 2 enclosures (inside, outside) sharing the same triangles,
@@ -299,7 +323,7 @@ test(int convention)
/* Geometrical normals point outside the cube in input triangles:
* if convention is front, front medium (0) is outside,
* that is medium 0's enclosure is infinite */
- CHK(is_front == ((medium == 0) == header.is_infinite));
+ CHK(conv_front == ((medium == 0) == header.is_infinite));
CHK(header.triangle_count == ntriangles);
CHK(header.unique_triangle_count == ntriangles);
CHK(header.vertices_count == nvertices);
@@ -322,7 +346,7 @@ test(int convention)
SENC(scene_ref_put(scn));
SENC(device_ref_put(dev));
SENC(descriptor_ref_put(desc));
- darray_uint_release(&merge_ctx.global_interf_data);
+ darray_intface_id_release(&merge_ctx.global_interf_data);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
diff --git a/src/test_senc_utils.h b/src/test_senc_utils.h
@@ -98,7 +98,7 @@ static const unsigned medium1_front0[12] = { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
static const unsigned gid_face[12] = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 };
static INLINE void
-get_indices(const unsigned itri, unsigned ids[3], const void* context)
+get_indices(const unsigned itri, unsigned ids[3], void* context)
{
const struct context* ctx = context;
ASSERT(ids && ctx);
@@ -108,7 +108,7 @@ get_indices(const unsigned itri, unsigned ids[3], const void* context)
}
static INLINE void
-get_position(const unsigned ivert, double pos[3], const void* context)
+get_position(const unsigned ivert, double pos[3], void* context)
{
const struct context* ctx = context;
ASSERT(pos && ctx);
@@ -118,7 +118,7 @@ get_position(const unsigned ivert, double pos[3], const void* context)
}
static INLINE void
-get_media(const unsigned itri, unsigned medium[2], const void* context)
+get_media(const unsigned itri, unsigned medium[2], void* context)
{
const struct context* ctx = context;
ASSERT(medium && ctx);
@@ -127,7 +127,7 @@ get_media(const unsigned itri, unsigned medium[2], const void* context)
}
static INLINE void
-get_global_id(const unsigned itri, unsigned* gid, const void* context)
+get_global_id(const unsigned itri, unsigned* gid, void* context)
{
const struct context* ctx = context;
ASSERT(gid && context);