From 520227f04f0ea08521db716c4d1fbc4fe8264cfe Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 18 Feb 2018 00:17:51 -0800 Subject: Implemented more robust screen orientation/size change handling on Android --- .../include/GLContextAndroid.h | 2 ++ .../GraphicsEngineOpenGL/src/GLContextAndroid.cpp | 27 ++++++++++++++-------- .../GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp | 8 +++++++ 3 files changed, 27 insertions(+), 10 deletions(-) (limited to 'Graphics/GraphicsEngineOpenGL') diff --git a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h index 622b60ba..db25be8e 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h @@ -40,6 +40,8 @@ namespace Diligent void SwapBuffers(); + void UpdateScreenSize(); + bool Invalidate(); void Suspend(); diff --git a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp index 47353a04..a8f788ee 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp @@ -340,6 +340,22 @@ namespace Diligent } + void GLContext::UpdateScreenSize() + { + int32_t new_screen_width = 0; + int32_t new_screen_height = 0; + eglQuerySurface( display_, surface_, EGL_WIDTH, &new_screen_width ); + eglQuerySurface( display_, surface_, EGL_HEIGHT, &new_screen_height ); + + if( new_screen_width != screen_width_ || new_screen_height != screen_height_ ) + { + screen_width_ = new_screen_width; + screen_height_ = new_screen_height; + //Screen resized + LOG_INFO_MESSAGE( "Window size changed to ", screen_width_, "x", screen_height_ ); + } + } + EGLint GLContext::Resume( ANativeWindow* window ) { LOG_INFO_MESSAGE( "Resuming gl context\n" ); @@ -353,16 +369,7 @@ namespace Diligent //Create surface window_ = window; surface_ = eglCreateWindowSurface( display_, config_, window_, NULL ); - int32_t new_screen_width = 0; - int32_t new_screen_height = 0; - eglQuerySurface( display_, surface_, EGL_WIDTH, &new_screen_width ); - eglQuerySurface( display_, surface_, EGL_HEIGHT, &new_screen_height ); - - if( new_screen_width != screen_width_ || new_screen_height != screen_height_ ) - { - //Screen resized - LOG_INFO_MESSAGE( "Screen resized\n" ); - } + UpdateScreenSize(); if( eglMakeCurrent( display_, surface_, surface_, context_ ) == EGL_TRUE ) return EGL_SUCCESS; diff --git a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp index 2cce8cde..4939716d 100644 --- a/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp @@ -84,6 +84,14 @@ void SwapChainGLImpl::Present() void SwapChainGLImpl::Resize( Uint32 NewWidth, Uint32 NewHeight ) { +#if PLATFORM_ANDROID + auto *pDeviceGL = ValidatedCast(m_pRenderDevice.RawPtr()); + auto &GLContext = pDeviceGL->m_GLContext; + GLContext.UpdateScreenSize(); + NewWidth = GLContext.GetScreenWidth(); + NewHeight = GLContext.GetScreenHeight(); +#endif + if( TSwapChainBase::Resize( NewWidth, NewHeight ) ) { auto pDeviceContext = m_wpDeviceContext.Lock(); -- cgit v1.2.3