diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2019-12-24 17:10:27 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2019-12-24 17:10:27 +0000 |
| commit | 583f60ce9f3bec7625393f94ee3693934ae5791b (patch) | |
| tree | f2ac411359d021f7d07956cec650f6fc567710a5 /Graphics/GraphicsEngine | |
| parent | Disabled SetRenderTarget(0, nullptr, nullptr) usage (fixed https://github.com... (diff) | |
| download | DiligentCore-583f60ce9f3bec7625393f94ee3693934ae5791b.tar.gz DiligentCore-583f60ce9f3bec7625393f94ee3693934ae5791b.zip | |
Reworked ClearRenderTarget and ClearDepthStencil methods to not take nullptr
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceContextBase.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index dee85899..93f62fb1 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -203,6 +203,9 @@ protected: /// Checks if the texture is currently bound as depth-stencil buffer. bool CheckIfBoundAsDepthStencil(TextureImplType* pTexture); + bool ClearDepthStencil(ITextureView* pView); + + bool ClearRenderTarget(ITextureView* pView); #ifdef DEVELOPMENT // clang-format off @@ -796,6 +799,95 @@ void DeviceContextBase<BaseInterface, ImplementationTraits>::ResetRenderTargets( template <typename BaseInterface, typename ImplementationTraits> +inline bool DeviceContextBase<BaseInterface, ImplementationTraits>::ClearDepthStencil(ITextureView* pView) +{ + if (pView == nullptr) + { + LOG_ERROR_MESSAGE("Depth-stencil view to clear must not be null"); + return false; + } + +#ifdef DEVELOPMENT + { + const auto& ViewDesc = pView->GetDesc(); + if (ViewDesc.ViewType != TEXTURE_VIEW_DEPTH_STENCIL) + { + LOG_ERROR_MESSAGE("The type (", GetTexViewTypeLiteralName(ViewDesc.ViewType), ") of the texture view '", ViewDesc.Name, + "' is invalid: ClearDepthStencil command expects depth-stencil view (TEXTURE_VIEW_DEPTH_STENCIL)."); + return false; + } + + if (pView != m_pBoundDepthStencil) + { + if (m_pDevice->GetDeviceCaps().IsGLDevice()) + { + LOG_ERROR_MESSAGE("Depth-stencil view '", ViewDesc.Name, + "' is not bound to the device context. ClearDepthStencil command requires " + "depth-stencil view be bound to the device contex in OpenGL backend"); + return false; + } + else + { + LOG_WARNING_MESSAGE("Depth-stencil view '", ViewDesc.Name, + "' is not bound to the device context. " + "ClearDepthStencil command is more efficient when depth-stencil " + "view is bound to the context. In OpenGL backend this is a requirement."); + } + } + } +#endif + + return true; +} + +template <typename BaseInterface, typename ImplementationTraits> +inline bool DeviceContextBase<BaseInterface, ImplementationTraits>::ClearRenderTarget(ITextureView* pView) +{ + if (pView == nullptr) + { + LOG_ERROR_MESSAGE("Render target view to clear must not be null"); + return false; + } + +#ifdef DEVELOPMENT + { + const auto& ViewDesc = pView->GetDesc(); + if (ViewDesc.ViewType != TEXTURE_VIEW_RENDER_TARGET) + { + LOG_ERROR_MESSAGE("The type (", GetTexViewTypeLiteralName(ViewDesc.ViewType), ") of texture view '", pView->GetDesc().Name, + "' is invalid: ClearRenderTarget command expects render target view (TEXTURE_VIEW_RENDER_TARGET)."); + return false; + } + + bool RTFound = false; + for (Uint32 i = 0; i < m_NumBoundRenderTargets && !RTFound; ++i) + { + RTFound = m_pBoundRenderTargets[i] == pView; + } + if (!RTFound) + { + if (m_pDevice->GetDeviceCaps().IsGLDevice()) + { + LOG_ERROR_MESSAGE("Render target view '", ViewDesc.Name, + "' is not bound to the device context. ClearRenderTarget command " + "requires render target view be bound to the device contex in OpenGL backend"); + return false; + } + else + { + LOG_WARNING_MESSAGE("Render target view '", ViewDesc.Name, + "' is not bound to the device context. ClearRenderTarget command is more efficient " + "if render target view is bound to the device context. In OpenGL backend this is a requirement."); + } + } + } +#endif + + return true; +} + + +template <typename BaseInterface, typename ImplementationTraits> inline void DeviceContextBase<BaseInterface, ImplementationTraits>:: UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const void* pData, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { |
