Browse Source

GL: remove one function pointer indirection for certain glDraw calls.

The extension-epcific code paths can reference the GL APIs directly, no
need to go through another function.
pull/495/head
Vladimír Vondruš 5 years ago
parent
commit
765ecee1f2
  1. 12
      src/Magnum/GL/Implementation/MeshState.cpp
  2. 4
      src/Magnum/GL/Implementation/MeshState.h
  3. 40
      src/Magnum/GL/Mesh.cpp
  4. 14
      src/Magnum/GL/Mesh.h

12
src/Magnum/GL/Implementation/MeshState.cpp

@ -159,8 +159,8 @@ MeshState::MeshState(Context& context, ContextState& contextState, std::vector<s
if(context.isExtensionSupported<Extensions::ANGLE::instanced_arrays>()) {
extensions.push_back(Extensions::ANGLE::instanced_arrays::string());
drawArraysInstancedImplementation = &Mesh::drawArraysInstancedImplementationANGLE;
drawElementsInstancedImplementation = &Mesh::drawElementsInstancedImplementationANGLE;
drawArraysInstancedImplementation = glDrawArraysInstancedANGLE;
drawElementsInstancedImplementation = glDrawElementsInstancedANGLE;
}
#ifndef MAGNUM_TARGET_WEBGL
else if(context.isExtensionSupported<Extensions::EXT::instanced_arrays>() ||
@ -169,8 +169,8 @@ MeshState::MeshState(Context& context, ContextState& contextState, std::vector<s
Extensions::EXT::instanced_arrays::string() :
Extensions::EXT::draw_instanced::string());
drawArraysInstancedImplementation = &Mesh::drawArraysInstancedImplementationEXT;
drawElementsInstancedImplementation = &Mesh::drawElementsInstancedImplementationEXT;
drawArraysInstancedImplementation = glDrawArraysInstancedEXT;
drawElementsInstancedImplementation = glDrawElementsInstancedEXT;
} else if(context.isExtensionSupported<Extensions::NV::instanced_arrays>() ||
context.isExtensionSupported<Extensions::NV::draw_instanced>()) {
@ -178,8 +178,8 @@ MeshState::MeshState(Context& context, ContextState& contextState, std::vector<s
Extensions::NV::instanced_arrays::string() :
Extensions::NV::draw_instanced::string());
drawArraysInstancedImplementation = &Mesh::drawArraysInstancedImplementationNV;
drawElementsInstancedImplementation = &Mesh::drawElementsInstancedImplementationNV;
drawArraysInstancedImplementation = glDrawArraysInstancedNV;
drawElementsInstancedImplementation = glDrawElementsInstancedNV;
}
#endif
else {

4
src/Magnum/GL/Implementation/MeshState.h

@ -54,8 +54,8 @@ struct MeshState {
void(Mesh::*unbindImplementation)();
#ifdef MAGNUM_TARGET_GLES2
void(Mesh::*drawArraysInstancedImplementation)(GLint, GLsizei, GLsizei);
void(Mesh::*drawElementsInstancedImplementation)(GLsizei, GLintptr, GLsizei);
void(APIENTRY *drawArraysInstancedImplementation)(GLenum, GLint, GLsizei, GLsizei);
void(APIENTRY *drawElementsInstancedImplementation)(GLenum, GLsizei, GLenum, const void*, GLsizei);
#endif
#ifdef MAGNUM_TARGET_GLES

40
src/Magnum/GL/Mesh.cpp

@ -467,10 +467,11 @@ void Mesh::drawInternal(Int count, Int baseVertex, Int instanceCount, GLintptr i
#endif
{
#ifndef MAGNUM_TARGET_GLES2
glDrawArraysInstanced(GLenum(_primitive), baseVertex, count, instanceCount);
glDrawArraysInstanced
#else
(this->*state.drawArraysInstancedImplementation)(baseVertex, count, instanceCount);
state.drawArraysInstancedImplementation
#endif
(GLenum(_primitive), baseVertex, count, instanceCount);
}
/* Indexed mesh with base vertex */
@ -503,10 +504,11 @@ void Mesh::drawInternal(Int count, Int baseVertex, Int instanceCount, GLintptr i
#endif
{
#ifndef MAGNUM_TARGET_GLES2
glDrawElementsInstanced(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset), instanceCount);
glDrawElementsInstanced
#else
(this->*state.drawElementsInstancedImplementation)(count, indexOffset, instanceCount);
state.drawElementsInstancedImplementation
#endif
(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset), instanceCount);
}
}
}
@ -871,34 +873,4 @@ void Mesh::unbindImplementationDefault() {
void Mesh::unbindImplementationVAO() {}
#ifdef MAGNUM_TARGET_GLES2
void Mesh::drawArraysInstancedImplementationANGLE(const GLint baseVertex, const GLsizei count, const GLsizei instanceCount) {
glDrawArraysInstancedANGLE(GLenum(_primitive), baseVertex, count, instanceCount);
}
#ifndef MAGNUM_TARGET_WEBGL
void Mesh::drawArraysInstancedImplementationEXT(const GLint baseVertex, const GLsizei count, const GLsizei instanceCount) {
glDrawArraysInstancedEXT(GLenum(_primitive), baseVertex, count, instanceCount);
}
void Mesh::drawArraysInstancedImplementationNV(const GLint baseVertex, const GLsizei count, const GLsizei instanceCount) {
glDrawArraysInstancedNV(GLenum(_primitive), baseVertex, count, instanceCount);
}
#endif
void Mesh::drawElementsInstancedImplementationANGLE(const GLsizei count, const GLintptr indexOffset, const GLsizei instanceCount) {
glDrawElementsInstancedANGLE(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset), instanceCount);
}
#ifndef MAGNUM_TARGET_WEBGL
void Mesh::drawElementsInstancedImplementationEXT(const GLsizei count, const GLintptr indexOffset, const GLsizei instanceCount) {
glDrawElementsInstancedEXT(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset), instanceCount);
}
void Mesh::drawElementsInstancedImplementationNV(const GLsizei count, const GLintptr indexOffset, const GLsizei instanceCount) {
glDrawElementsInstancedNV(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset), instanceCount);
}
#endif
#endif
}}

