Browse Source

Make VAO binding into a dedicated function.

It's used from more than one place.
pull/231/head
Vladimír Vondruš 8 years ago
parent
commit
59b88e5aef
  1. 9
      src/Magnum/Buffer.cpp
  2. 2
      src/Magnum/Implementation/MeshState.cpp
  3. 2
      src/Magnum/Implementation/MeshState.h
  4. 17
      src/Magnum/Mesh.cpp
  5. 5
      src/Magnum/Mesh.h

9
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 */

2
src/Magnum/Implementation/MeshState.cpp

@ -68,6 +68,7 @@ MeshState::MeshState(Context& context, ContextState& contextState, std::vector<s
}
bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationVAO;
bindVAOImplementation = &Mesh::bindVAOImplementationVAO;
bindImplementation = &Mesh::bindImplementationVAO;
unbindImplementation = &Mesh::unbindImplementationVAO;
}
@ -77,6 +78,7 @@ MeshState::MeshState(Context& context, ContextState& contextState, std::vector<s
destroyImplementation = &Mesh::destroyImplementationDefault;
attributePointerImplementation = &Mesh::attributePointerImplementationDefault;
bindIndexBufferImplementation = &Mesh::bindIndexBufferImplementationDefault;
bindVAOImplementation = &Mesh::bindVAOImplementationDefault;
bindImplementation = &Mesh::bindImplementationDefault;
unbindImplementation = &Mesh::unbindImplementationDefault;
}

2
src/Magnum/Implementation/MeshState.h

@ -59,6 +59,8 @@ struct MeshState {
void(*multiDrawImplementation)(std::initializer_list<std::reference_wrapper<MeshView>>);
#endif
void(*bindVAOImplementation)(GLuint);
#ifndef MAGNUM_TARGET_GLES
GLuint defaultVAO{}; /* Used on core profile in case ARB_VAO is disabled */
#endif

17
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);
}
}

5
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

Loading…
Cancel
Save