From 583f60ce9f3bec7625393f94ee3693934ae5791b Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 24 Dec 2019 09:10:27 -0800 Subject: Reworked ClearRenderTarget and ClearDepthStencil methods to not take nullptr --- .../GraphicsEngine/include/DeviceContextBase.h | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'Graphics/GraphicsEngine') 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 @@ -795,6 +798,95 @@ void DeviceContextBase::ResetRenderTargets( } +template +inline bool DeviceContextBase::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 +inline bool DeviceContextBase::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 inline void DeviceContextBase:: UpdateBuffer(IBuffer* pBuffer, Uint32 Offset, Uint32 Size, const void* pData, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) -- cgit v1.2.3