Skip to content

Commit

Permalink
clusterizer: Pass meshlet by value to computeMeshletBounds
Browse files Browse the repository at this point in the history
In C there's no support for references so we need to either pass meshlet
by value or by constant pointer. This change switches to pass by value
as it's cleaner for the callers.

This does mean that the caller has to copy a relatively large meshlet
structure, but the cost of copying the indices and - more importantly -
computing the bounding spheres and apex is substantially larger than a
memcpy.
  • Loading branch information
zeux committed Nov 7, 2018
1 parent d24700a commit 925ff15
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ void meshlets(const Mesh& mesh)
double startc = timestamp();
for (size_t i = 0; i < meshlets.size(); ++i)
{
meshopt_Bounds bounds = meshopt_computeMeshletBounds(&meshlets[i], &mesh.vertices[0].px, mesh.vertices.size(), sizeof(Vertex));
meshopt_Bounds bounds = meshopt_computeMeshletBounds(meshlets[i], &mesh.vertices[0].px, mesh.vertices.size(), sizeof(Vertex));

// trivial accept: we can't ever backface cull this meshlet
accepted += (bounds.cone_cutoff >= 1);
Expand Down
14 changes: 7 additions & 7 deletions src/clusterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,18 @@ meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t
return bounds;
}

meshopt_Bounds meshopt_computeMeshletBounds(const meshopt_Meshlet* meshlet, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride)
meshopt_Bounds meshopt_computeMeshletBounds(meshopt_Meshlet meshlet, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride)
{
assert(vertex_positions_stride > 0 && vertex_positions_stride <= 256);
assert(vertex_positions_stride % sizeof(float) == 0);

unsigned int indices[sizeof(meshlet->indices) / sizeof(meshlet->indices[0][0])];
unsigned int indices[sizeof(meshlet.indices) / sizeof(meshlet.indices[0][0])];

for (unsigned int i = 0; i < meshlet->triangle_count; ++i)
for (unsigned int i = 0; i < meshlet.triangle_count; ++i)
{
unsigned int a = meshlet->vertices[meshlet->indices[i][0]];
unsigned int b = meshlet->vertices[meshlet->indices[i][1]];
unsigned int c = meshlet->vertices[meshlet->indices[i][2]];
unsigned int a = meshlet.vertices[meshlet.indices[i][0]];
unsigned int b = meshlet.vertices[meshlet.indices[i][1]];
unsigned int c = meshlet.vertices[meshlet.indices[i][2]];

assert(a < vertex_count && b < vertex_count && c < vertex_count);

Expand All @@ -337,5 +337,5 @@ meshopt_Bounds meshopt_computeMeshletBounds(const meshopt_Meshlet* meshlet, cons
indices[i * 3 + 2] = c;
}

return meshopt_computeClusterBounds(indices, meshlet->triangle_count * 3, vertex_positions, vertex_count, vertex_positions_stride);
return meshopt_computeClusterBounds(indices, meshlet.triangle_count * 3, vertex_positions, vertex_count, vertex_positions_stride);
}
2 changes: 1 addition & 1 deletion src/meshoptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ struct meshopt_Bounds
* vertex_positions should have float3 position in the first 12 bytes of each vertex - similar to glVertexPointer
*/
MESHOPTIMIZER_EXPERIMENTAL struct meshopt_Bounds meshopt_computeClusterBounds(const unsigned int* indices, size_t index_count, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
MESHOPTIMIZER_EXPERIMENTAL struct meshopt_Bounds meshopt_computeMeshletBounds(const struct meshopt_Meshlet* meshlet, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);
MESHOPTIMIZER_EXPERIMENTAL struct meshopt_Bounds meshopt_computeMeshletBounds(struct meshopt_Meshlet meshlet, const float* vertex_positions, size_t vertex_count, size_t vertex_positions_stride);

#ifdef __cplusplus
} /* extern "C" */
Expand Down

0 comments on commit 925ff15

Please sign in to comment.