diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2019-12-28 22:26:00 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2019-12-28 22:26:00 +0000 |
| commit | b07bfac703a948d14eacc212e683e78d5ad3a6a8 (patch) | |
| tree | 9c28fa337794059ef562aecd65c6b42e75fa50a6 /Graphics/GraphicsEngineOpenGL | |
| parent | Fixed few more clang warnings; fixed iOS build error (diff) | |
| download | DiligentCore-b07bfac703a948d14eacc212e683e78d5ad3a6a8.tar.gz DiligentCore-b07bfac703a948d14eacc212e683e78d5ad3a6a8.zip | |
Added SwapChainGLBase class
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
5 files changed, 117 insertions, 59 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index 1ea19441..73fcb5ba 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -22,6 +22,7 @@ set(INCLUDE include/SamplerGLImpl.h include/ShaderGLImpl.h include/ShaderResourceBindingGLImpl.h + include/SwapChainGLBase.h include/TexRegionRender.h include/Texture1D_OGL.h include/Texture1DArray_OGL.h diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.h b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.h new file mode 100644 index 00000000..54cc4616 --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLBase.h @@ -0,0 +1,109 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "SwapChainBase.h" +#include "TextureViewGLImpl.h" + +namespace Diligent +{ + +class IMemoryAllocator; + +/// Base implementation of a swap chain for OpenGL. +template <class BaseInterface> +class SwapChainGLBase : public SwapChainBase<BaseInterface> +{ +public: + using TSwapChainBase = SwapChainBase<BaseInterface>; + + SwapChainGLBase(IReferenceCounters* pRefCounters, + IRenderDevice* pDevice, + IDeviceContext* pDeviceContext, + const SwapChainDesc& SCDesc) : + TSwapChainBase{pRefCounters, pDevice, pDeviceContext, SCDesc} + {} + + + /// Implementation of ISwapChain::GetCurrentBackBufferRTV() in OpenGL backend. + virtual ITextureView* GetCurrentBackBufferRTV() override final { return m_pRenderTargetView; } + + /// Implementation of ISwapChain::GetDepthBufferDSV() in OpenGL backend. + virtual ITextureView* GetDepthBufferDSV() override final { return m_pDepthStencilView; } + +protected: + bool Resize(Uint32 NewWidth, Uint32 NewHeight, Int32 /*To be different from virtual function*/) + { + if (TSwapChainBase::Resize(NewWidth, NewHeight, 0)) + { + if (m_pRenderTargetView) + { + if (auto pDeviceContext = m_wpDeviceContext.Lock()) + { + 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) + { + 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."); + } + } + } + + CreateDummyBuffers(m_pRenderDevice.RawPtr<RenderDeviceGLImpl>()); + return true; + } + + return false; + } + + void 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)); + } + + RefCntAutoPtr<TextureViewGLImpl> m_pRenderTargetView; + RefCntAutoPtr<TextureViewGLImpl> m_pDepthStencilView; +}; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h index 659d1bfa..920b9b76 100644 --- a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h +++ b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLIOS.h @@ -65,7 +65,7 @@ private: 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/include/SwapChainGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h index 15608044..74d98c0f 100644 --- a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h @@ -24,7 +24,7 @@ #pragma once #include "SwapChainGL.h" -#include "SwapChainBase.h" +#include "SwapChainGLBase.h" #include "GLObjectWrapper.h" namespace Diligent @@ -33,10 +33,10 @@ namespace Diligent class IMemoryAllocator; /// Swap chain implementation in OpenGL backend. -class SwapChainGLImpl final : public SwapChainBase<ISwapChainGL> +class SwapChainGLImpl final : public SwapChainGLBase<ISwapChainGL> { public: - using TSwapChainBase = SwapChainBase<ISwapChainGL>; + using TSwapChainGLBase = SwapChainGLBase<ISwapChainGL>; SwapChainGLImpl(IReferenceCounters* pRefCounters, const EngineGLCreateInfo& InitAttribs, @@ -61,18 +61,6 @@ public: /// Implementation of ISwapChainGL::GetDefaultFBO(). virtual GLuint GetDefaultFBO() const override final { return 0; } - - /// Implementation of ISwapChain::GetCurrentBackBufferRTV() in OpenGL backend. - virtual ITextureView* GetCurrentBackBufferRTV() override final { return m_pRenderTargetView; } - - /// Implementation of ISwapChain::GetDepthBufferDSV() in OpenGL backend. - virtual ITextureView* GetDepthBufferDSV() override final { return m_pDepthStencilView; } - -private: - void CreateDummyBuffers(RenderDeviceGLImpl* pRenderDeviceGL); - - RefCntAutoPtr<TextureViewGLImpl> m_pRenderTargetView; - RefCntAutoPtr<TextureViewGLImpl> m_pDepthStencilView; }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp index a5e0dd93..ce063143 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -34,7 +34,7 @@ SwapChainGLImpl::SwapChainGLImpl(IReferenceCounters* pRefCounters, RenderDeviceGLImpl* pRenderDeviceGL, DeviceContextGLImpl* pImmediateContextGL) : // clang-format off - TSwapChainBase + TSwapChainGLBase { pRefCounters, pRenderDeviceGL, @@ -73,33 +73,11 @@ SwapChainGLImpl::SwapChainGLImpl(IReferenceCounters* pRefCounters, CreateDummyBuffers(pRenderDeviceGL); } -void SwapChainGLImpl::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)); -} - SwapChainGLImpl::~SwapChainGLImpl() { } -IMPLEMENT_QUERY_INTERFACE(SwapChainGLImpl, IID_SwapChainGL, TSwapChainBase) +IMPLEMENT_QUERY_INTERFACE(SwapChainGLImpl, IID_SwapChainGL, TSwapChainGLBase) void SwapChainGLImpl::Present(Uint32 SyncInterval) { @@ -132,25 +110,7 @@ void SwapChainGLImpl::Resize(Uint32 NewWidth, Uint32 NewHeight) NewHeight = GLContext.GetScreenHeight(); #endif - 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 = 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) - { - 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."); - } - } - } + TSwapChainGLBase::Resize(NewWidth, NewHeight, 0); } void SwapChainGLImpl::SetFullscreenMode(const DisplayModeAttribs& DisplayMode) |
