@@ -19,7 +19,8 @@ const size_t kMeshletMaxVertices = 256;
1919// A reasonable limit is around 2*max_vertices or less
2020const size_t kMeshletMaxTriangles = 512 ;
2121
22- static void computeBoundingSphere (float result[4 ], const float * points, size_t count, size_t points_stride, const float * radii, size_t radii_stride, size_t axis_count, const unsigned int * indices = NULL )
22+ template <int Axes>
23+ static void computeBoundingSphere (float result[4 ], const float * points, size_t count, size_t points_stride, const float * radii, size_t radii_stride, const unsigned int * indices = NULL )
2324{
2425 static const float axes[7 ][3 ] = {
2526 // X, Y, Z
@@ -35,7 +36,7 @@ static void computeBoundingSphere(float result[4], const float* points, size_t c
3536 };
3637
3738 assert (count > 0 );
38- assert (axis_count <= sizeof (axes) / sizeof (axes[0 ]));
39+ assert (size_t (Axes) <= sizeof (axes) / sizeof (axes[0 ]));
3940
4041 size_t points_stride_float = points_stride / sizeof (float );
4142 size_t radii_stride_float = radii_stride / sizeof (float );
@@ -44,7 +45,7 @@ static void computeBoundingSphere(float result[4], const float* points, size_t c
4445 unsigned int pmin[7 ], pmax[7 ];
4546 float tmin[7 ], tmax[7 ];
4647
47- for (size_t axis = 0 ; axis < axis_count ; ++axis)
48+ for (int axis = 0 ; axis < Axes ; ++axis)
4849 {
4950 pmin[axis] = pmax[axis] = 0 ;
5051 tmin[axis] = FLT_MAX ;
@@ -57,7 +58,7 @@ static void computeBoundingSphere(float result[4], const float* points, size_t c
5758 const float * p = points + v * points_stride_float;
5859 float r = radii[v * radii_stride_float];
5960
60- for (size_t axis = 0 ; axis < axis_count ; ++axis)
61+ for (int axis = 0 ; axis < Axes ; ++axis)
6162 {
6263 const float * ax = axes[axis];
6364
@@ -75,7 +76,7 @@ static void computeBoundingSphere(float result[4], const float* points, size_t c
7576 size_t paxis = 0 ;
7677 float paxisdr = 0 ;
7778
78- for (size_t axis = 0 ; axis < axis_count ; ++axis)
79+ for (int axis = 0 ; axis < Axes ; ++axis)
7980 {
8081 const float * p1 = points + pmin[axis] * points_stride_float;
8182 const float * p2 = points + pmax[axis] * points_stride_float;
@@ -182,13 +183,13 @@ static meshopt_Bounds computeClusterBounds(const unsigned int* indices, size_t i
182183
183184 // compute cluster bounding sphere; we'll use the center to determine normal cone apex as well
184185 float psphere[4 ] = {};
185- computeBoundingSphere (psphere, vertex_positions, corner_count, vertex_positions_stride, &rzero, 0 , 7 , corners);
186+ computeBoundingSphere< 7 > (psphere, vertex_positions, corner_count, vertex_positions_stride, &rzero, 0 , corners);
186187
187188 float center[3 ] = {psphere[0 ], psphere[1 ], psphere[2 ]};
188189
189190 // treating triangle normals as points, find the bounding sphere - the sphere center determines the optimal cone axis
190191 float nsphere[4 ] = {};
191- computeBoundingSphere (nsphere, normals[0 ], triangles, sizeof (float ) * 4 , &rzero, 0 , 3 );
192+ computeBoundingSphere< 3 > (nsphere, normals[0 ], triangles, sizeof (float ) * 4 , &rzero, 0 );
192193
193194 float axis[3 ] = {nsphere[0 ], nsphere[1 ], nsphere[2 ]};
194195 float axislength = sqrtf (axis[0 ] * axis[0 ] + axis[1 ] * axis[1 ] + axis[2 ] * axis[2 ]);
@@ -353,7 +354,7 @@ meshopt_Bounds meshopt_computeSphereBounds(const float* positions, size_t count,
353354 const float rzero = 0 .f ;
354355
355356 float psphere[4 ] = {};
356- computeBoundingSphere (psphere, positions, count, positions_stride, radii ? radii : &rzero, radii ? radii_stride : 0 , 7 );
357+ computeBoundingSphere< 7 > (psphere, positions, count, positions_stride, radii ? radii : &rzero, radii ? radii_stride : 0 );
357358
358359 bounds.center [0 ] = psphere[0 ];
359360 bounds.center [1 ] = psphere[1 ];
0 commit comments