Skip to content

Commit 106db31

Browse files
committed
LODSphereMesh: fix MSVC capture error in buildStitchTriangles
MSVC rejects using the constexpr locals N/stride inside the vid/snap lambdas without an explicit capture (C3493), while capturing them trips Clang's unused-capture warning. Reference the namespace-scope CHUNK_RES directly so no capture is needed on either compiler.
1 parent 3262777 commit 106db31

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

src/celengine/lodspheremesh.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,22 @@ LODSphereMesh::ensureBuffers()
238238
static void
239239
buildStitchTriangles(int mask, std::vector<unsigned int>& out)
240240
{
241-
constexpr int N = CHUNK_RES;
242-
constexpr auto stride = static_cast<unsigned int>(N + 1);
243241
auto vid = [](int a, int b) {
244-
return static_cast<unsigned int>(a * static_cast<int>(stride) + b);
242+
return static_cast<unsigned int>(a * (CHUNK_RES + 1) + b);
245243
};
246244
auto snap = [mask](int a, int b) {
247245
if (a == 0 && (mask & EDGE_LEFT) != 0 && (b & 1) != 0) --b;
248-
if (a == N && (mask & EDGE_RIGHT) != 0 && (b & 1) != 0) --b;
246+
if (a == CHUNK_RES && (mask & EDGE_RIGHT) != 0 && (b & 1) != 0) --b;
249247
if (b == 0 && (mask & EDGE_BOTTOM) != 0 && (a & 1) != 0) --a;
250-
if (b == N && (mask & EDGE_TOP) != 0 && (a & 1) != 0) --a;
248+
if (b == CHUNK_RES && (mask & EDGE_TOP) != 0 && (a & 1) != 0) --a;
251249
return std::pair<int, int>(a, b);
252250
};
253251

254252
out.clear();
255-
out.reserve(static_cast<std::size_t>(N) * N * 6);
256-
for (int ii = 0; ii < N; ++ii)
253+
out.reserve(static_cast<std::size_t>(CHUNK_RES) * CHUNK_RES * 6);
254+
for (int ii = 0; ii < CHUNK_RES; ++ii)
257255
{
258-
for (int jj = 0; jj < N; ++jj)
256+
for (int jj = 0; jj < CHUNK_RES; ++jj)
259257
{
260258
auto [a00, b00] = snap(ii, jj);
261259
auto [a10, b10] = snap(ii + 1, jj);
@@ -334,8 +332,8 @@ LODSphereMesh::getOrCreateChunk(const ChunkKey& key, unsigned int attributes)
334332
if (it != chunkCache.end())
335333
return &it->second;
336334

337-
const bool wantTangents = (attributes & Tangents) != 0;
338-
const bool wantTex = nTexturesUsed > 0;
335+
bool wantTangents = (attributes & Tangents) != 0;
336+
bool wantTex = nTexturesUsed > 0;
339337

340338
double cols = static_cast<double>(1u << (key.depth + 1));
341339
double rows = static_cast<double>(1u << key.depth);
@@ -394,10 +392,10 @@ LODSphereMesh::appendChunk(const ChunkMesh& chunk, unsigned int edgeMask,
394392
auto baseVertex = static_cast<unsigned int>(batchVertices.size()
395393
/ static_cast<std::size_t>(batchVertexSize));
396394

397-
const std::size_t nVerts = chunk.vertices.size()
395+
std::size_t nVerts = chunk.vertices.size()
398396
/ static_cast<std::size_t>(srcVertexSize);
399-
const bool srcHasUV = srcVertexSize > prefixFloats;
400-
const int mapOff = prefixFloats; // map fraction (sf, tf) in the source vertex
397+
bool srcHasUV = srcVertexSize > prefixFloats;
398+
int mapOff = prefixFloats; // map fraction (sf, tf) in the source vertex
401399

402400
for (std::size_t v = 0; v < nVerts; ++v)
403401
{
@@ -827,7 +825,7 @@ LODSphereMesh::uploadAndBindBatch(unsigned int attributes, CelestiaGLProgram* pr
827825
batchVertices.size() * sizeof(float)),
828826
gl::Buffer::BufferUsage::StreamDraw);
829827

830-
const auto stride = static_cast<GLsizei>(batchVertexSize * sizeof(float));
828+
auto stride = static_cast<GLsizei>(batchVertexSize * sizeof(float));
831829

832830
glEnableVertexAttribArray(CelestiaGLProgram::VertexCoordAttributeIndex);
833831
glVertexAttribPointer(CelestiaGLProgram::VertexCoordAttributeIndex,
@@ -867,7 +865,7 @@ LODSphereMesh::uploadAndBindBatch(unsigned int attributes, CelestiaGLProgram* pr
867865
void
868866
LODSphereMesh::drawBatch(unsigned int attributes)
869867
{
870-
const GLenum primitive = LODSPHERE_WIREFRAME ? GL_LINES : GL_TRIANGLES;
868+
GLenum primitive = LODSPHERE_WIREFRAME ? GL_LINES : GL_TRIANGLES;
871869
for (const DrawGroup& g : frameGroups)
872870
{
873871
for (int tc = 0; tc < nTexturesUsed; ++tc)

0 commit comments

Comments
 (0)