From 06e148613222849454bdc12dee8fd599bcb267c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 13 Dec 2015 12:17:08 -0800 Subject: [PATCH] Added BGFX_RESET_DEPTH_CLAMP. Issue #598. --- include/bgfx/bgfxdefines.h | 1 + src/renderer_d3d11.cpp | 27 ++++++++++++++++++++++----- src/renderer_d3d12.cpp | 14 ++++++++++++-- src/renderer_gl.cpp | 20 ++++++++++++++------ 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/include/bgfx/bgfxdefines.h b/include/bgfx/bgfxdefines.h index 2b03a2ca..828fcc24 100644 --- a/include/bgfx/bgfxdefines.h +++ b/include/bgfx/bgfxdefines.h @@ -354,6 +354,7 @@ #define BGFX_RESET_FLIP_AFTER_RENDER UINT32_C(0x00004000) //!< This flag specifies where flip occurs. Default behavior is that flip occurs before rendering new frame. This flag only has effect when `BGFX_CONFIG_MULTITHREADED=0`. #define BGFX_RESET_SRGB_BACKBUFFER UINT32_C(0x00008000) //!< Enable sRGB backbuffer. #define BGFX_RESET_HIDPI UINT32_C(0x00010000) //!< Enable HiDPI rendering. +#define BGFX_RESET_DEPTH_CLAMP UINT32_C(0x00020000) //!< Enable depth clamp. #define BGFX_RESET_RESERVED_SHIFT 31 //!< Internal bits shift. #define BGFX_RESET_RESERVED_MASK UINT32_C(0x80000000) //!< Internal bits mask. diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 77302a50..912f68be 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -586,6 +586,7 @@ namespace bgfx { namespace d3d11 , m_captureResolve(NULL) , m_wireframe(false) , m_maxAnisotropy(1) + , m_depthClamp(false) , m_currentProgram(NULL) , m_vsChanges(0) , m_fsChanges(0) @@ -2166,19 +2167,34 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { bool recenter = !!(_resolution.m_flags & BGFX_RESET_HMD_RECENTER); + uint32_t maxAnisotropy = 1; if (!!(_resolution.m_flags & BGFX_RESET_MAXANISOTROPY) ) { - m_maxAnisotropy = (m_featureLevel == D3D_FEATURE_LEVEL_9_1) + maxAnisotropy = (m_featureLevel == D3D_FEATURE_LEVEL_9_1) ? D3D_FL9_1_DEFAULT_MAX_ANISOTROPY : D3D11_REQ_MAXANISOTROPY ; } - else + + if (m_maxAnisotropy != maxAnisotropy) { - m_maxAnisotropy = 1; + m_maxAnisotropy = maxAnisotropy; + m_samplerStateCache.invalidate(); } - uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY); + bool depthClamp = false; + if (!!(_resolution.m_flags & BGFX_RESET_DEPTH_CLAMP) ) + { + depthClamp = m_featureLevel <= D3D_FEATURE_LEVEL_9_3; // disabling depth clamp is only supported on 10_0+ + } + + if (m_depthClamp != depthClamp) + { + m_depthClamp = depthClamp; + m_rasterizerStateCache.invalidate(); + } + + uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY | BGFX_RESET_DEPTH_CLAMP); if (m_resolution.m_width != _resolution.m_width || m_resolution.m_height != _resolution.m_height @@ -2657,7 +2673,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); desc.DepthBias = 0; desc.DepthBiasClamp = 0.0f; desc.SlopeScaledDepthBias = 0.0f; - desc.DepthClipEnable = m_featureLevel <= D3D_FEATURE_LEVEL_9_3; // disabling depth clip is only supported on 10_0+ + desc.DepthClipEnable = m_depthClamp; desc.ScissorEnable = _scissor; desc.MultisampleEnable = !!(_state&BGFX_STATE_MSAA); desc.AntialiasedLineEnable = false; @@ -3340,6 +3356,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); SwapChainDesc m_scd; uint32_t m_maxAnisotropy; + bool m_depthClamp; IndexBufferD3D11 m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; VertexBufferD3D11 m_vertexBuffers[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index c4639def..7fc33159 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -459,6 +459,7 @@ namespace bgfx { namespace d3d12 RendererContextD3D12() : m_wireframe(false) , m_maxAnisotropy(1) + , m_depthClamp(false) , m_fsChanges(0) , m_vsChanges(0) , m_backBufferColorIdx(0) @@ -1729,7 +1730,15 @@ data.NumQualityLevels = 0; m_maxAnisotropy = 1; } - uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY); + bool depthClamp = !!(_resolution.m_flags & BGFX_RESET_DEPTH_CLAMP); + + if (m_depthClamp != depthClamp) + { + m_depthClamp = depthClamp; + m_pipelineStateCache.invalidate(); + } + + uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY | BGFX_RESET_DEPTH_CLAMP); if (m_resolution.m_width != _resolution.m_width || m_resolution.m_height != _resolution.m_height @@ -2007,7 +2016,7 @@ data.NumQualityLevels = 0; desc.DepthBias = 0; desc.DepthBiasClamp = 0.0f; desc.SlopeScaledDepthBias = 0.0f; - desc.DepthClipEnable = false; + desc.DepthClipEnable = m_depthClamp; desc.MultisampleEnable = !!(_state&BGFX_STATE_MSAA); desc.AntialiasedLineEnable = false; desc.ForcedSampleCount = 0; @@ -2636,6 +2645,7 @@ data.NumQualityLevels = 0; DXGI_SWAP_CHAIN_DESC m_scd; uint32_t m_maxAnisotropy; + bool m_depthClamp; BufferD3D12 m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; VertexBufferD3D12 m_vertexBuffers[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 5330657e..90068030 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1936,11 +1936,6 @@ namespace bgfx { namespace gl GL_CHECK(glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) ); } - if (s_extension[Extension::ARB_depth_clamp].m_supported) - { - GL_CHECK(glEnable(GL_DEPTH_CLAMP) ); - } - if (NULL == glFrameTerminatorGREMEDY || !s_extension[Extension::GREMEDY_frame_terminator].m_supported) { @@ -2404,7 +2399,20 @@ namespace bgfx { namespace gl ? m_maxAnisotropyDefault : 0.0f ; - uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY); + + if (s_extension[Extension::ARB_depth_clamp].m_supported) + { + if (!!(_resolution.m_flags & BGFX_RESET_DEPTH_CLAMP) ) + { + GL_CHECK(glEnable(GL_DEPTH_CLAMP) ); + } + else + { + GL_CHECK(glDisable(GL_DEPTH_CLAMP) ); + } + } + + uint32_t flags = _resolution.m_flags & ~(BGFX_RESET_HMD_RECENTER | BGFX_RESET_MAXANISOTROPY | BGFX_RESET_DEPTH_CLAMP); if (m_resolution.m_width != _resolution.m_width || m_resolution.m_height != _resolution.m_height