From 354898decf45d32a09d9b4a15319413a5d199f2a Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 1 Jul 2018 17:08:59 -0700 Subject: Reworked binding default frame buffer to keep references to current RTV and DSV instead of nulls. --- .../GraphicsEngine/include/DeviceContextBase.h | 50 +++++++++++----------- Graphics/GraphicsEngine/interface/SwapChain.h | 19 ++++++++ 2 files changed, 45 insertions(+), 24 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h index 431ac867..e8e339db 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.h +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h @@ -399,12 +399,36 @@ inline void DeviceContextBase :: SetScissorRects( Uint32 NumRects } template -inline bool DeviceContextBase :: SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy ) +inline bool DeviceContextBase :: SetRenderTargets( Uint32 NumRenderTargets, ITextureView* ppRenderTargets[], ITextureView* pDepthStencil, Uint32 Dummy ) { bool bBindRenderTargets = false; m_FramebufferWidth = 0; m_FramebufferHeight = 0; m_FramebufferSlices = 0; + + ITextureView* pDefaultRTV = nullptr; + if (NumRenderTargets == 0 && pDepthStencil == nullptr) + { + VERIFY(m_pSwapChain, "Swap chain is not initialized in the device context"); + + NumRenderTargets = 1; + pDefaultRTV = m_pSwapChain->GetCurrentBackBufferRTV(); + ppRenderTargets = &pDefaultRTV; + pDepthStencil = m_pSwapChain->GetDepthBufferDSV(); + + const auto &SwapChainDesc = m_pSwapChain->GetDesc(); + m_FramebufferWidth = SwapChainDesc.Width; + m_FramebufferHeight = SwapChainDesc.Height; + m_FramebufferSlices = 1; + + if (!m_IsDefaultFramebufferBound) + bBindRenderTargets = true; + m_IsDefaultFramebufferBound = true; + } + else + m_IsDefaultFramebufferBound = false; + + if( NumRenderTargets != m_NumBoundRenderTargets ) { bBindRenderTargets = true; @@ -442,7 +466,7 @@ inline bool DeviceContextBase :: SetRenderTargets( Uint32 NumRend } } - // Here both views a certainly live object, since we store + // Here both views are certainly live objects, since we store // strong references to all bound render targets. So we // can safely compare pointers. if( m_pBoundRenderTargets[rt] != pRTView ) @@ -483,28 +507,6 @@ inline bool DeviceContextBase :: SetRenderTargets( Uint32 NumRend bBindRenderTargets = true; } - if (NumRenderTargets == 0 && pDepthStencil == nullptr) - { - if (!m_IsDefaultFramebufferBound) - { - m_IsDefaultFramebufferBound = true; - bBindRenderTargets = true; - } - - if (m_pSwapChain) - { - const auto &SwapChainDesc = m_pSwapChain->GetDesc(); - m_FramebufferWidth = SwapChainDesc.Width; - m_FramebufferHeight = SwapChainDesc.Height; - m_FramebufferSlices = 1; - } - else - { - UNEXPECTED("Swap chain is not initialized in the device context"); - } - } - else - m_IsDefaultFramebufferBound = false; VERIFY_EXPR(m_FramebufferWidth > 0 && m_FramebufferHeight > 0 && m_FramebufferSlices > 0); diff --git a/Graphics/GraphicsEngine/interface/SwapChain.h b/Graphics/GraphicsEngine/interface/SwapChain.h index 578d4fdb..4746c2d8 100644 --- a/Graphics/GraphicsEngine/interface/SwapChain.h +++ b/Graphics/GraphicsEngine/interface/SwapChain.h @@ -27,6 +27,7 @@ /// Definition of the Diligent::ISwapChain interface and related data structures #include "../../../Primitives/interface/Object.h" +#include "TextureView.h" #include "GraphicsTypes.h" namespace Diligent @@ -60,6 +61,24 @@ public: /// Sets windowed mode (only supported on Win32 platform) virtual void SetWindowedMode() = 0; + + /// Returns render target view of the current back buffer in the swap chain + + /// \note For Direct3D12 and Vulkan backends, the function returns + /// different pointer for every offscreen buffer in the swap chain + /// (flipped by every call to ISwapChain::Present()). For Direct3D11 + /// backend it always returns the same pointer. For OpenGL/GLES backends + /// the method returns null. + /// + /// The method does *NOT* call AddRef() on the returned interface, + /// so Release() must not be called. + virtual ITextureView* GetCurrentBackBufferRTV() = 0; + + /// Returns depth-stencil view of the depth buffer + + /// The method does *NOT* call AddRef() on the returned interface, + /// so Release() must not be called. + virtual ITextureView* GetDepthBufferDSV() = 0; }; } -- cgit v1.2.3