diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-02-03 18:17:00 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-02-03 18:17:00 +0000 |
| commit | 2cda18e07c1e52448d574932779d785ef111000c (patch) | |
| tree | 3f8fc12efac7ad1ba3cf09d2708b5e09c7622121 /Graphics/GraphicsEngineOpenGL | |
| parent | Added info about MacOS to readme (diff) | |
| download | DiligentCore-2cda18e07c1e52448d574932779d785ef111000c.tar.gz DiligentCore-2cda18e07c1e52448d574932779d785ef111000c.zip | |
Reworked swap chain initialization in OpenGL to be better separated from GLContext
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
14 files changed, 135 insertions, 72 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index 3ff8988d..1279e60d 100644 --- a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt +++ b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt @@ -39,6 +39,7 @@ set(INTERFACE interface/BufferGL.h interface/BufferViewGL.h interface/DeviceContextGL.h + interface/EngineGLAttribs.h interface/PipelineStateGL.h interface/RenderDeviceFactoryOpenGL.h interface/RenderDeviceGL.h diff --git a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h index 2a0db394..5a4a80fc 100644 --- a/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/DeviceContextGLImpl.h @@ -27,6 +27,7 @@ #include "DeviceContextBase.h" #include "BaseInterfacesGL.h" #include "GLContextState.h" +#include "GLObjectWrapper.h" namespace Diligent { @@ -100,6 +101,7 @@ private: std::vector<class BufferGLImpl*> m_BoundWritableBuffers; bool m_bVAOIsUpToDate = false; + GLObjectWrappers::GLFrameBufferObj m_DefaultFBO; }; } diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h index 481c0299..da3ebe5a 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextWindows.h @@ -25,29 +25,19 @@ namespace Diligent { - - struct ContextInitInfo - { - SwapChainDesc SwapChainAttribs; - void *pNativeWndHandle = nullptr; - }; - class GLContext { public: typedef HGLRC NativeGLContextType; - GLContext( const ContextInitInfo &Info, struct DeviceCaps &DeviceCaps ); + GLContext( const struct EngineGLAttribs &InitAttribs, struct DeviceCaps &DeviceCaps ); ~GLContext(); void SwapBuffers(); - const SwapChainDesc& GetSwapChainDesc()const{ return m_SwapChainAttribs; } - NativeGLContextType GetCurrentNativeGLContext(); private: HGLRC m_Context; HDC m_WindowHandleToDeviceContext; - SwapChainDesc m_SwapChainAttribs; }; } diff --git a/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h index 520e9965..9b128518 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h @@ -32,7 +32,7 @@ template<class CreateReleaseHelperType> class GLObjWrapper { public: - GLObjWrapper(bool CreateObject, CreateReleaseHelperType CreateReleaseHelper = CreateReleaseHelperType()) : + explicit GLObjWrapper(bool CreateObject, CreateReleaseHelperType CreateReleaseHelper = CreateReleaseHelperType()) : m_uiHandle(0), m_CreateReleaseHelper(CreateReleaseHelper) { @@ -224,9 +224,30 @@ typedef GLObjWrapper<GLSamplerCreateReleaseHelper> GLSamplerObj; class GLFBOCreateReleaseHelper { public: - void Create(GLuint &FBO) { glGenFramebuffers(1, &FBO); } - void Release(GLuint FBO) { glDeleteFramebuffers(1, &FBO); } + explicit GLFBOCreateReleaseHelper(GLuint ExternalFBOHandle = 0) : + m_ExternalFBOHandle(ExternalFBOHandle) + {} + + void Create(GLuint &FBO) + { + if (m_ExternalFBOHandle != 0) + FBO = m_ExternalFBOHandle; // Attach to external FBO handle + else + glGenFramebuffers(1, &FBO); + } + + void Release(GLuint FBO) + { + if (m_ExternalFBOHandle != 0) + m_ExternalFBOHandle = 0; // DO NOT delete the FBO + else + glDeleteFramebuffers(1, &FBO); + } + static const char *Name; + +private: + GLuint m_ExternalFBOHandle; }; typedef GLObjWrapper<GLFBOCreateReleaseHelper> GLFrameBufferObj; diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h index e550da3f..1caa3b89 100644 --- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.h @@ -29,6 +29,7 @@ #include "BaseInterfacesGL.h" #include "FBOCache.h" #include "TexRegionRender.h" +#include "EngineGLAttribs.h" enum class GPU_VENDOR { @@ -55,7 +56,7 @@ class RenderDeviceGLImpl : public RenderDeviceBase<IGLDeviceBaseInterface> public: typedef RenderDeviceBase<IGLDeviceBaseInterface> TRenderDeviceBase; - RenderDeviceGLImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const ContextInitInfo &InitInfo ); + RenderDeviceGLImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs ); ~RenderDeviceGLImpl(); virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; diff --git a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h index 4e634b87..87859fb8 100644 --- a/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/SwapChainGLImpl.h @@ -25,6 +25,7 @@ #include "SwapChainGL.h" #include "SwapChainBase.h" +#include "GLObjectWrapper.h" namespace Diligent { @@ -37,16 +38,19 @@ public: typedef SwapChainBase<ISwapChainGL> TSwapChainBase; SwapChainGLImpl(IReferenceCounters *pRefCounters, + const EngineGLAttribs &InitAttribs, const SwapChainDesc& SwapChainDesc, class RenderDeviceGLImpl* pRenderDeviceGL, class DeviceContextGLImpl* pImmediateContextGL); ~SwapChainGLImpl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ); + virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; - virtual void Present(); + virtual void Present()override; - virtual void Resize( Uint32 NewWidth, Uint32 NewHeight ); + virtual void Resize( Uint32 NewWidth, Uint32 NewHeight )override; + + virtual GLuint GetDefaultFBO()const override { return 0; } }; } diff --git a/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h b/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h new file mode 100644 index 00000000..59dbad3d --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h @@ -0,0 +1,48 @@ +/* Copyright 2015-2018 Egor Yusov + * + * 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 + +/// \file +/// Definition of the Engine OpenGL/GLES attribs + +#include "BasicTypes.h" +#include "GraphicsTypes.h" + +namespace Diligent +{ + /// Attributes of the OpenGL-based engine implementation + struct EngineGLAttribs : public EngineCreationAttribs + { + /// Native window handle + + /// * On Win32 platform, this is a window handle (HWND) + /// * On Android platform, this is a pointer to the native window (ANativeWindow*) + void *pNativeWndHandle = nullptr; + +#if PLATFORM_LINUX + /// For linux platform only, this is the pointer to the display + void *pDisplay = nullptr; +#endif + }; +} diff --git a/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h b/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h index a9c4891f..a24858ca 100644 --- a/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h +++ b/Graphics/GraphicsEngineOpenGL/interface/RenderDeviceFactoryOpenGL.h @@ -30,6 +30,7 @@ #include "DeviceContext.h" #include "SwapChain.h" #include "HLSL2GLSLConverter.h" +#include "EngineGLAttribs.h" #if defined(PLATFORM_WIN32) || defined(PLATFORM_UNIVERSAL_WINDOWS) @@ -56,18 +57,14 @@ namespace Diligent class IEngineFactoryOpenGL { public: - virtual void CreateDeviceAndSwapChainGL(const EngineCreationAttribs& CreationAttribs, + virtual void CreateDeviceAndSwapChainGL(const EngineGLAttribs& CreationAttribs, IRenderDevice **ppDevice, IDeviceContext **ppImmediateContext, const SwapChainDesc& SCDesc, - void *pNativeWndHandle, - #if PLATFORM_LINUX - void *pDisplay, - #endif ISwapChain **ppSwapChain ) = 0; virtual void CreateHLSL2GLSLConverter(IHLSL2GLSLConverter **ppConverter) = 0; - virtual void AttachToActiveGLContext( const EngineCreationAttribs& CreationAttribs, + virtual void AttachToActiveGLContext( const EngineGLAttribs& CreationAttribs, IRenderDevice **ppDevice, IDeviceContext **ppImmediateContext ) = 0; }; diff --git a/Graphics/GraphicsEngineOpenGL/interface/SwapChainGL.h b/Graphics/GraphicsEngineOpenGL/interface/SwapChainGL.h index d77eb4e6..e9405899 100644 --- a/Graphics/GraphicsEngineOpenGL/interface/SwapChainGL.h +++ b/Graphics/GraphicsEngineOpenGL/interface/SwapChainGL.h @@ -39,6 +39,8 @@ static constexpr INTERFACE_ID IID_SwapChainGL = class ISwapChainGL : public ISwapChain { public: + /// Returns the default framebuffer handle + virtual GLuint GetDefaultFBO()const = 0; }; } diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 5946f899..8b243605 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -22,14 +22,15 @@ */ #include "pch.h" -#include "DeviceContextGLImpl.h" -#include "RenderDeviceGLImpl.h" -#include "GLTypeConversions.h" - #include <iostream> #include <fstream> #include <string> +#include "SwapChainGL.h" +#include "DeviceContextGLImpl.h" +#include "RenderDeviceGLImpl.h" +#include "GLTypeConversions.h" + #include "BufferGLImpl.h" #include "ShaderGLImpl.h" #include "VAOCache.h" @@ -51,7 +52,8 @@ namespace Diligent DeviceContextGLImpl::DeviceContextGLImpl( IReferenceCounters *pRefCounters, class RenderDeviceGLImpl *pDeviceGL, bool bIsDeferred ) : TDeviceContextBase(pRefCounters, pDeviceGL, bIsDeferred), m_ContextState(pDeviceGL), - m_CommitedResourcesTentativeBarriers(0) + m_CommitedResourcesTentativeBarriers(0), + m_DefaultFBO(false) { m_BoundWritableTextures.reserve( 16 ); m_BoundWritableBuffers.reserve( 16 ); @@ -285,7 +287,13 @@ namespace Diligent { if (m_IsDefaultFramebufferBound) { - m_ContextState.BindFBO( GLObjectWrappers::GLFrameBufferObj(false) ); + auto *pSwapChainGL = ValidatedCast<ISwapChainGL>(m_pSwapChain.RawPtr()); + GLuint DefaultFBOHandle = pSwapChainGL->GetDefaultFBO(); + if (m_DefaultFBO != DefaultFBOHandle) + { + m_DefaultFBO = GLObjectWrappers::GLFrameBufferObj(true, GLObjectWrappers::GLFBOCreateReleaseHelper(DefaultFBOHandle)); + } + m_ContextState.BindFBO(m_DefaultFBO); } else { diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp index a09d8a2a..0760e70e 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextWindows.cpp @@ -26,6 +26,7 @@ #include "GLContextWindows.h" #include "DeviceCaps.h" #include "GLTypeConversions.h" +#include "EngineGLAttribs.h" namespace Diligent { @@ -84,19 +85,14 @@ namespace Diligent LOG_INFO_MESSAGE_ONCE( MessageSS.str().c_str() ); } - GLContext::GLContext( const ContextInitInfo &Info, DeviceCaps &DeviceCaps ) : - m_SwapChainAttribs(Info.SwapChainAttribs), + GLContext::GLContext(const EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps ) : m_Context(0), m_WindowHandleToDeviceContext(0) { Int32 MajorVersion = 0, MinorVersion = 0; - if(Info.pNativeWndHandle != nullptr) + if(InitAttribs.pNativeWndHandle != nullptr) { - HWND hWnd = reinterpret_cast<HWND>(Info.pNativeWndHandle); - RECT rc; - GetClientRect( hWnd, &rc ); - m_SwapChainAttribs.Width = rc.right - rc.left; - m_SwapChainAttribs.Height = rc.bottom - rc.top; + HWND hWnd = reinterpret_cast<HWND>(InitAttribs.pNativeWndHandle); // See http://www.opengl.org/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_(C%2B%2B/Win) // http://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL) @@ -201,7 +197,7 @@ namespace Diligent //Or better yet, use the GL3 way to get the version number glGetIntegerv( GL_MAJOR_VERSION, &MajorVersion ); glGetIntegerv( GL_MINOR_VERSION, &MinorVersion ); - LOG_INFO_MESSAGE(Info.pNativeWndHandle != nullptr ? "Initialized OpenGL " : "Attached to OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ')'); + LOG_INFO_MESSAGE(InitAttribs.pNativeWndHandle != nullptr ? "Initialized OpenGL " : "Attached to OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ')'); // Under the standard filtering rules for cubemaps, filtering does not work across faces of the cubemap. // This results in a seam across the faces of a cubemap. This was a hardware limitation in the past, but diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp index bf172073..d10e4a0d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp @@ -57,19 +57,15 @@ public: return &TheFactory; } - virtual void CreateDeviceAndSwapChainGL(const EngineCreationAttribs& CreationAttribs, + virtual void CreateDeviceAndSwapChainGL(const EngineGLAttribs& CreationAttribs, IRenderDevice **ppDevice, IDeviceContext **ppImmediateContext, const SwapChainDesc& SCDesc, - void *pNativeWndHandle, - #if PLATFORM_LINUX - void *pDisplay, - #endif ISwapChain **ppSwapChain )override final; virtual void CreateHLSL2GLSLConverter(IHLSL2GLSLConverter **ppConverter)override final; - virtual void AttachToActiveGLContext( const EngineCreationAttribs& CreationAttribs, + virtual void AttachToActiveGLContext( const EngineGLAttribs& CreationAttribs, IRenderDevice **ppDevice, IDeviceContext **ppImmediateContext )override final; }; @@ -84,20 +80,12 @@ public: /// \param [out] ppImmediateContext - Address of the memory location where pointers to /// the immediate context will be written. /// \param [in] SCDesc - Swap chain description. -/// \param [in] pNativeWndHandle - Platform-specific native handle of the window -/// the swap chain will be associated with: -/// * On Win32 platform, this should be window handle (HWND) -/// * On Android platform, this should be a pointer to the native window (ANativeWindow*) /// \param [out] ppSwapChain - Address of the memory location where pointer to the new /// swap chain will be written. -void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineCreationAttribs& CreationAttribs, +void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineGLAttribs& CreationAttribs, IRenderDevice **ppDevice, IDeviceContext **ppImmediateContext, const SwapChainDesc& SCDesc, - void *pNativeWndHandle, - #if PLATFORM_LINUX - void *pDisplay, - #endif ISwapChain **ppSwapChain ) { VERIFY( ppDevice && ppImmediateContext && ppSwapChain, "Null pointer provided" ); @@ -113,13 +101,7 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineCreationAtt SetRawAllocator(CreationAttribs.pRawMemAllocator); auto &RawMemAllocator = GetRawAllocator(); - ContextInitInfo InitInfo; - InitInfo.pNativeWndHandle = pNativeWndHandle; - #if PLATFORM_LINUX - InitInfo.pDisplay = pDisplay; - #endif - InitInfo.SwapChainAttribs = SCDesc; - RenderDeviceGLImpl *pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, InitInfo) ); + RenderDeviceGLImpl *pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, CreationAttribs) ); pRenderDeviceOpenGL->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice) ); DeviceContextGLImpl *pDeviceContextOpenGL( NEW_RC_OBJ(RawMemAllocator, "DeviceContextGLImpl instance", DeviceContextGLImpl)(pRenderDeviceOpenGL, false ) ); @@ -128,7 +110,7 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineCreationAtt pDeviceContextOpenGL->QueryInterface(IID_DeviceContext, reinterpret_cast<IObject**>(ppImmediateContext) ); pRenderDeviceOpenGL->SetImmediateContext(pDeviceContextOpenGL); - SwapChainGLImpl *pSwapChainGL = NEW_RC_OBJ(RawMemAllocator, "SwapChainGLImpl instance", SwapChainGLImpl)(SCDesc, pRenderDeviceOpenGL, pDeviceContextOpenGL ); + SwapChainGLImpl *pSwapChainGL = NEW_RC_OBJ(RawMemAllocator, "SwapChainGLImpl instance", SwapChainGLImpl)(CreationAttribs, SCDesc, pRenderDeviceOpenGL, pDeviceContextOpenGL ); pSwapChainGL->QueryInterface(IID_SwapChain, reinterpret_cast<IObject**>(ppSwapChain) ); pDeviceContextOpenGL->SetSwapChain(pSwapChainGL); @@ -168,7 +150,7 @@ void EngineFactoryOpenGLImpl::CreateDeviceAndSwapChainGL(const EngineCreationAtt /// the created device will be written. /// \param [out] ppImmediateContext - Address of the memory location where pointers to /// the immediate context will be written. -void EngineFactoryOpenGLImpl::AttachToActiveGLContext( const EngineCreationAttribs& CreationAttribs, +void EngineFactoryOpenGLImpl::AttachToActiveGLContext( const EngineGLAttribs& CreationAttribs, IRenderDevice **ppDevice, IDeviceContext **ppImmediateContext ) { @@ -184,11 +166,7 @@ void EngineFactoryOpenGLImpl::AttachToActiveGLContext( const EngineCreationAttri SetRawAllocator(CreationAttribs.pRawMemAllocator); auto &RawMemAllocator = GetRawAllocator(); - ContextInitInfo InitInfo; - InitInfo.SwapChainAttribs.BufferCount = 0; - InitInfo.SwapChainAttribs.ColorBufferFormat = TEX_FORMAT_UNKNOWN; - InitInfo.SwapChainAttribs.DepthBufferFormat = TEX_FORMAT_UNKNOWN; - RenderDeviceGLImpl *pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, InitInfo) ); + RenderDeviceGLImpl *pRenderDeviceOpenGL( NEW_RC_OBJ(RawMemAllocator, "TRenderDeviceGLImpl instance", TRenderDeviceGLImpl)(RawMemAllocator, CreationAttribs) ); pRenderDeviceOpenGL->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice) ); DeviceContextGLImpl *pDeviceContextOpenGL( NEW_RC_OBJ(RawMemAllocator, "DeviceContextGLImpl instance", DeviceContextGLImpl)(pRenderDeviceOpenGL, false ) ); diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index 1eda4043..7b126e80 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp @@ -46,10 +46,10 @@ namespace Diligent { -RenderDeviceGLImpl :: RenderDeviceGLImpl(IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const ContextInitInfo &InitInfo): +RenderDeviceGLImpl :: RenderDeviceGLImpl(IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs): TRenderDeviceBase(pRefCounters, RawMemAllocator, 0, sizeof(TextureBaseGL), sizeof(TextureViewGLImpl), sizeof(BufferGLImpl), sizeof(BufferViewGLImpl), sizeof(ShaderGLImpl), sizeof(SamplerGLImpl), sizeof(PipelineStateGLImpl), sizeof(ShaderResourceBindingGLImpl)), // Device caps must be filled in before the constructor of Pipeline Cache is called! - m_GLContext(InitInfo, m_DeviceCaps), + m_GLContext(InitAttribs, m_DeviceCaps), m_TexRegionRender(this) { GLint NumExtensions = 0; diff --git a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp index a56f669c..bedc984a 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -29,11 +29,21 @@ namespace Diligent { SwapChainGLImpl::SwapChainGLImpl(IReferenceCounters *pRefCounters, + const EngineGLAttribs &InitAttribs, const SwapChainDesc& SCDesc, RenderDeviceGLImpl* pRenderDeviceGL, DeviceContextGLImpl* pImmediateContextGL) : - TSwapChainBase( pRefCounters, pRenderDeviceGL, pImmediateContextGL, pRenderDeviceGL->m_GLContext.GetSwapChainDesc() ) + TSwapChainBase( pRefCounters, pRenderDeviceGL, pImmediateContextGL, SCDesc) { +#if defined(PLATFORM_WIN32) + HWND hWnd = reinterpret_cast<HWND>(InitAttribs.pNativeWndHandle); + RECT rc; + GetClientRect(hWnd, &rc); + m_SwapChainDesc.Width = rc.right - rc.left; + m_SwapChainDesc.Height = rc.bottom - rc.top; +#else +# error Unsupported platform +#endif } SwapChainGLImpl::~SwapChainGLImpl() @@ -45,7 +55,12 @@ IMPLEMENT_QUERY_INTERFACE( SwapChainGLImpl, IID_SwapChainGL, TSwapChainBase ) void SwapChainGLImpl::Present() { auto *pDeviceGL = ValidatedCast<RenderDeviceGLImpl>(m_pRenderDevice.RawPtr()); - pDeviceGL->m_GLContext.SwapBuffers(); + auto &GLContext = pDeviceGL->m_GLContext; +#if defined(PLATFORM_WIN32) + GLContext.SwapBuffers(); +#else +# error Unsupported platform +#endif } void SwapChainGLImpl::Resize( Uint32 NewWidth, Uint32 NewHeight ) |
