From 59b88e5aef1a82c4511e92af49a4a24da188ef2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 14 Feb 2018 13:04:43 +0100 Subject: [PATCH] Make VAO binding into a dedicated function. It's used from more than one place. --- src/Magnum/Buffer.cpp | 9 ++------- src/Magnum/Implementation/MeshState.cpp | 2 ++ src/Magnum/Implementation/MeshState.h | 2 ++ src/Magnum/Mesh.cpp | 17 ++++++++++++----- src/Magnum/Mesh.h | 5 +++++ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/Magnum/Buffer.cpp b/src/Magnum/Buffer.cpp index 4b811edca..722fb7c4a 100644 --- a/src/Magnum/Buffer.cpp +++ b/src/Magnum/Buffer.cpp @@ -283,13 +283,8 @@ auto Buffer::bindSomewhereInternal(const TargetHint hint) -> TargetHint { auto& currentVAO = Context::current().state().mesh->currentVAO; /* It can be also State::DisengagedBinding, in which case we unbind as well to be sure */ - if(currentVAO != 0) { - #ifndef MAGNUM_TARGET_GLES2 - glBindVertexArray(currentVAO = 0); - #else - glBindVertexArrayOES(currentVAO = 0); - #endif - } + if(currentVAO != 0) + Context::current().state().mesh->bindVAOImplementation(0); } /* Bind the buffer to hint target otherwise */ diff --git a/src/Magnum/Implementation/MeshState.cpp b/src/Magnum/Implementation/MeshState.cpp index c2309b8d5..4b77c241c 100644 --- a/src/Magnum/Implementation/MeshState.cpp +++ b/src/Magnum/Implementation/MeshState.cpp @@ -68,6 +68,7 @@ MeshState::MeshState(Context& context, ContextState& contextState, std::vector>); #endif + void(*bindVAOImplementation)(GLuint); + #ifndef MAGNUM_TARGET_GLES GLuint defaultVAO{}; /* Used on core profile in case ARB_VAO is disabled */ #endif diff --git a/src/Magnum/Mesh.cpp b/src/Magnum/Mesh.cpp index 31ada4665..5d7ebc32c 100644 --- a/src/Magnum/Mesh.cpp +++ b/src/Magnum/Mesh.cpp @@ -418,16 +418,23 @@ void Mesh::draw(AbstractShaderProgram& shader, TransformFeedback& xfb, UnsignedI } #endif +void Mesh::bindVAOImplementationDefault(GLuint) {} + +void Mesh::bindVAOImplementationVAO(const GLuint id) { + #ifndef MAGNUM_TARGET_GLES2 + glBindVertexArray + #else + glBindVertexArrayOES + #endif + (Context::current().state().mesh->currentVAO = id); +} + void Mesh::bindVAO() { GLuint& current = Context::current().state().mesh->currentVAO; if(current != _id) { /* Binding the VAO finally creates it */ _flags |= ObjectFlag::Created; - #ifndef MAGNUM_TARGET_GLES2 - glBindVertexArray(current = _id); - #else - glBindVertexArrayOES(current = _id); - #endif + bindVAOImplementationVAO(_id); } } diff --git a/src/Magnum/Mesh.h b/src/Magnum/Mesh.h index e82be879e..0dcaf3d38 100644 --- a/src/Magnum/Mesh.h +++ b/src/Magnum/Mesh.h @@ -1043,6 +1043,11 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { #endif #endif + /* Unconditionally binds a specified VAO and updates the state tracker. + Used also in Buffer::bindSomewhereInternal(). */ + static void MAGNUM_LOCAL bindVAOImplementationDefault(GLuint id); + static void MAGNUM_LOCAL bindVAOImplementationVAO(GLuint id); + void MAGNUM_LOCAL bindVAO(); #ifndef MAGNUM_TARGET_GLES