From a38e873f8aee88f3cd17a4290d8b172c35701227 Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Fri, 25 Oct 2019 14:56:54 +0200 Subject: [PATCH] rebind instance data buffer if index buffer changes Fix case of drawing different indices of same vertex buffer using same instance data. This can happen in the case of conditionally drawing subsets of vertex buffer stored in different index buffers while re-using non-transient instance buffers. --- src/renderer_gl.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 89f3ff8c8..8aa9f950c 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -7195,6 +7195,8 @@ namespace bgfx { namespace gl { bool diffStreamHandles = false; + bool diffIndexBuffer = false; + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask ; streamMask >>= 1, idx += 1 @@ -7252,6 +7254,8 @@ namespace bgfx { namespace gl { GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) ); } + + diffIndexBuffer = true; } if (0 != currentState.m_streamMask) @@ -7308,7 +7312,10 @@ namespace bgfx { namespace gl } program.bindAttributesEnd(); + } + if (bindAttribs || diffStartVertex || diffIndexBuffer) + { if (isValid(draw.m_instanceDataBuffer) ) { GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[draw.m_instanceDataBuffer.idx].m_id) );