From 90aff3bdbd17f2d6ce8eddac04ba2a01a43a759c Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Thu, 9 Apr 2026 20:31:40 -0300 Subject: [PATCH] graphics: fix state tracking when an indexed batched draw has 0 indices. fixes #2291. --- src/modules/graphics/Graphics.cpp | 12 +++++++----- src/modules/graphics/Graphics.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 458ba9e16..77b2fb241 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -1954,10 +1954,11 @@ Graphics::BatchedVertexData Graphics::requestBatchedDraw(const BatchedDrawComman bool shouldflush = false; bool shouldresize = false; + bool indexeddraw = cmd.indexMode != TRIANGLEINDEX_NONE; if (cmd.primitiveMode != state.primitiveMode || cmd.formats[0] != state.formats[0] || cmd.formats[1] != state.formats[1] - || ((cmd.indexMode != TRIANGLEINDEX_NONE) != (state.indexCount > 0)) + || indexeddraw != state.indexedDraw || cmd.texture != state.texture || cmd.standardShaderType != state.standardShaderType) { @@ -1967,7 +1968,7 @@ Graphics::BatchedVertexData Graphics::requestBatchedDraw(const BatchedDrawComman int totalvertices = state.vertexCount + cmd.vertexCount; // We only support uint16 index buffers for now. - if (totalvertices > LOVE_UINT16_MAX && cmd.indexMode != TRIANGLEINDEX_NONE) + if (totalvertices > LOVE_UINT16_MAX && indexeddraw) shouldflush = true; int reqIndexCount = getIndexCount(cmd.indexMode, cmd.vertexCount); @@ -1996,7 +1997,7 @@ Graphics::BatchedVertexData Graphics::requestBatchedDraw(const BatchedDrawComman newdatasizes[i] = stride * cmd.vertexCount; } - if (cmd.indexMode != TRIANGLEINDEX_NONE) + if (indexeddraw) { size_t datasize = (state.indexCount + reqIndexCount) * sizeof(uint16); @@ -2015,6 +2016,7 @@ Graphics::BatchedVertexData Graphics::requestBatchedDraw(const BatchedDrawComman flushBatchedDraws(); state.primitiveMode = cmd.primitiveMode; + state.indexedDraw = indexeddraw; state.formats[0] = cmd.formats[0]; state.formats[1] = cmd.formats[1]; state.texture = cmd.texture; @@ -2048,7 +2050,7 @@ Graphics::BatchedVertexData Graphics::requestBatchedDraw(const BatchedDrawComman } } - if (cmd.indexMode != TRIANGLEINDEX_NONE) + if (indexeddraw) { if (state.indexBufferMap.data == nullptr) state.indexBufferMap = state.indexBuffer->map(reqIndexSize); @@ -2129,7 +2131,7 @@ void Graphics::flushBatchedDraws() pushIdentityTransform(); - if (sbstate.indexCount > 0) + if (sbstate.indexedDraw) { usedsizes[2] = sizeof(uint16) * sbstate.indexCount; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 13f93b7ff..5c235f6df 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -974,6 +974,7 @@ protected: StreamBuffer *indexBuffer = nullptr; PrimitiveType primitiveMode = PRIMITIVE_TRIANGLES; + bool indexedDraw = false; CommonFormat formats[2] = {}; StrongRef texture; Shader::StandardShader standardShaderType = Shader::STANDARD_DEFAULT;