From bede836077af1bd67ee6e501d797dbf7ac7f1842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 4 Mar 2023 00:16:27 +0100 Subject: [PATCH] GL: expose Renderer::setDepthRange(). --- doc/changelog.dox | 1 + doc/opengl-mapping.dox | 2 +- .../GL/Implementation/RendererState.cpp | 8 +++-- src/Magnum/GL/Implementation/RendererState.h | 1 + src/Magnum/GL/Renderer.cpp | 16 ++++++++++ src/Magnum/GL/Renderer.h | 30 +++++++++++++++++-- src/Magnum/GL/Test/RendererGLTest.cpp | 19 ++++++++++-- 7 files changed, 70 insertions(+), 7 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 7cbe36428..ebcb52e84 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -153,6 +153,7 @@ See also: @relativeref{GL::Renderer,Feature::SampleAlphaToOne}, @relativeref{GL::Renderer,Feature::SampleCoverage} and @ref GL::Renderer::setSampleCoverage() GL 1.3 APIs +- Exposed missing @ref GL::Renderer::setDepthRange() GL 1.0 API - A new @cpp "nv-egl-crashy-query-device-attrib" @ce workaround for a crash happening during EGL initialization in recent NVidia drivers. See @ref opengl-workarounds and [mosra/magnum#491](https://github.com/mosra/magnum/pull/491) diff --git a/doc/opengl-mapping.dox b/doc/opengl-mapping.dox index b718c44a2..48a73ec54 100644 --- a/doc/opengl-mapping.dox +++ b/doc/opengl-mapping.dox @@ -131,7 +131,7 @@ OpenGL function | Matching API @fn_gl{DebugMessageInsert}, \n @fn_gl_extension{InsertEventMarker,EXT,debug_marker}, \n @fn_gl_extension{StringMarker,GREMEDY,string_marker} | @ref GL::DebugMessage::insert() @fn_gl{DepthFunc} | @ref GL::Renderer::setDepthFunction() @fn_gl{DepthMask} | @ref GL::Renderer::setDepthMask() -@fn_gl{DepthRange} | | +@fn_gl{DepthRange} | @ref GL::Renderer::setDepthRange() @fn_gl{DepthRangeArray} | | @fn_gl{DepthRangeIndexed} | | @fn_gl{DetachShader} | | diff --git a/src/Magnum/GL/Implementation/RendererState.cpp b/src/Magnum/GL/Implementation/RendererState.cpp index 4d7fe8961..56f12f6ff 100644 --- a/src/Magnum/GL/Implementation/RendererState.cpp +++ b/src/Magnum/GL/Implementation/RendererState.cpp @@ -40,7 +40,7 @@ RendererState::RendererState(Context& context, ContextState& contextState, Conta : resetNotificationStrategy() #endif { - /* Float depth clear value implementation */ + /* Float depth clear value / range implementation */ #ifndef MAGNUM_TARGET_GLES if(context.isExtensionSupported()) #endif @@ -51,9 +51,13 @@ RendererState::RendererState(Context& context, ContextState& contextState, Conta #endif clearDepthfImplementation = glClearDepthf; + depthRangefImplementation = glDepthRangef; } #ifndef MAGNUM_TARGET_GLES - else clearDepthfImplementation = &Renderer::clearDepthfImplementationDefault; + else { + clearDepthfImplementation = &Renderer::clearDepthfImplementationDefault; + depthRangefImplementation = &Renderer::depthRangefImplementationDefault; + } #endif #ifndef MAGNUM_TARGET_WEBGL diff --git a/src/Magnum/GL/Implementation/RendererState.h b/src/Magnum/GL/Implementation/RendererState.h index ee64f91fd..6f573a64d 100644 --- a/src/Magnum/GL/Implementation/RendererState.h +++ b/src/Magnum/GL/Implementation/RendererState.h @@ -39,6 +39,7 @@ struct RendererState { /* These are direct pointers to the GL functions, so need a __stdcall on Windows to compile properly on 32 bits */ void(APIENTRY *clearDepthfImplementation)(GLfloat); + void(APIENTRY *depthRangefImplementation)(GLfloat, GLfloat); #if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) void(APIENTRY *minSampleShadingImplementation)(GLfloat); #endif diff --git a/src/Magnum/GL/Renderer.cpp b/src/Magnum/GL/Renderer.cpp index aaf20630c..0ac3087c1 100644 --- a/src/Magnum/GL/Renderer.cpp +++ b/src/Magnum/GL/Renderer.cpp @@ -302,6 +302,22 @@ void Renderer::setDepthFunction(const DepthFunction function) { glDepthFunc(GLenum(function)); } +#ifndef MAGNUM_TARGET_GLES +void Renderer::setDepthRange(const Double near, const Double far) { + glDepthRange(near, far); +} +#endif + +void Renderer::setDepthRange(const Float near, const Float far) { + Context::current().state().renderer.depthRangefImplementation(near, far); +} + +#ifndef MAGNUM_TARGET_GLES +void Renderer::depthRangefImplementationDefault(const Float near, const Float far) { + glDepthRange(GLdouble(near), GLdouble(far)); +} +#endif + void Renderer::setColorMask(const GLboolean allowRed, const GLboolean allowGreen, const GLboolean allowBlue, const GLboolean allowAlpha) { glColorMask(allowRed, allowGreen, allowBlue, allowAlpha); } diff --git a/src/Magnum/GL/Renderer.h b/src/Magnum/GL/Renderer.h index e8acbbf30..35b9ae942 100644 --- a/src/Magnum/GL/Renderer.h +++ b/src/Magnum/GL/Renderer.h @@ -693,7 +693,7 @@ class MAGNUM_GL_EXPORT Renderer { * Initial value is @cpp 1.0 @ce. * @see @ref Feature::DepthTest, @ref AbstractFramebuffer::clearDepth(), * @ref AbstractFramebuffer::clearDepthStencil(), - * @fn_gl_keyword{ClearDepth} + * @ref setDepthRange(), @fn_gl_keyword{ClearDepth} * @requires_gl See @ref setClearDepth(Float), which is available in * OpenGL ES and WebGL. * @deprecated_gl Prefer to use @ref AbstractFramebuffer::clearDepth() @@ -713,7 +713,7 @@ class MAGNUM_GL_EXPORT Renderer { * @ref setClearDepth(Double). * @see @ref Feature::DepthTest, @ref AbstractFramebuffer::clearDepth(), * @ref AbstractFramebuffer::clearDepthStencil(), - * @fn_gl2_keyword{ClearDepthf,ClearDepth} + * @ref setDepthRange(), @fn_gl2_keyword{ClearDepthf,ClearDepth} * @deprecated_gl Prefer to use @ref AbstractFramebuffer::clearDepth() * / @ref AbstractFramebuffer::clearDepthStencil() instead of * @ref setClearDepth() and @ref AbstractFramebuffer::clear() as @@ -1192,6 +1192,31 @@ class MAGNUM_GL_EXPORT Renderer { */ static void setDepthFunction(DepthFunction function); + #ifndef MAGNUM_TARGET_GLES + /** + * @brief Set depth range + * @m_since_latest + * + * Initial value is @cpp 0.0 @ce and @cpp 1.0 @ce. + * @see @fn_gl_keyword{DepthRange} + * @requires_gl See @ref setClearDepth(Float), which is available in + * OpenGL ES and WebGL. + */ + static void setDepthRange(Double near, Double far); + #endif + + /** + * @overload + * @m_since_latest + * + * Initial value is @cpp 0.0 @ce and @cpp 1.0 @ce. If OpenGL ES, OpenGL + * 4.1 or extension @gl_extension{ARB,ES2_compatibility} is not + * available, this function behaves exactly as + * @ref setDepthRange(Double, Double). + * @see @fn_gl2_keyword{DepthRangef,DepthRange} + */ + static void setDepthRange(Float near, Float far); + /* Since 1.8.17, the original short-hand group closing doesn't work anymore. FFS. */ /** @@ -2239,6 +2264,7 @@ class MAGNUM_GL_EXPORT Renderer { which need a __stdcall on Windows to compile properly on 32 bits */ #ifndef MAGNUM_TARGET_GLES static void APIENTRY MAGNUM_GL_LOCAL clearDepthfImplementationDefault(GLfloat depth); + static void APIENTRY MAGNUM_GL_LOCAL depthRangefImplementationDefault(GLfloat near, GLfloat far); #endif #ifndef MAGNUM_TARGET_WEBGL static GLenum APIENTRY MAGNUM_GL_LOCAL graphicsResetStatusImplementationDefault(); diff --git a/src/Magnum/GL/Test/RendererGLTest.cpp b/src/Magnum/GL/Test/RendererGLTest.cpp index e9818be2c..cf10d655b 100644 --- a/src/Magnum/GL/Test/RendererGLTest.cpp +++ b/src/Magnum/GL/Test/RendererGLTest.cpp @@ -68,6 +68,7 @@ struct RendererGLTest: OpenGLTester { void drawBuffersIndexed(); void drawBuffersBlend(); #endif + template void clearDepthDepthRange(); private: PluginManager::Manager _manager{"nonexistent"}; @@ -87,9 +88,12 @@ RendererGLTest::RendererGLTest() { #endif #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) &RendererGLTest::drawBuffersIndexed, - &RendererGLTest::drawBuffersBlend + &RendererGLTest::drawBuffersBlend, #endif - }); + #ifndef MAGNUM_TARGET_GLES + &RendererGLTest::clearDepthDepthRange, + #endif + &RendererGLTest::clearDepthDepthRange}); /* Load the plugins directly from the build tree. Otherwise they're either static and already loaded or not present in the build tree */ @@ -299,6 +303,17 @@ void RendererGLTest::drawBuffersBlend() { } #endif +template void RendererGLTest::clearDepthDepthRange() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + /* Just setting the default value to verify it doesn't crash or emit an + error in either of the overloads */ + Renderer::setClearDepth(T(1.0)); + Renderer::setDepthRange(T(0.0), T(1.0)); + + MAGNUM_VERIFY_NO_GL_ERROR(); +} + }}}} CORRADE_TEST_MAIN(Magnum::GL::Test::RendererGLTest)