From 169031fb7bf30e2c98c81cbf865aa5a4662aa716 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2019 12:47:56 +0100 Subject: [PATCH] GL: reset element buffer binding state tracker when switching VAOs. Fixes the failing test from previous commit and obsoletes another incomplete and ugly state tracking fix. --- src/Magnum/GL/Mesh.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Magnum/GL/Mesh.cpp b/src/Magnum/GL/Mesh.cpp index 832c9fa92..09a60d9c3 100644 --- a/src/Magnum/GL/Mesh.cpp +++ b/src/Magnum/GL/Mesh.cpp @@ -544,6 +544,13 @@ void Mesh::bindVAO() { /* Binding the VAO finally creates it */ _flags |= ObjectFlag::Created; bindVAOImplementationVAO(_id); + + /* Reset element buffer binding, because binding a different VAO with a + different index buffer will change that binding as well. (GL state, + what the hell.) We could also theoretically reset the binding + directly to _indexBuffer->id(), but let's play safe and force the + rebind every time. */ + Context::current().state().buffer->bindings[Implementation::BufferState::indexForTarget(Buffer::TargetHint::ElementArray)] = _indexBuffer.id(); } } @@ -769,10 +776,8 @@ void Mesh::bindIndexBufferImplementationDefault(Buffer&) {} void Mesh::bindIndexBufferImplementationVAO(Buffer& buffer) { bindVAO(); - /* Reset ElementArray binding to force explicit glBindBuffer call later */ - /** @todo Do this cleaner way */ - Context::current().state().buffer->bindings[Implementation::BufferState::indexForTarget(Buffer::TargetHint::ElementArray)] = 0; - + /* Binding the VAO in the above function resets element buffer binding, + meaning the following will always cause the glBindBuffer() to be called */ buffer.bindInternal(Buffer::TargetHint::ElementArray); }