diff --git a/include/PICA/pica_simd.hpp b/include/PICA/pica_simd.hpp index c315f8b5a..ae7d04eb2 100644 --- a/include/PICA/pica_simd.hpp +++ b/include/PICA/pica_simd.hpp @@ -255,18 +255,18 @@ namespace PICA::IndexBuffer { // So we need to subtract the base vertex index from every index in the index buffer ourselves // This is not really common, so we do it without SIMD for the moment, just to be able to run on Android Studio template - void subtractBaseIndex(u8* indexBuffer, u32 vertexCount, u16 baseIndex) { + void subtractBaseIndex(u8* indexBuffer, u32 indexCount, u16 baseIndex) { // Calculate the minimum and maximum indices used in the index buffer, so we'll only upload them if constexpr (useShortIndices) { u16* indexBuffer16 = reinterpret_cast(indexBuffer); - for (u32 i = 0; i < vertexCount; i++) { + for (u32 i = 0; i < indexCount; i++) { indexBuffer16[i] -= baseIndex; } } else { u8 baseIndex8 = u8(baseIndex); - for (u32 i = 0; i < vertexCount; i++) { + for (u32 i = 0; i < indexCount; i++) { indexBuffer[i] -= baseIndex8; } } diff --git a/include/renderer_gl/gl_driver.hpp b/include/renderer_gl/gl_driver.hpp index c7109b011..a15c061f6 100644 --- a/include/renderer_gl/gl_driver.hpp +++ b/include/renderer_gl/gl_driver.hpp @@ -6,8 +6,6 @@ namespace OpenGL { struct Driver { bool supportsExtFbFetch = false; bool supportsArmFbFetch = false; - // Does this driver support glDraw(Range)ElementsBaseVertex? - bool supportsDrawElementsBaseVertex = false; bool supportFbFetch() const { return supportsExtFbFetch || supportsArmFbFetch; } }; diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index ba0516155..90b8f9101 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -195,7 +195,6 @@ void RendererGL::initGraphicsContextInternal() { // Populate our driver info structure driverInfo.supportsExtFbFetch = (GLAD_GL_EXT_shader_framebuffer_fetch != 0); driverInfo.supportsArmFbFetch = (GLAD_GL_ARM_shader_framebuffer_fetch != 0); - driverInfo.supportsDrawElementsBaseVertex = (glDrawRangeElementsBaseVertex != nullptr); // Initialize the default vertex shader used with shadergen std::string defaultShadergenVSSource = fragShaderGen.getDefaultVertexShader(); @@ -531,7 +530,7 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span v // If glDrawRangeElementsBaseVertex is not available then prepareForDraw will have subtracted the base vertex from the index buffer // for us, so just use glDrawRangeElements glDrawRangeElements( - primitiveTopology, 0, maximumIndex - minimumIndex, GLsizei(vertices.size()), + primitiveTopology, 0, GLint(maximumIndex - minimumIndex), GLsizei(vertices.size()), usingShortIndices ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE, hwIndexBufferOffset ); } @@ -1183,9 +1182,10 @@ void RendererGL::accelerateVertexUpload(ShaderUnit& shaderUnit, PICA::DrawAccele std::memcpy(indexBufferRes.pointer, accel->indexBuffer, indexBufferSize); // If we don't have glDrawRangeElementsBaseVertex, we must subtract the base index value from our index buffer manually - if (!driverInfo.supportsDrawElementsBaseVertex) [[unlikely]] { - usingShortIndices ? PICA::IndexBuffer::subtractBaseIndex((u8*)indexBufferRes.pointer, vertexCount, accel->minimumIndex) - : PICA::IndexBuffer::subtractBaseIndex((u8*)indexBufferRes.pointer, vertexCount, accel->minimumIndex); + if (glDrawRangeElementsBaseVertex == nullptr) [[unlikely]] { + const u32 indexCount = regs[PICA::InternalRegs::VertexCountReg]; + usingShortIndices ? PICA::IndexBuffer::subtractBaseIndex((u8*)indexBufferRes.pointer, indexCount, accel->minimumIndex) + : PICA::IndexBuffer::subtractBaseIndex((u8*)indexBufferRes.pointer, indexCount, accel->minimumIndex); } hwIndexBuffer->Unmap(indexBufferSize);