From d2adc0573970b6a71cce9a8c2e66608b5444eacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 3 Mar 2023 23:00:33 +0100 Subject: [PATCH] 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. --- .../GL/Implementation/RendererState.cpp | 11 +++---- src/Magnum/GL/Implementation/RendererState.h | 10 +++---- src/Magnum/GL/Renderer.cpp | 30 +++---------------- src/Magnum/GL/Renderer.h | 16 +++------- 4 files changed, 19 insertions(+), 48 deletions(-) diff --git a/src/Magnum/GL/Implementation/RendererState.cpp b/src/Magnum/GL/Implementation/RendererState.cpp index 69cae0f17..4d7fe8961 100644 --- a/src/Magnum/GL/Implementation/RendererState.cpp +++ b/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(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[Extensions::OES::sample_shading::Index] = Extensions::OES::sample_shading::string(); - minSampleShadingImplementation = &Renderer::minSampleShadingImplementationOES; + minSampleShadingImplementation = glMinSampleShadingOES; } else { minSampleShadingImplementation = nullptr; } diff --git a/src/Magnum/GL/Implementation/RendererState.h b/src/Magnum/GL/Implementation/RendererState.h index 17b398cb7..ee64f91fd 100644 --- a/src/Magnum/GL/Implementation/RendererState.h +++ b/src/Magnum/GL/Implementation/RendererState.h @@ -36,12 +36,12 @@ struct RendererState { explicit RendererState(Context& context, ContextState& contextState, Containers::StaticArrayView 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 diff --git a/src/Magnum/GL/Renderer.cpp b/src/Magnum/GL/Renderer.cpp index 5825f329b..0e59c3305 100644 --- a/src/Magnum/GL/Renderer.cpp +++ b/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 diff --git a/src/Magnum/GL/Renderer.h b/src/Magnum/GL/Renderer.h index f4190fbfa..0dc53863f 100644 --- a/src/Magnum/GL/Renderer.h +++ b/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 };