From 5d2b7f40c7255ed4252e08c0ea2cacb4d201f6dc Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 28 Dec 2019 12:54:59 -0800 Subject: Fixed few more clang warnings; fixed iOS build error --- .../GraphicsEngineOpenGL/include/SwapChainGLIOS.h | 8 +++-- .../GraphicsEngineOpenGL/src/SwapChainGLIOS.mm | 39 ++++++++++++++++++---- .../include/TestingSwapChainBase.h | 6 ++-- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h index e82a2f75..659d1bfa 100644 --- a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h +++ b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h @@ -56,12 +56,16 @@ public: virtual GLuint GetDefaultFBO() const override final; - virtual ITextureView* GetCurrentBackBufferRTV() override final { return nullptr; } - virtual ITextureView* GetDepthBufferDSV() override final { return nullptr; } + virtual ITextureView* GetCurrentBackBufferRTV() override final { return m_pRenderTargetView; } + virtual ITextureView* GetDepthBufferDSV() override final { return m_pDepthStencilView; } private: void InitRenderBuffers(bool InitFromDrawable, Uint32& Width, Uint32& Height); + void CreateDummyBuffers(RenderDeviceGLImpl* pRenderDeviceGL); + RefCntAutoPtr m_pRenderTargetView; + RefCntAutoPtr m_pDepthStencilView; + GLObjectWrappers::GLRenderBufferObj m_ColorRenderBuffer; GLObjectWrappers::GLRenderBufferObj m_DepthRenderBuffer; GLObjectWrappers::GLFrameBufferObj m_DefaultFBO; diff --git a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLIOS.mm b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLIOS.mm index bbdfb94c..0e84b408 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLIOS.mm +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLIOS.mm @@ -45,6 +45,7 @@ SwapChainGLIOS::SwapChainGLIOS(IReferenceCounters* pRefCounters, { m_CALayer = InitAttribs.pNativeWndHandle; InitRenderBuffers(true, m_SwapChainDesc.Width, m_SwapChainDesc.Height); + CreateDummyBuffers(m_pRenderDevice.RawPtr()); } IMPLEMENT_QUERY_INTERFACE( SwapChainGLIOS, IID_SwapChainGL, TSwapChainBase ) @@ -108,24 +109,48 @@ void SwapChainGLIOS::InitRenderBuffers(bool InitFromDrawable, Uint32 &Width, Uin } } +void SwapChainGLIOS::CreateDummyBuffers(RenderDeviceGLImpl* pRenderDeviceGL) +{ + TextureDesc ColorBuffDesc; + ColorBuffDesc.Type = RESOURCE_DIM_TEX_2D; + ColorBuffDesc.Name = "Main color buffer stub"; + ColorBuffDesc.Width = m_SwapChainDesc.Width; + ColorBuffDesc.Height = m_SwapChainDesc.Height; + ColorBuffDesc.Format = m_SwapChainDesc.ColorBufferFormat; + ColorBuffDesc.BindFlags = BIND_RENDER_TARGET; + RefCntAutoPtr pDummyColorBuffer; + pRenderDeviceGL->CreateDummyTexture(ColorBuffDesc, RESOURCE_STATE_RENDER_TARGET, &pDummyColorBuffer); + m_pRenderTargetView = ValidatedCast(pDummyColorBuffer->GetDefaultView(TEXTURE_VIEW_RENDER_TARGET)); + + TextureDesc DepthBuffDesc = ColorBuffDesc; + DepthBuffDesc.Name = "Main depth buffer stub"; + DepthBuffDesc.Format = m_SwapChainDesc.DepthBufferFormat; + DepthBuffDesc.BindFlags = BIND_DEPTH_STENCIL; + RefCntAutoPtr pDummyDepthBuffer; + pRenderDeviceGL->CreateDummyTexture(DepthBuffDesc, RESOURCE_STATE_DEPTH_WRITE, &pDummyDepthBuffer); + m_pDepthStencilView = ValidatedCast(pDummyDepthBuffer->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL)); +} + void SwapChainGLIOS::Resize( Uint32 NewWidth, Uint32 NewHeight ) { InitRenderBuffers(false, NewWidth, NewHeight); if( TSwapChainBase::Resize( NewWidth, NewHeight ) ) { + CreateDummyBuffers(m_pRenderDevice.RawPtr()); + auto pDeviceContext = m_wpDeviceContext.Lock(); VERIFY( pDeviceContext, "Immediate context has been released" ); if( pDeviceContext ) { - auto *pImmediateCtxGL = ValidatedCast( pDeviceContext.RawPtr() ); - bool bIsDefaultFBBound = pImmediateCtxGL->IsDefaultFBBound(); - - if( bIsDefaultFBBound ) + auto* pImmediateCtxGL = pDeviceContext.RawPtr(); + // Unbind the back buffer to be consistent with other backends + auto* pCurrentBackBuffer = ValidatedCast(m_pRenderTargetView->GetTexture()); + auto RenderTargetsReset = pImmediateCtxGL->UnbindTextureFromFramebuffer(pCurrentBackBuffer, false); + if (RenderTargetsReset) { - // Reset render targets and update viewport - pImmediateCtxGL->SetRenderTargets(0, nullptr, nullptr, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - pImmediateCtxGL->SetViewports( 1, nullptr, 0, 0 ); + LOG_INFO_MESSAGE_ONCE("Resizing the swap chain requires back and depth-stencil buffers to be unbound from the device context. " + "An application should use SetRenderTargets() to restore them."); } } } diff --git a/Tests/DiligentCoreAPITest/include/TestingSwapChainBase.h b/Tests/DiligentCoreAPITest/include/TestingSwapChainBase.h index 24b9b764..70829951 100644 --- a/Tests/DiligentCoreAPITest/include/TestingSwapChainBase.h +++ b/Tests/DiligentCoreAPITest/include/TestingSwapChainBase.h @@ -73,9 +73,9 @@ public: IDeviceContext* pContext, const SwapChainDesc& SCDesc) : TObjectBase{pRefCounters}, + m_SwapChainDesc{SCDesc}, m_pDevice{pDevice}, - m_pContext{pContext}, - m_SwapChainDesc{SCDesc} + m_pContext{pContext} { VERIFY_EXPR(m_SwapChainDesc.ColorBufferFormat != TEX_FORMAT_UNKNOWN); VERIFY_EXPR(m_SwapChainDesc.Width != 0); @@ -134,7 +134,7 @@ public: } } - void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override { if (ppInterface == nullptr) return; -- cgit v1.2.3