diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-07-02 00:08:59 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-07-02 00:08:59 +0000 |
| commit | 354898decf45d32a09d9b4a15319413a5d199f2a (patch) | |
| tree | 61e46f6cb4fc324338903c79292c9c995e3f67ef /Graphics/GraphicsEngine | |
| parent | Reworked how render targets are bound in Vulkan: added RenderPass cache (diff) | |
| download | DiligentCore-354898decf45d32a09d9b4a15319413a5d199f2a.tar.gz DiligentCore-354898decf45d32a09d9b4a15319413a5d199f2a.zip | |
Reworked binding default frame buffer to keep references to current RTV and DSV instead of nulls.
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/DeviceContextBase.h | 50 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/SwapChain.h | 19 |
2 files changed, 45 insertions, 24 deletions
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<BaseInterface> :: SetScissorRects( Uint32 NumRects } template<typename BaseInterface> -inline bool DeviceContextBase<BaseInterface> :: SetRenderTargets( Uint32 NumRenderTargets, ITextureView *ppRenderTargets[], ITextureView *pDepthStencil, Uint32 Dummy ) +inline bool DeviceContextBase<BaseInterface> :: 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<BaseInterface> :: 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<BaseInterface> :: 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; }; } |
