From e5d695a20e555cb50435c8c82adcb809d6a2c0cf Mon Sep 17 00:00:00 2001 From: Egor Date: Sat, 3 Feb 2018 12:21:27 -0800 Subject: Fixed Android and MacOS builds --- .../GraphicsEngineOpenGL/include/GLContextAndroid.h | 14 +++++--------- Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h | 2 +- Graphics/GraphicsEngineOpenGL/include/GLContextMacOS.h | 14 +------------- .../GraphicsEngineOpenGL/include/GLObjectWrapper.h | 2 +- .../include/RenderDeviceGLESImpl.h | 2 +- Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp | 17 +++++++---------- Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp | 18 +++--------------- .../GraphicsEngineOpenGL/src/RenderDeviceGLESImpl.cpp | 4 ++-- Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp | 12 +++++++++++- 9 files changed, 32 insertions(+), 53 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') 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 40dcf92d..49c5d99a 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextLinux.h @@ -30,7 +30,7 @@ namespace Diligent public: typedef GLXContext NativeGLContextType; - GLContext(const struct EngineGLAttribs &Attribs, struct DeviceCaps &DeviceCaps); + GLContext(const struct EngineGLAttribs &InitAttribs, struct DeviceCaps &DeviceCaps); ~GLContext(); void SwapBuffers(); 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/GLObjectWrapper.h b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h index 9b128518..de0e14d6 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLObjectWrapper.h @@ -32,7 +32,7 @@ template class GLObjWrapper { public: - explicit GLObjWrapper(bool CreateObject, CreateReleaseHelperType CreateReleaseHelper = CreateReleaseHelperType()) : + GLObjWrapper(bool CreateObject, CreateReleaseHelperType CreateReleaseHelper = CreateReleaseHelperType()) : m_uiHandle(0), m_CreateReleaseHelper(CreateReleaseHelper) { 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/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(Info.pNativeWndHandle); + auto *NativeWindow = reinterpret_cast(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/GLContextMacOS.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp index 81e0efdd..65cca525 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextMacOS.cpp @@ -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( struct 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/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/SwapChainGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp index ed47747e..4754b93d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -50,6 +50,14 @@ SwapChainGLImpl::SwapChainGLImpl(IReferenceCounters *pRefCounters, 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_SwapChainAttribs.Width = 1024; + m_SwapChainAttribs.Height = 768; #else # error Unsupported platform #endif @@ -65,8 +73,10 @@ void SwapChainGLImpl::Present() { auto *pDeviceGL = ValidatedCast(m_pRenderDevice.RawPtr()); auto &GLContext = pDeviceGL->m_GLContext; -#if defined(PLATFORM_WIN32) || defined(PLATFORM_LINUX) +#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 -- cgit v1.2.3