From e4f8d8023ca64a9ff246d0001e4225143390c36e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 15 Jul 2019 18:45:41 -0700 Subject: Fixed issue with depth clamping in GL backend --- Graphics/GraphicsEngine/interface/RasterizerState.h | 4 +--- Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp | 7 ++++++- Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngine/interface/RasterizerState.h b/Graphics/GraphicsEngine/interface/RasterizerState.h index b1638af8..7b941a5d 100644 --- a/Graphics/GraphicsEngine/interface/RasterizerState.h +++ b/Graphics/GraphicsEngine/interface/RasterizerState.h @@ -104,9 +104,7 @@ struct RasterizerStateDesc /// Default value: False. Bool FrontCounterClockwise = False; - /// Enable clipping based on distance. - /// \warning On DirectX this only disables clipping against far clipping plane, - /// while on OpenGL this disables clipping against both far and near clip planes. + /// Enable clipping against near and far clip planes. /// Default value: True. Bool DepthClipEnable = True; diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index f6fde626..55fa5435 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -88,7 +88,12 @@ namespace Diligent m_ContextState.SetDepthBias( static_cast( RasterizerDesc.DepthBias ), RasterizerDesc.SlopeScaledDepthBias ); if( RasterizerDesc.DepthBiasClamp != 0 ) LOG_WARNING_MESSAGE( "Depth bias clamp is not supported on OpenGL" ); - m_ContextState.SetDepthClamp( RasterizerDesc.DepthClipEnable ); + + // Enabling depth clamping in GL is the same as disabling clipping in Direct3D. + // https://docs.microsoft.com/en-us/windows/win32/api/d3d11/ns-d3d11-d3d11_rasterizer_desc + // https://www.khronos.org/opengl/wiki/GLAPI/glEnable + m_ContextState.SetDepthClamp( !RasterizerDesc.DepthClipEnable ); + m_ContextState.EnableScissorTest( RasterizerDesc.ScissorEnable ); if( RasterizerDesc.AntialiasedLineEnable ) LOG_WARNING_MESSAGE( "Line antialiasing is not supported on OpenGL" ); diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp index a2163a53..246f1806 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextState.cpp @@ -517,6 +517,10 @@ namespace Diligent { if( bEnableDepthClamp ) { + // Note that enabling depth clamping in GL is the same as + // disabling clipping in Direct3D. + // https://docs.microsoft.com/en-us/windows/win32/api/d3d11/ns-d3d11-d3d11_rasterizer_desc + // https://www.khronos.org/opengl/wiki/GLAPI/glEnable #pragma warning(push) #pragma warning(disable : 4127) if( GL_DEPTH_CLAMP ) @@ -529,9 +533,6 @@ namespace Diligent { if( GL_DEPTH_CLAMP ) { - // WARNING: on OpenGL, depth clamping is disabled against - // both far and near clip planes. On DirectX, only clipping - // against far clip plane can be disabled glDisable( GL_DEPTH_CLAMP ); CHECK_GL_ERROR( "Failed to disable depth clamp" ); } -- cgit v1.2.3