From 5a22bd0ef444ebc85e54af2216569b2de902ec38 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Tue, 21 May 2024 10:31:20 +0300 Subject: [PATCH 1/4] compact _eglContext check --- MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index 272c249115a..8f307d0ba3a 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -475,9 +475,7 @@ protected void CreateGLContext() break; } - if (_eglContext == EGL10.EglNoContext) - _eglContext = null; - + if (_eglContext == EGL10.EglNoContext) _eglContext = null; if (_eglContext == null) throw new Exception("Could not create EGL context" + GL.GetEglErrorAsString()); From 6d6e7cd20f67fd81a870d548596908ce78e258d7 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Tue, 21 May 2024 10:34:04 +0300 Subject: [PATCH 2/4] set _eglConfig --- MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index 8f307d0ba3a..c2e8d61ae3c 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -458,12 +458,13 @@ protected void CreateGLContext() if (!found || numConfigs[0] <= 0) throw new Exception("No valid EGL configs found" + GL.GetEglErrorAsString()); + _eglConfig = results[0]; foreach (GLESVersion ver in ((OGL_DROID)OGL.Current).GetSupportedGLESVersions()) { Log.Verbose("AndroidGameView", "Creating GLES {0} Context", ver); - _eglContext = GL.Egl.EglCreateContext(adapter.EglDisplay, results[0], EGL10.EglNoContext, ver.GetAttributes()); + _eglContext = GL.Egl.EglCreateContext(adapter.EglDisplay, _eglConfig, EGL10.EglNoContext, ver.GetAttributes()); if (_eglContext == null || _eglContext == EGL10.EglNoContext) { @@ -480,7 +481,6 @@ protected void CreateGLContext() throw new Exception("Could not create EGL context" + GL.GetEglErrorAsString()); Log.Verbose("AndroidGameView", "Created GLES {0} Context", _glesVersion); - _eglConfig = results[0]; } protected EGLSurface CreatePBufferSurface(EGLConfig config, int[] attribList) From e3619f2b67b55b1a04b8268ccde1dcab61a5f8e7 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Tue, 21 May 2024 10:37:25 +0300 Subject: [PATCH 3/4] extract ChooseGLConfig() --- .../Platform/Android/AndroidSurfaceView.cs | 10 +++++++++- .../Platform/Cardboard/AndroidSurfaceView.cs | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index c2e8d61ae3c..b5db27e5517 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -272,6 +272,8 @@ void ProcessStateResumed() // create context if not available if (_eglContext == null) { + ChooseGLConfig(); + CreateGLContext(); if (_eglSurface == null) @@ -382,7 +384,7 @@ protected override void Dispose(bool disposing) base.Dispose(disposing); } - protected void CreateGLContext() + protected void ChooseGLConfig() { var adapter = ((IPlatformGraphicsAdapter)GraphicsAdapter.DefaultAdapter).Strategy.ToConcrete(); var GL = adapter.Ogl; @@ -459,6 +461,12 @@ protected void CreateGLContext() if (!found || numConfigs[0] <= 0) throw new Exception("No valid EGL configs found" + GL.GetEglErrorAsString()); _eglConfig = results[0]; + } + + protected void CreateGLContext() + { + var adapter = ((IPlatformGraphicsAdapter)GraphicsAdapter.DefaultAdapter).Strategy.ToConcrete(); + var GL = adapter.Ogl; foreach (GLESVersion ver in ((OGL_DROID)OGL.Current).GetSupportedGLESVersions()) { diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 33bc34378eb..3f2e2f78b29 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -217,6 +217,8 @@ void ProcessStateResumed() // create context if not available if (_eglContext == null) { + //ChooseGLConfig(); + //CreateGLContext(); if (_eglSurface == null) From e01283b855d897c29bf62f63779118ea17489920 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Tue, 21 May 2024 10:50:26 +0300 Subject: [PATCH 4/4] move ChooseGLConfig() --- MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs | 7 +++++-- .../Platform/Cardboard/AndroidSurfaceView.cs | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index b5db27e5517..16d15ac893c 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -269,11 +269,14 @@ void ProcessStateResumed() _isGLContextLost = false; } - // create context if not available - if (_eglContext == null) + if (_eglConfig == null) { ChooseGLConfig(); + } + // create context if not available + if (_eglContext == null) + { CreateGLContext(); if (_eglSurface == null) diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 3f2e2f78b29..ed11411efa1 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -214,11 +214,14 @@ void ProcessStateResumed() _isGLContextLost = false; } - // create context if not available - if (_eglContext == null) + if (_eglConfig == null) { //ChooseGLConfig(); + } + // create context if not available + if (_eglContext == null) + { //CreateGLContext(); if (_eglSurface == null)