diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2019-12-28 20:54:59 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2019-12-28 20:54:59 +0000 |
| commit | 5d2b7f40c7255ed4252e08c0ea2cacb4d201f6dc (patch) | |
| tree | 4a878e13d0f8bab12f293c217aeef2f6ab017335 /Graphics/GraphicsEngineOpenGL | |
| parent | Fixed a couple of build warnings (diff) | |
| download | DiligentCore-5d2b7f40c7255ed4252e08c0ea2cacb4d201f6dc.tar.gz DiligentCore-5d2b7f40c7255ed4252e08c0ea2cacb4d201f6dc.zip | |
Fixed few more clang warnings; fixed iOS build error
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h | 8 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/src/SwapChainGLIOS.mm | 39 |
2 files changed, 38 insertions, 9 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<TextureViewGLImpl> m_pRenderTargetView; + RefCntAutoPtr<TextureViewGLImpl> 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<RenderDeviceGLImpl>()); } 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<ITexture> pDummyColorBuffer; + pRenderDeviceGL->CreateDummyTexture(ColorBuffDesc, RESOURCE_STATE_RENDER_TARGET, &pDummyColorBuffer); + m_pRenderTargetView = ValidatedCast<TextureViewGLImpl>(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<ITexture> pDummyDepthBuffer; + pRenderDeviceGL->CreateDummyTexture(DepthBuffDesc, RESOURCE_STATE_DEPTH_WRITE, &pDummyDepthBuffer); + m_pDepthStencilView = ValidatedCast<TextureViewGLImpl>(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<RenderDeviceGLImpl>()); + auto pDeviceContext = m_wpDeviceContext.Lock(); VERIFY( pDeviceContext, "Immediate context has been released" ); if( pDeviceContext ) { - auto *pImmediateCtxGL = ValidatedCast<DeviceContextGLImpl>( pDeviceContext.RawPtr() ); - bool bIsDefaultFBBound = pImmediateCtxGL->IsDefaultFBBound(); - - if( bIsDefaultFBBound ) + auto* pImmediateCtxGL = pDeviceContext.RawPtr<DeviceContextGLImpl>(); + // Unbind the back buffer to be consistent with other backends + auto* pCurrentBackBuffer = ValidatedCast<TextureBaseGL>(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."); } } } |