14
src/Magnum/GL/Mesh.h

@ -1133,20 +1133,6 @@ class MAGNUM_GL_EXPORT Mesh: public AbstractObject {
void MAGNUM_GL_LOCAL unbindImplementationDefault();
void MAGNUM_GL_LOCAL unbindImplementationVAO();
#ifdef MAGNUM_TARGET_GLES2
void MAGNUM_GL_LOCAL drawArraysInstancedImplementationANGLE(GLint baseVertex, GLsizei count, GLsizei instanceCount);
#ifndef MAGNUM_TARGET_WEBGL
void MAGNUM_GL_LOCAL drawArraysInstancedImplementationEXT(GLint baseVertex, GLsizei count, GLsizei instanceCount);
void MAGNUM_GL_LOCAL drawArraysInstancedImplementationNV(GLint baseVertex, GLsizei count, GLsizei instanceCount);
#endif
void MAGNUM_GL_LOCAL drawElementsInstancedImplementationANGLE(GLsizei count, GLintptr indexOffset, GLsizei instanceCount);
#ifndef MAGNUM_TARGET_WEBGL
void MAGNUM_GL_LOCAL drawElementsInstancedImplementationEXT(GLsizei count, GLintptr indexOffset, GLsizei instanceCount);
void MAGNUM_GL_LOCAL drawElementsInstancedImplementationNV(GLsizei count, GLintptr indexOffset, GLsizei instanceCount);
#endif
#endif
/* _id, _primitive, _flags set from constructors */
GLuint _id;
MeshPrimitive _primitive;

Loading…
Cancel
Save