Browse Source

GL: call GL APIs directly from Renderer where possible.

Instead of having them wrapped in extra functions for
extension-dependent functionality. The only case that stays is the line
width range implementation, as the raw variant looked too ugly /
dangerous otherwise.
pull/601/head
Vladimír Vondruš 3 years ago
parent
commit
d2adc05739
  1. 11
      src/Magnum/GL/Implementation/RendererState.cpp
  2. 10
      src/Magnum/GL/Implementation/RendererState.h
  3. 30
      src/Magnum/GL/Renderer.cpp
  4. 16
      src/Magnum/GL/Renderer.h

11
src/Magnum/GL/Implementation/RendererState.cpp

@ -50,7 +50,7 @@ RendererState::RendererState(Context& context, ContextState& contextState, Conta
Extensions::ARB::ES2_compatibility::string();
#endif
clearDepthfImplementation = &Renderer::clearDepthfImplementationES;
clearDepthfImplementation = glClearDepthf;
}
#ifndef MAGNUM_TARGET_GLES
else clearDepthfImplementation = &Renderer::clearDepthfImplementationDefault;
@ -67,12 +67,13 @@ RendererState::RendererState(Context& context, ContextState& contextState, Conta
#ifndef MAGNUM_TARGET_GLES
extensions[Extensions::ARB::robustness::Index] =
Extensions::ARB::robustness::string();
graphicsResetStatusImplementation = glGetGraphicsResetStatusARB;
#else
extensions[Extensions::EXT::robustness::Index] =
Extensions::EXT::robustness::string();
graphicsResetStatusImplementation = glGetGraphicsResetStatusEXT;
#endif
graphicsResetStatusImplementation = &Renderer::graphicsResetStatusImplementationRobustness;
} else graphicsResetStatusImplementation = &Renderer::graphicsResetStatusImplementationDefault;
#else
static_cast<void>(context);
@ -104,15 +105,15 @@ RendererState::RendererState(Context& context, ContextState& contextState, Conta
}
#ifndef MAGNUM_TARGET_GLES
minSampleShadingImplementation = &Renderer::minSampleShadingImplementationDefault;
minSampleShadingImplementation = glMinSampleShading;
#elif !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
if(context.isVersionSupported(Version::GLES320)) {
minSampleShadingImplementation = &Renderer::minSampleShadingImplementationDefault;
minSampleShadingImplementation = glMinSampleShading;
} else if(context.isExtensionSupported<Extensions::OES::sample_shading>()) {
extensions[Extensions::OES::sample_shading::Index] =
Extensions::OES::sample_shading::string();
minSampleShadingImplementation = &Renderer::minSampleShadingImplementationOES;
minSampleShadingImplementation = glMinSampleShadingOES;
} else {
minSampleShadingImplementation = nullptr;
}

10
src/Magnum/GL/Implementation/RendererState.h

@ -36,12 +36,12 @@ struct RendererState {
explicit RendererState(Context& context, ContextState& contextState, Containers::StaticArrayView<Implementation::ExtensionCount, const char*> extensions);
Range1D(*lineWidthRangeImplementation)();
void(*clearDepthfImplementation)(GLfloat);
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void(*minSampleShadingImplementation)(GLfloat);
#endif
/* These are direct pointers to the GL functions, so need a __stdcall on
Windows to compile properly on 32 bits */
void(APIENTRY *clearDepthfImplementation)(GLfloat);
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void(APIENTRY *minSampleShadingImplementation)(GLfloat);
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void(APIENTRY *patchParameteriImplementation)(GLenum, GLint);
#endif
@ -55,7 +55,7 @@ struct RendererState {
void(APIENTRY *colorMaskiImplementation)(GLuint, GLboolean, GLboolean, GLboolean, GLboolean);
#endif
#ifndef MAGNUM_TARGET_WEBGL
Renderer::GraphicsResetStatus(*graphicsResetStatusImplementation)();
GLenum(APIENTRY *graphicsResetStatusImplementation)();
Renderer::ResetNotificationStrategy resetNotificationStrategy;
#endif

30
src/Magnum/GL/Renderer.cpp

@ -149,18 +149,8 @@ void Renderer::setPointSize(const Float size) {
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
void Renderer::setMinSampleShading(const Float value) {
(Context::current().state().renderer.minSampleShadingImplementation)(value);
Context::current().state().renderer.minSampleShadingImplementation(value);
}
void Renderer::minSampleShadingImplementationDefault(const GLfloat value) {
glMinSampleShading(value);
}
#ifdef MAGNUM_TARGET_GLES
void Renderer::minSampleShadingImplementationOES(const GLfloat value) {
glMinSampleShadingOES(value);
}
#endif
#endif
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
@ -402,7 +392,7 @@ Renderer::ResetNotificationStrategy Renderer::resetNotificationStrategy() {
}
Renderer::GraphicsResetStatus Renderer::graphicsResetStatus() {
return Context::current().state().renderer.graphicsResetStatusImplementation();
return Renderer::GraphicsResetStatus(Context::current().state().renderer.graphicsResetStatusImplementation());
}
#endif
@ -418,21 +408,9 @@ void Renderer::clearDepthfImplementationDefault(const GLfloat depth) {
}
#endif
void Renderer::clearDepthfImplementationES(const GLfloat depth) {
glClearDepthf(depth);
}
#ifndef MAGNUM_TARGET_WEBGL
Renderer::GraphicsResetStatus Renderer::graphicsResetStatusImplementationDefault() {
return GraphicsResetStatus::NoError;
}
Renderer::GraphicsResetStatus Renderer::graphicsResetStatusImplementationRobustness() {
#ifndef MAGNUM_TARGET_GLES
return GraphicsResetStatus(glGetGraphicsResetStatusARB());
#else
return GraphicsResetStatus(glGetGraphicsResetStatusEXT());
#endif
GLenum Renderer::graphicsResetStatusImplementationDefault() {
return GL_NO_ERROR;
}
#endif

16
src/Magnum/GL/Renderer.h

@ -2193,21 +2193,13 @@ class MAGNUM_GL_EXPORT Renderer {
static MAGNUM_GL_LOCAL Range1D lineWidthRangeImplementationMesaForwardCompatible();
#endif
/* These have to be compatible with direct pointers to the GL functions
which need a __stdcall on Windows to compile properly on 32 bits */
#ifndef MAGNUM_TARGET_GLES
static void MAGNUM_GL_LOCAL clearDepthfImplementationDefault(GLfloat depth);
static void APIENTRY MAGNUM_GL_LOCAL clearDepthfImplementationDefault(GLfloat depth);
#endif
static void MAGNUM_GL_LOCAL clearDepthfImplementationES(GLfloat depth);
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
static MAGNUM_GL_LOCAL void minSampleShadingImplementationDefault(GLfloat value);
#ifdef MAGNUM_TARGET_GLES
static MAGNUM_GL_LOCAL void minSampleShadingImplementationOES(GLfloat value);
#endif
#endif
#ifndef MAGNUM_TARGET_WEBGL
static GraphicsResetStatus MAGNUM_GL_LOCAL graphicsResetStatusImplementationDefault();
static GraphicsResetStatus MAGNUM_GL_LOCAL graphicsResetStatusImplementationRobustness();
static GLenum APIENTRY MAGNUM_GL_LOCAL graphicsResetStatusImplementationDefault();
#endif
};

Loading…
Cancel
Save