From 89e1718309473686f1bae9ef46c501fc1d6e1520 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 1 Aug 2020 14:22:47 -0700 Subject: Implemented ClearRenderTarget/ClearDepthStencil for inside render pass clears --- .../GraphicsEngine/include/DeviceContextBase.hpp | 94 ++++++++++++++++------ 1 file changed, 68 insertions(+), 26 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp index 74fc5966..8679f202 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp @@ -888,8 +888,6 @@ inline bool DeviceContextBase::ClearDepthSt } #ifdef DILIGENT_DEVELOPMENT - VERIFY(m_pActiveRenderPass == nullptr, "ClearDepthStencil command must be used outside of render pass. Inside the render pass, use ClearDepthStencilAttachment command."); - { const auto& ViewDesc = pView->GetDesc(); if (ViewDesc.ViewType != TEXTURE_VIEW_DEPTH_STENCIL) @@ -899,21 +897,44 @@ inline bool DeviceContextBase::ClearDepthSt return false; } - if (pView != m_pBoundDepthStencil) + if (m_pActiveRenderPass != nullptr) { - if (m_pDevice->GetDeviceCaps().IsGLDevice()) + bool AttachmentFound = false; + if (m_pBoundFramebuffer != nullptr) + { + const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + for (Uint32 i = 0; i < FBDesc.AttachmentCount && !AttachmentFound; ++i) + { + AttachmentFound = FBDesc.ppAttachments[i] == pView; + } + } + + if (!AttachmentFound) { 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"); + "' is not bound as framebuffer attachment. ClearDepthStencil command inside a render pass " + "requires depth-stencil view be bound as framebuffer attachment."); return false; } - else + } + else + { + if (pView != m_pBoundDepthStencil) { - 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."); + 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."); + } } } } @@ -932,8 +953,6 @@ inline bool DeviceContextBase::ClearRenderT } #ifdef DILIGENT_DEVELOPMENT - VERIFY(m_pActiveRenderPass == nullptr, "ClearRenderTarget command must be used outside of render pass. Inside the render pass, use ClearRenderTargetAttachment command."); - { const auto& ViewDesc = pView->GetDesc(); if (ViewDesc.ViewType != TEXTURE_VIEW_RENDER_TARGET) @@ -943,25 +962,48 @@ inline bool DeviceContextBase::ClearRenderT return false; } - bool RTFound = false; - for (Uint32 i = 0; i < m_NumBoundRenderTargets && !RTFound; ++i) - { - RTFound = m_pBoundRenderTargets[i] == pView; - } - if (!RTFound) + if (m_pActiveRenderPass != nullptr) { - if (m_pDevice->GetDeviceCaps().IsGLDevice()) + bool AttachmentFound = false; + if (m_pBoundFramebuffer != nullptr) + { + const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + for (Uint32 i = 0; i < FBDesc.AttachmentCount && !AttachmentFound; ++i) + { + AttachmentFound = FBDesc.ppAttachments[i] == pView; + } + } + + if (!AttachmentFound) { 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"); + "' is not bound as framebuffer attachment. ClearRenderTarget command inside a render pass " + "requires render target view be bound as framebuffer attachment."); return false; } - else + } + else + { + bool RTFound = false; + for (Uint32 i = 0; i < m_NumBoundRenderTargets && !RTFound; ++i) + { + RTFound = m_pBoundRenderTargets[i] == pView; + } + if (!RTFound) { - 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."); + 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."); + } } } } -- cgit v1.2.3