From 84788751447bb681489f6839a24112725ed3eba7 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Sat, 18 May 2024 13:00:05 +0300 Subject: [PATCH 1/5] remove unnecessary code --- .../Platform/Android/AndroidSurfaceView.cs | 11 ----------- .../Platform/Cardboard/AndroidSurfaceView.cs | 11 ----------- 2 files changed, 22 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index bc53e5d2735..b001f48e28f 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -236,17 +236,6 @@ void processStateResumed() // do not run game if surface is not available if (_isAndroidSurfaceAvailable) { - // create surface if context is available - if (_eglContext != null && !_isGLContextLost) - { - if (_eglSurface == null) - { - CreateGLSurface(); - BindGLSurfaceGLContext(); - GdmResetClientBounds(); - } - } - // Restart due to context loss bool contextLost = false; if (_isGLContextLost) diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 936f0a37d1a..5554f9c3e27 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -187,17 +187,6 @@ void processStateResumed() // do not run game if surface is not available if (_isAndroidSurfaceAvailable) { - // create surface if context is available - if (_eglContext != null && !_isGLContextLost) - { - if (_eglSurface == null) - { - CreateGLSurface(); - BindGLSurfaceGLContext(); - GdmResetClientBounds(); - } - } - // Restart due to context loss bool contextLost = false; if (_isGLContextLost) From 7af6610f241d13e9041ad05c3f04ae74700c959c Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Sat, 18 May 2024 13:00:36 +0300 Subject: [PATCH 2/5] rename ProcessStateResumed() --- MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs | 4 ++-- MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index b001f48e28f..4a979873c44 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -214,7 +214,7 @@ void RunStep() switch (_appState) { case AppState.Resumed: - processStateResumed(); + ProcessStateResumed(); break; case AppState.Paused: @@ -231,7 +231,7 @@ void RunStep() return; } - void processStateResumed() + void ProcessStateResumed() { // do not run game if surface is not available if (_isAndroidSurfaceAvailable) diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 5554f9c3e27..541895b28a6 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -165,7 +165,7 @@ void RunStep() switch (_appState) { case AppState.Resumed: - processStateResumed(); + ProcessStateResumed(); break; case AppState.Paused: @@ -182,7 +182,7 @@ void RunStep() return; } - void processStateResumed() + void ProcessStateResumed() { // do not run game if surface is not available if (_isAndroidSurfaceAvailable) From 8d01b3de2ff272ff048d16fd07d5413e147eda0b Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Sat, 18 May 2024 13:06:22 +0300 Subject: [PATCH 3/5] simplify ifs --- MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs | 4 +++- MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index 4a979873c44..3548c209512 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -275,6 +275,7 @@ void ProcessStateResumed() if (_eglSurface == null) { CreateGLSurface(); + System.Diagnostics.Debug.Assert(_eglContext != null); BindGLSurfaceGLContext(); GdmResetClientBounds(); } @@ -292,9 +293,10 @@ void ProcessStateResumed() } } - if (_eglContext != null && _eglSurface == null) + if (_eglSurface == null) { CreateGLSurface(); + System.Diagnostics.Debug.Assert(_eglContext != null); BindGLSurfaceGLContext(); GdmResetClientBounds(); } diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 541895b28a6..556b4189db9 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -226,6 +226,7 @@ void ProcessStateResumed() if (_eglSurface == null) { CreateGLSurface(); + System.Diagnostics.Debug.Assert(_eglContext != null); BindGLSurfaceGLContext(); GdmResetClientBounds(); } @@ -243,9 +244,10 @@ void ProcessStateResumed() } } - if (_eglContext != null && _eglSurface == null) + if (_eglSurface == null) { CreateGLSurface(); + System.Diagnostics.Debug.Assert(_eglContext != null); BindGLSurfaceGLContext(); GdmResetClientBounds(); } From a7dd4b1bd29db9a15bee8e6e19673ec306431e23 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Sat, 18 May 2024 13:12:46 +0300 Subject: [PATCH 4/5] replace MakeCurrentContext --- .../Platform/Android/AndroidSurfaceView.cs | 14 +++----------- .../Platform/Cardboard/AndroidSurfaceView.cs | 17 +++-------------- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index 3548c209512..025198036f9 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -119,12 +119,6 @@ internal void SwapBuffers() } } - private void MakeCurrentContext() - { - if (!_egl.EglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext)) - System.Diagnostics.Debug.WriteLine("Error Make Current" + GetErrorAsString()); - } - internal void StartGameLoop() { _isCancellationRequested = false; @@ -276,7 +270,7 @@ void ProcessStateResumed() { CreateGLSurface(); System.Diagnostics.Debug.Assert(_eglContext != null); - BindGLSurfaceGLContext(); + MakeCurrentGLContext(); GdmResetClientBounds(); } @@ -297,7 +291,7 @@ void ProcessStateResumed() { CreateGLSurface(); System.Diagnostics.Debug.Assert(_eglContext != null); - BindGLSurfaceGLContext(); + MakeCurrentGLContext(); GdmResetClientBounds(); } @@ -313,8 +307,6 @@ void ProcessStateResumed() try { - this.MakeCurrentContext(); - var handler = Tick; if (handler != null) handler(this, EventArgs.Empty); @@ -631,7 +623,7 @@ protected void CreateGLSurface() } } - private void BindGLSurfaceGLContext() + private void MakeCurrentGLContext() { try { diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 556b4189db9..8e415a175b8 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -121,15 +121,6 @@ internal void SwapBuffers() // see: OnFinishFrame. } - private void MakeCurrentContext() - { - // Surface & GL Context was created by GLSurfaceView. - return; - - if (!_egl.EglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext)) - System.Diagnostics.Debug.WriteLine("Error Make Current" + GetErrorAsString()); - } - internal void StartGameLoop() { // Cardboard: @@ -227,7 +218,7 @@ void ProcessStateResumed() { CreateGLSurface(); System.Diagnostics.Debug.Assert(_eglContext != null); - BindGLSurfaceGLContext(); + MakeCurrentGLContext(); GdmResetClientBounds(); } @@ -248,7 +239,7 @@ void ProcessStateResumed() { CreateGLSurface(); System.Diagnostics.Debug.Assert(_eglContext != null); - BindGLSurfaceGLContext(); + MakeCurrentGLContext(); GdmResetClientBounds(); } @@ -264,8 +255,6 @@ void ProcessStateResumed() try { - this.MakeCurrentContext(); - var handler = Tick; if (handler != null) handler(this, EventArgs.Empty); @@ -459,7 +448,7 @@ protected void CreateGLSurface() } } - private void BindGLSurfaceGLContext() + private void MakeCurrentGLContext() { try { From 61cd177c88f2c5fac711fad2941b019619953577 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Sat, 18 May 2024 13:17:22 +0300 Subject: [PATCH 5/5] move _eglDisplay --- MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs | 4 ++-- MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index 025198036f9..4a27d1f109b 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -726,9 +726,9 @@ public override bool OnGenericMotionEvent(MotionEvent e) #region Properties private IEGL10 _egl; + private EGLDisplay _eglDisplay; private GLESVersion _glesVersion; private EGLConfig _eglConfig; - private EGLDisplay _eglDisplay; private EGLContext _eglContext; private EGLSurface _eglSurface; @@ -737,9 +737,9 @@ public override bool OnGenericMotionEvent(MotionEvent e) #region ISurfaceView IEGL10 ISurfaceView.Egl { get { return _egl; } } + EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } } GLESVersion ISurfaceView.GLesVersion { get { return _glesVersion; } } EGLConfig ISurfaceView.EglConfig { get { return _eglConfig; } } - EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } } EGLContext ISurfaceView.EglContext { get { return _eglContext; } } #endregion diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 8e415a175b8..30b100b280d 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -553,9 +553,9 @@ public override bool OnGenericMotionEvent(MotionEvent e) #region Properties private IEGL10 _egl; + private EGLDisplay _eglDisplay; private GLESVersion _glesVersion; private EGLConfig _eglConfig; - private EGLDisplay _eglDisplay; private EGLContext _eglContext; private EGLSurface _eglSurface; @@ -564,9 +564,9 @@ public override bool OnGenericMotionEvent(MotionEvent e) #region ISurfaceView IEGL10 ISurfaceView.Egl { get { return _egl; } } + EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } } GLESVersion ISurfaceView.GLesVersion { get { return _glesVersion; } } EGLConfig ISurfaceView.EglConfig { get { return _eglConfig; } } - EGLDisplay ISurfaceView.EglDisplay { get { return _eglDisplay; } } EGLContext ISurfaceView.EglContext { get { return _eglContext; } } #endregion