Skip to content

Commit 520227f

Browse files
Implemented more robust screen orientation/size change handling on Android
1 parent 0e7f471 commit 520227f

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

Graphics/GraphicsEngineOpenGL/include/GLContextAndroid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ namespace Diligent
4040

4141
void SwapBuffers();
4242

43+
void UpdateScreenSize();
44+
4345
bool Invalidate();
4446

4547
void Suspend();

Graphics/GraphicsEngineOpenGL/src/GLContextAndroid.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,22 @@ namespace Diligent
340340
}
341341

342342

343+
void GLContext::UpdateScreenSize()
344+
{
345+
int32_t new_screen_width = 0;
346+
int32_t new_screen_height = 0;
347+
eglQuerySurface( display_, surface_, EGL_WIDTH, &new_screen_width );
348+
eglQuerySurface( display_, surface_, EGL_HEIGHT, &new_screen_height );
349+
350+
if( new_screen_width != screen_width_ || new_screen_height != screen_height_ )
351+
{
352+
screen_width_ = new_screen_width;
353+
screen_height_ = new_screen_height;
354+
//Screen resized
355+
LOG_INFO_MESSAGE( "Window size changed to ", screen_width_, "x", screen_height_ );
356+
}
357+
}
358+
343359
EGLint GLContext::Resume( ANativeWindow* window )
344360
{
345361
LOG_INFO_MESSAGE( "Resuming gl context\n" );
@@ -353,16 +369,7 @@ namespace Diligent
353369
//Create surface
354370
window_ = window;
355371
surface_ = eglCreateWindowSurface( display_, config_, window_, NULL );
356-
int32_t new_screen_width = 0;
357-
int32_t new_screen_height = 0;
358-
eglQuerySurface( display_, surface_, EGL_WIDTH, &new_screen_width );
359-
eglQuerySurface( display_, surface_, EGL_HEIGHT, &new_screen_height );
360-
361-
if( new_screen_width != screen_width_ || new_screen_height != screen_height_ )
362-
{
363-
//Screen resized
364-
LOG_INFO_MESSAGE( "Screen resized\n" );
365-
}
372+
UpdateScreenSize();
366373

367374
if( eglMakeCurrent( display_, surface_, surface_, context_ ) == EGL_TRUE )
368375
return EGL_SUCCESS;

Graphics/GraphicsEngineOpenGL/src/SwapChainGLImpl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ void SwapChainGLImpl::Present()
8484

8585
void SwapChainGLImpl::Resize( Uint32 NewWidth, Uint32 NewHeight )
8686
{
87+
#if PLATFORM_ANDROID
88+
auto *pDeviceGL = ValidatedCast<RenderDeviceGLImpl>(m_pRenderDevice.RawPtr());
89+
auto &GLContext = pDeviceGL->m_GLContext;
90+
GLContext.UpdateScreenSize();
91+
NewWidth = GLContext.GetScreenWidth();
92+
NewHeight = GLContext.GetScreenHeight();
93+
#endif
94+
8795
if( TSwapChainBase::Resize( NewWidth, NewHeight ) )
8896
{
8997
auto pDeviceContext = m_wpDeviceContext.Lock();

0 commit comments

Comments
 (0)