star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit 14e645c99da364a68e01c89a1dcf45318db4a432
parent 987a07025d74d01037c9abe4e62f710dd0bac91e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  7 Feb 2020 15:37:24 +0100

Add one float to the buffer of vertex positions

According to Embree, the last vertex position must be at least 16 bytes
length.

Diffstat:
Msrc/s3d_mesh.c | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/s3d_mesh.c b/src/s3d_mesh.c @@ -36,6 +36,10 @@ #include <rsys/float3.h> +/* Number of floats added to the vertex position in order to ensure the Embree + * vertex padding constraint */ +#define POSITION_PADDING 1 + /******************************************************************************* * Helper functions ******************************************************************************/ @@ -102,7 +106,8 @@ mesh_setup_positions if(attr->get == S3D_KEEP) { ASSERT(mesh->attribs[S3D_POSITION]); - ASSERT(darray_float_size_get(&mesh->attribs[S3D_POSITION]->data) == nverts*3); + ASSERT(darray_float_size_get + (&mesh->attribs[S3D_POSITION]->data) - POSITION_PADDING == nverts*3); return; } @@ -114,7 +119,11 @@ mesh_setup_positions /* Allocate vertex positions */ res = vertex_buffer_create(mesh->dev->allocator, &mesh->attribs[S3D_POSITION]); if(res != RES_OK) FATAL("Insufficient memory\n"); - res = darray_float_resize(&mesh->attribs[S3D_POSITION]->data, nverts*3); + + /* Embree requires that the last element is at least 16bytes length. One has + * thus to add some padding to the buffer of positions. */ + res = darray_float_resize + (&mesh->attribs[S3D_POSITION]->data, nverts*3 + POSITION_PADDING); if(res != RES_OK) FATAL("Insufficient memory\n"); mesh->attribs_type[S3D_POSITION] = S3D_FLOAT3; @@ -314,7 +323,8 @@ mesh_get_nverts(const struct mesh* mesh) return 0; ASSERT(mesh->attribs_type[S3D_POSITION] == S3D_FLOAT3); - ncoords = darray_float_size_get(&mesh->attribs[S3D_POSITION]->data); + ncoords = darray_float_size_get + (&mesh->attribs[S3D_POSITION]->data) - POSITION_PADDING; ASSERT(ncoords % 3 == 0); return ncoords / 3; }