diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-02-03 20:52:27 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-02-03 20:52:27 +0000 |
| commit | 12606a7ba80f5c0be94b80397cfb4e925132a39c (patch) | |
| tree | 6a87434257c6904f54c3cc25d1d980b64a3a1129 /Graphics/GraphicsEngineOpenGL | |
| parent | Added SwapChain ISO impl (diff) | |
| parent | Fixed another MacOS build issue (diff) | |
| download | DiligentCore-12606a7ba80f5c0be94b80397cfb4e925132a39c.tar.gz DiligentCore-12606a7ba80f5c0be94b80397cfb4e925132a39c.zip | |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
22 files changed, 180 insertions, 148 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/CMakeLists.txt b/Graphics/GraphicsEngineOpenGL/CMakeLists.txt index 71d822d1..74058c91 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/GLContextAndroid.h b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h index 8e64b2cd..622b60ba 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h @@ -28,18 +28,12 @@ namespace Diligent { - struct ContextInitInfo - { - SwapChainDesc SwapChainAttribs; - void *pNativeWndHandle = nullptr; - }; - class GLContext { public: typedef EGLContext NativeGLContextType; - GLContext( const ContextInitInfo &Info, DeviceCaps &DeviceCaps ); + GLContext( const struct EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps ); ~GLContext(); bool Init( ANativeWindow* window ); @@ -51,9 +45,9 @@ namespace Diligent void Suspend(); EGLint Resume( ANativeWindow* window ); - const SwapChainDesc& GetSwapChainDesc()const{ return SwapChainAttribs_; } - NativeGLContextType GetCurrentNativeGLContext(); + int32_t GetScreenWidth()const{return screen_width_;} + int32_t GetScreenHeight()const{return screen_height_;} private: //EGL configurations @@ -68,6 +62,8 @@ namespace Diligent int32_t depth_size_ = 0; int32_t major_version_ = 0; int32_t minor_version_ = 0; + int32_t screen_width_ = 0; + int32_t screen_height_ = 0; //Flags bool gles_initialized_ = false; diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h index e4530fd7..49c5d99a 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h @@ -25,31 +25,20 @@ namespace Diligent { - - struct ContextInitInfo - { - SwapChainDesc SwapChainAttribs; - void *pNativeWndHandle = nullptr; - void *pDisplay = nullptr; - }; - class GLContext { public: typedef GLXContext 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: void *m_pNativeWindow = nullptr; void *m_pDisplay = nullptr; NativeGLContextType m_Context; - SwapChainDesc m_SwapChainAttribs; }; } diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h index 3e5b77bb..df6d3b23 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h @@ -25,25 +25,13 @@ namespace Diligent { - struct ContextInitInfo - { - SwapChainDesc SwapChainAttribs; - void *pNativeWndHandle = nullptr; - }; - class GLContext { public: typedef void* NativeGLContextType; // NSOpenGLContext* - GLContext(const ContextInitInfo &Info, struct DeviceCaps &DeviceCaps); - void SwapBuffers(); - - const SwapChainDesc& GetSwapChainDesc()const{ return m_SwapChainAttribs; } + GLContext(const struct EngineGLAttribs &InitAttribs, struct DeviceCaps &DeviceCaps); NativeGLContextType GetCurrentNativeGLContext(); - - private: - SwapChainDesc m_SwapChainAttribs; }; } 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 43f77193..4da5932d 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h @@ -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/RenderDeviceGLESImpl.h b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h index cb542177..973e31b9 100644 --- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLESImpl.h @@ -31,7 +31,7 @@ namespace Diligent class RenderDeviceGLESImpl : public RenderDeviceGLImpl { public: - RenderDeviceGLESImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const ContextInitInfo &InitInfo ); + RenderDeviceGLESImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs ); virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ); 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..bbb998bd --- /dev/null +++ b/Graphics/GraphicsEngineOpenGL/interface/EngineGLAttribs.h @@ -0,0 +1,49 @@ +/* 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*) + /// * On Linux, this is the native window (Window) + 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 13e884b7..86f39647 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 854eebaf..155758a5 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/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp index 1abda109..685e82cb 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp @@ -24,6 +24,7 @@ #include "pch.h" #include "GLContextAndroid.h" +#include "EngineGLAttribs.h" #ifndef EGL_CONTEXT_MINOR_VERSION_KHR #define EGL_CONTEXT_MINOR_VERSION_KHR 0x30FB @@ -114,11 +115,8 @@ namespace Diligent LOG_ERROR_AND_THROW( "Failed to create EGLSurface" ); } - int32_t screen_width = 0, screen_height = 0; - eglQuerySurface( display_, surface_, EGL_WIDTH, &screen_width ); - eglQuerySurface( display_, surface_, EGL_HEIGHT, &screen_height ); - SwapChainAttribs_.Width = screen_width; - SwapChainAttribs_.Height = screen_height; + eglQuerySurface( display_, surface_, EGL_WIDTH, &screen_width_ ); + eglQuerySurface( display_, surface_, EGL_HEIGHT, &screen_height_ ); /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). @@ -230,17 +228,16 @@ namespace Diligent return true; } - GLContext::GLContext( const ContextInitInfo &Info, DeviceCaps &DeviceCaps ) : + GLContext::GLContext( const EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps ) : display_( EGL_NO_DISPLAY ), surface_( EGL_NO_SURFACE ), context_( EGL_NO_CONTEXT ), egl_context_initialized_( false ), gles_initialized_( false ), major_version_(0), - minor_version_(0), - SwapChainAttribs_(Info.SwapChainAttribs) + minor_version_(0) { - auto *NativeWindow = reinterpret_cast<ANativeWindow*>(Info.pNativeWndHandle); + auto *NativeWindow = reinterpret_cast<ANativeWindow*>(InitAttribs.pNativeWndHandle); Init( NativeWindow ); FillDeviceCaps(DeviceCaps); @@ -351,7 +348,7 @@ namespace Diligent eglQuerySurface( display_, surface_, EGL_WIDTH, &new_screen_width ); eglQuerySurface( display_, surface_, EGL_HEIGHT, &new_screen_height ); - if( new_screen_width != SwapChainAttribs_.Width || new_screen_height != SwapChainAttribs_.Height ) + if( new_screen_width != screen_width_ || new_screen_height != screen_height_ ) { //Screen resized LOG_INFO_MESSAGE( "Screen resized\n" ); diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp index c20b4b9f..ffa31068 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextLinux.cpp @@ -26,6 +26,7 @@ #include "GLContextLinux.h" #include "DeviceCaps.h" #include "GLTypeConversions.h" +#include "EngineGLAttribs.h" namespace Diligent { @@ -83,11 +84,10 @@ 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_pNativeWindow(Info.pNativeWndHandle), - m_pDisplay(Info.pDisplay) + m_pNativeWindow(InitAttribs.pNativeWndHandle), + m_pDisplay(InitAttribs.pDisplay) { auto CurrentCtx = glXGetCurrentContext(); if (CurrentCtx == 0) @@ -100,17 +100,8 @@ namespace Diligent if( GLEW_OK != err ) LOG_ERROR_AND_THROW( "Failed to initialize GLEW" ); - if(Info.pNativeWndHandle != nullptr && Info.pDisplay != nullptr) + if(InitAttribs.pNativeWndHandle != nullptr && InitAttribs.pDisplay != nullptr) { - auto wnd = static_cast<Window>(reinterpret_cast<size_t>(Info.pNativeWndHandle)); - auto display = reinterpret_cast<Display*>(Info.pDisplay); - - XWindowAttributes XWndAttribs; - XGetWindowAttributes(display, wnd, &XWndAttribs); - - m_SwapChainAttribs.Width = XWndAttribs.width; - m_SwapChainAttribs.Height = XWndAttribs.height; - //glXSwapIntervalEXT(0); if( glDebugMessageCallback ) @@ -135,7 +126,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, ", ", GLRenderer, ')'); + LOG_INFO_MESSAGE(InitAttribs.pNativeWndHandle != nullptr ? "Initialized OpenGL " : "Attached to OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ", ", GLRenderer, ')'); // 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/GLContextMacOS.mm b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm index 81e0efdd..b578dd92 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.mm @@ -28,12 +28,11 @@ #include "GLContextMacOS.h" #include "DeviceCaps.h" #include "GLTypeConversions.h" +#include "EngineGLAttribs.h" namespace Diligent { - - GLContext::GLContext( const ContextInitInfo &Info, DeviceCaps &DeviceCaps ) : - m_SwapChainAttribs(Info.SwapChainAttribs) + GLContext::GLContext( const EngineGLAttribs &InitAttribs, DeviceCaps &DeviceCaps ) { if (GetCurrentNativeGLContext() == nullptr) { @@ -46,12 +45,6 @@ namespace Diligent if( GLEW_OK != err ) LOG_ERROR_AND_THROW( "Failed to initialize GLEW" ); - //Set dummy width and height until resize is called by the app - if(m_SwapChainAttribs.Width == 0) - m_SwapChainAttribs.Width = 1024; - if(m_SwapChainAttribs.Height) - m_SwapChainAttribs.Height = 768; - //Checking GL version const GLubyte *GLVersionString = glGetString( GL_VERSION ); const GLubyte *GLRenderer = glGetString(GL_RENDERER); @@ -60,7 +53,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, ", ", GLRenderer, ')'); + LOG_INFO_MESSAGE(InitAttribs.pNativeWndHandle != nullptr ? "Initialized OpenGL " : "Attached to OpenGL ", MajorVersion, '.', MinorVersion, " context (", GLVersionString, ", ", GLRenderer, ')'); // 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 @@ -93,11 +86,6 @@ namespace Diligent DeviceCaps.bMultithreadedResourceCreationSupported = False; } - void GLContext::SwapBuffers() - { - LOG_ERROR("Swap buffers operation must be performed by the app on MacOS"); - } - GLContext::NativeGLContextType GLContext::GetCurrentNativeGLContext() { NSOpenGLContext* CurrentCtx = [NSOpenGLContext currentContext]; 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 2ef70c15..a3945fc2 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceFactoryOpenGL.cpp @@ -59,19 +59,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; }; @@ -86,20 +82,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" ); @@ -115,13 +103,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 ) ); @@ -130,7 +112,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); @@ -170,7 +152,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 ) { @@ -186,11 +168,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/RenderDeviceGLESImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp index 041b4fcd..0446a157 100644 --- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp @@ -27,8 +27,8 @@ namespace Diligent { - RenderDeviceGLESImpl::RenderDeviceGLESImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const ContextInitInfo &InitInfo ) : - RenderDeviceGLImpl( pRefCounters, RawMemAllocator, InitInfo ) + RenderDeviceGLESImpl::RenderDeviceGLESImpl( IReferenceCounters *pRefCounters, IMemoryAllocator &RawMemAllocator, const EngineGLAttribs &InitAttribs ) : + RenderDeviceGLImpl( pRefCounters, RawMemAllocator, InitAttribs ) { } diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp index 551e2751..ffb9794a 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..6b392943 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -29,11 +29,38 @@ 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; +#elif defined(PLATFORM_LINUX) + auto wnd = static_cast<Window>(reinterpret_cast<size_t>(InitAttribs.pNativeWndHandle)); + auto display = reinterpret_cast<Display*>(InitAttribs.pDisplay); + + XWindowAttributes XWndAttribs; + XGetWindowAttributes(display, wnd, &XWndAttribs); + + m_SwapChainDesc.Width = XWndAttribs.width; + m_SwapChainDesc.Height = XWndAttribs.height; +#elif defined(PLATFORM_ANDROID) + auto &GLContext = pRenderDeviceGL->m_GLContext; + m_SwapChainDesc.Width = GLContext.GetScreenWidth(); + m_SwapChainDesc.Height = GLContext.GetScreenHeight(); +#elif defined(PLATFORM_MACOS) + //Set dummy width and height until resize is called by the app + m_SwapChainDesc.Width = 1024; + m_SwapChainDesc.Height = 768; +#else +# error Unsupported platform +#endif } SwapChainGLImpl::~SwapChainGLImpl() @@ -45,7 +72,14 @@ 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) || defined(PLATFORM_LINUX) ||defined(PLATFORM_ANDROID) + GLContext.SwapBuffers(); +#elif defined(PLATFORM_MACOS) + LOG_ERROR("Swap buffers operation must be performed by the app on MacOS"); +#else +# error Unsupported platform +#endif } void SwapChainGLImpl::Resize( Uint32 NewWidth, Uint32 NewHeight ) |
