diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-08-11 05:31:08 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-08-11 05:31:08 +0000 |
| commit | 1ecb28239bb09ce028afbe9d8e5254ca5c480e88 (patch) | |
| tree | a8dc359d1c835e893b0a91649e42e82e782782c5 /Graphics/GraphicsEngineOpenGL | |
| parent | Implemented render pass MS resolve in OpenGL (diff) | |
| download | DiligentCore-1ecb28239bb09ce028afbe9d8e5254ca5c480e88.tar.gz DiligentCore-1ecb28239bb09ce028afbe9d8e5254ca5c480e88.zip | |
OpenGL backend: enabled handling of default framebuffer in render passes
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp | 30 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp | 52 |
2 files changed, 70 insertions, 12 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 37e4a3f4..3b3122bf 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -424,6 +424,22 @@ void DeviceContextGLImpl::BeginSubpass() VERIFY_EXPR(m_SubpassIndex < RPDesc.SubpassCount); const auto& SubpassDesc = RPDesc.pSubpasses[m_SubpassIndex]; const auto& FBDesc = m_pBoundFramebuffer->GetDesc(); + + const auto& RenderTargetFBO = m_pBoundFramebuffer->GetSubpassFramebuffer(m_SubpassIndex).RenderTarget; + if (RenderTargetFBO != 0) + { + m_ContextState.BindFBO(RenderTargetFBO); + } + else + { + GLuint DefaultFBOHandle = m_pSwapChain->GetDefaultFBO(); + if (m_DefaultFBO != DefaultFBOHandle) + { + m_DefaultFBO = GLObjectWrappers::GLFrameBufferObj{true, GLObjectWrappers::GLFBOCreateReleaseHelper(DefaultFBOHandle)}; + } + m_ContextState.BindFBO(m_DefaultFBO); + } + for (Uint32 rt = 0; rt < SubpassDesc.RenderTargetAttachmentCount; ++rt) { const auto& RTAttachmentRef = SubpassDesc.pRenderTargetAttachments[rt]; @@ -464,8 +480,8 @@ void DeviceContextGLImpl::EndSubpass() { const auto& SubpassFBOs = m_pBoundFramebuffer->GetSubpassFramebuffer(m_SubpassIndex); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, SubpassFBOs.RenderTarget); - DEV_CHECK_GL_ERROR("Failed to bind subpass render target FBO as draw framebuffer"); + glBindFramebuffer(GL_READ_FRAMEBUFFER, SubpassFBOs.RenderTarget); + DEV_CHECK_GL_ERROR("Failed to bind subpass render target FBO as read framebuffer"); GLuint ResolveDstFBO = SubpassFBOs.Resolve; if (ResolveDstFBO == 0) @@ -481,7 +497,7 @@ void DeviceContextGLImpl::EndSubpass() GL_COLOR_BUFFER_BIT, GL_NEAREST // Filter is ignored ); - DEV_CHECK_GL_ERROR("glBlitFramebuffer() failed when resolving multi-sampled texture"); + DEV_CHECK_GL_ERROR("glBlitFramebuffer() failed when resolving multi-sampled attachments"); } m_ContextState.InvalidateFBO(); } @@ -495,7 +511,7 @@ void DeviceContextGLImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) m_AttachmentClearValues[i] = Attribs.pClearValues[i]; VERIFY_EXPR(m_pBoundFramebuffer); - m_ContextState.BindFBO(m_pBoundFramebuffer->GetSubpassFramebuffer(m_SubpassIndex).RenderTarget); + SetViewports(1, nullptr, 0, 0); BeginSubpass(); @@ -504,20 +520,14 @@ void DeviceContextGLImpl::BeginRenderPass(const BeginRenderPassAttribs& Attribs) void DeviceContextGLImpl::NextSubpass() { EndSubpass(); - TDeviceContextBase::NextSubpass(); - - m_ContextState.BindFBO(m_pBoundFramebuffer->GetSubpassFramebuffer(m_SubpassIndex).RenderTarget); - BeginSubpass(); } void DeviceContextGLImpl::EndRenderPass() { EndSubpass(); - TDeviceContextBase::EndRenderPass(); - m_ContextState.InvalidateFBO(); } diff --git a/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp index 51abf1ba..c84d9816 100644 --- a/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/FramebufferGLImpl.cpp @@ -34,6 +34,50 @@ namespace Diligent { +static bool UseDefaultFBO(Uint32 NumRenderTargets, + TextureViewGLImpl* ppRTVs[], + TextureViewGLImpl* pDSV) +{ + bool useDefaultFBO = false; + for (Uint32 rt = 0; rt < NumRenderTargets; ++rt) + { + if (ppRTVs[rt] != nullptr && ppRTVs[rt]->GetHandle() == 0) + { + if (rt == 0) + { + useDefaultFBO = true; + } + else + { + LOG_ERROR_AND_THROW("In OpenGL, swap chain back buffer can be the only render target in the framebuffer " + "and cannot be combined with any other render target."); + } + } + } + + if (pDSV != nullptr) + { + if (useDefaultFBO && pDSV->GetHandle() != 0) + { + LOG_ERROR_AND_THROW("In OpenGL, swap chain back buffer can only be paired with the default depth-stencil buffer."); + } + + if (pDSV->GetHandle() == 0) + { + if (!useDefaultFBO && NumRenderTargets > 0) + { + LOG_ERROR_AND_THROW("In OpenGL, the swap chain's depth-stencil buffer can only be paired with its back buffer."); + } + else + { + useDefaultFBO = true; + } + } + } + + return useDefaultFBO; +} + FramebufferGLImpl::FramebufferGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pDevice, GLContextState& CtxState, @@ -62,7 +106,9 @@ FramebufferGLImpl::FramebufferGLImpl(IReferenceCounters* pRefCounters, { pDSV = ValidatedCast<TextureViewGLImpl>(m_Desc.ppAttachments[SubpassDesc.pDepthStencilAttachment->AttachmentIndex]); } - auto RenderTargetFBO = FBOCache::CreateFBO(CtxState, SubpassDesc.RenderTargetAttachmentCount, ppRTVs, pDSV); + auto RenderTargetFBO = UseDefaultFBO(SubpassDesc.RenderTargetAttachmentCount, ppRTVs, pDSV) ? + GLObjectWrappers::GLFrameBufferObj{false} : + FBOCache::CreateFBO(CtxState, SubpassDesc.RenderTargetAttachmentCount, ppRTVs, pDSV); GLObjectWrappers::GLFrameBufferObj ResolveFBO{false}; if (SubpassDesc.pResolveAttachments != nullptr) @@ -76,7 +122,9 @@ FramebufferGLImpl::FramebufferGLImpl(IReferenceCounters* pRefCounters, ppRsvlViews[rt] = ValidatedCast<TextureViewGLImpl>(m_Desc.ppAttachments[RslvAttachmentRef.AttachmentIndex]); } } - ResolveFBO = FBOCache::CreateFBO(CtxState, SubpassDesc.RenderTargetAttachmentCount, ppRsvlViews, nullptr); + ResolveFBO = UseDefaultFBO(SubpassDesc.RenderTargetAttachmentCount, ppRsvlViews, nullptr) ? + GLObjectWrappers::GLFrameBufferObj{false} : + FBOCache::CreateFBO(CtxState, SubpassDesc.RenderTargetAttachmentCount, ppRsvlViews, nullptr); } m_SubpassFramebuffers.emplace_back(std::move(RenderTargetFBO), std::move(ResolveFBO)); |
