Browse Source

GL: expose Renderer::setDepthRange().

pull/601/head
Vladimír Vondruš 3 years ago
parent
commit
bede836077
  1. 1
      doc/changelog.dox
  2. 2
      doc/opengl-mapping.dox
  3. 8
      src/Magnum/GL/Implementation/RendererState.cpp
  4. 1
      src/Magnum/GL/Implementation/RendererState.h
  5. 16
      src/Magnum/GL/Renderer.cpp
  6. 30
      src/Magnum/GL/Renderer.h
  7. 19
      src/Magnum/GL/Test/RendererGLTest.cpp

1
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)

2
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} | |

8
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<Extensions::ARB::ES2_compatibility>())
#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

1
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

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

30
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();

19
src/Magnum/GL/Test/RendererGLTest.cpp

@ -68,6 +68,7 @@ struct RendererGLTest: OpenGLTester {
void drawBuffersIndexed();
void drawBuffersBlend();
#endif
template<class T> void clearDepthDepthRange();
private:
PluginManager::Manager<Trade::AbstractImporter> _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<Double>,
#endif
&RendererGLTest::clearDepthDepthRange<Float>});
/* 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<class T> void RendererGLTest::clearDepthDepthRange() {
setTestCaseTemplateName(Math::TypeTraits<T>::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)

Loading…
Cancel
Save