diff --git a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs index 89c5f39ecdf..e5e19293a75 100644 --- a/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs @@ -47,7 +47,6 @@ enum AppState volatile bool _forceRecreateSurface = false; bool _androidSurfaceAvailable = false; - bool _glSurfaceAvailable; bool _lostglContext; DateTime _prevTickTime; @@ -178,15 +177,11 @@ void Java.Lang.IRunnable.Run() { _isCancellationRequested = null; - if (_glSurfaceAvailable) + if (_eglSurface != null) { - if (_eglSurface != null && _eglSurface != EGL10.EglNoSurface) - { - ClearCurrentContext(); - DestroyGLSurface(); - } + ClearCurrentContext(); + DestroyGLSurface(); _eglSurface = null; - _glSurfaceAvailable = false; } if (_eglContext != null) @@ -258,7 +253,7 @@ void processStateResuming() { try { - if (!_glSurfaceAvailable) + if (_eglSurface == null) CreateGLSurface(); } catch (Exception ex) @@ -298,7 +293,7 @@ void processStateResuming() CreateGLContext(); - if (!_glSurfaceAvailable) + if (_eglSurface == null) CreateGLSurface(); // OGL.InitExtensions() must be called while we have a gl context. @@ -317,7 +312,7 @@ void processStateResuming() } // finish state if surface created, may take a frame or two until the android UI thread callbacks fire - if (_glSurfaceAvailable) + if (_eglSurface != null) { // must resume openAL device here Microsoft.Xna.Platform.Audio.AudioService.Resume(); @@ -334,13 +329,9 @@ void ForceSurfaceRecreation() // needed at app start if (_eglContext != null && _androidSurfaceAvailable) { - if (_eglSurface != null && _eglSurface != EGL10.EglNoSurface) - { - ClearCurrentContext(); - DestroyGLSurface(); - } + ClearCurrentContext(); + DestroyGLSurface(); _eglSurface = null; - _glSurfaceAvailable = false; CreateGLSurface(); @@ -390,16 +381,12 @@ void processStateRunning() void processStatePausing() { - if (_glSurfaceAvailable) + // Surface we are using needs to go away + if (_eglSurface != null) { - // Surface we are using needs to go away - if (_eglSurface != null && _eglSurface != EGL10.EglNoSurface) - { - ClearCurrentContext(); - DestroyGLSurface(); - } + ClearCurrentContext(); + DestroyGLSurface(); _eglSurface = null; - _glSurfaceAvailable = false; } // must pause openAL device here @@ -479,7 +466,7 @@ private void DestroyGLDisplay() protected void DestroyGLSurface() { - System.Diagnostics.Debug.Assert(_eglSurface != null && _eglSurface != EGL10.EglNoSurface); + System.Diagnostics.Debug.Assert(_eglSurface != null); if (!_egl.EglDestroySurface(_eglDisplay, _eglSurface)) Log.Verbose("AndroidGameView", "Could not destroy EGL surface" + GetErrorAsString()); @@ -742,28 +729,27 @@ private string GetErrorAsString() protected void CreateGLSurface() { - System.Diagnostics.Debug.Assert(_glSurfaceAvailable == false); - try { // If there is an existing surface, destroy the old one - if (_eglSurface != null && _eglSurface != EGL10.EglNoSurface) + if (_eglSurface != null) { ClearCurrentContext(); DestroyGLSurface(); } _eglSurface = null; - _glSurfaceAvailable = false; _eglSurface = _egl.EglCreateWindowSurface(_eglDisplay, _eglConfig, (Java.Lang.Object)this.Holder, null); - if (_eglSurface == null || _eglSurface == EGL10.EglNoSurface) + + if (_eglSurface == EGL10.EglNoSurface) + _eglSurface = null; + + if (_eglSurface == null) throw new Exception("Could not create EGL window surface" + GetErrorAsString()); if (!_egl.EglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext)) throw new Exception("Could not make EGL current" + GetErrorAsString()); - _glSurfaceAvailable = true; - // Must set viewport after creation, the viewport has correct values in it already as we call it, but // the surface is created after the correct viewport is already applied so we must do it again. GraphicsDeviceManager gdm = ((IPlatformGame)_game).GetStrategy().GraphicsDeviceManager; @@ -777,7 +763,7 @@ protected void CreateGLSurface() } catch (Exception ex) { - _glSurfaceAvailable = false; + _eglSurface = null; Log.Error("AndroidGameView", ex.ToString()); } } diff --git a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs index 1e9daa034c0..ffc9c15dd1d 100644 --- a/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs +++ b/MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs @@ -46,7 +46,6 @@ enum AppState volatile bool _forceRecreateSurface = false; bool _androidSurfaceAvailable = false; - bool _glSurfaceAvailable; bool _lostglContext; DateTime _prevTickTime; @@ -210,7 +209,7 @@ void processStateResuming() { try { - if (!_glSurfaceAvailable) + if (_eglSurface == null) CreateGLSurface(); } catch (Exception ex) @@ -250,7 +249,7 @@ void processStateResuming() //CreateGLContext(); - if (!_glSurfaceAvailable) + if (_eglSurface == null) CreateGLSurface(); // OGL.InitExtensions() must be called while we have a gl context. @@ -269,7 +268,7 @@ void processStateResuming() } // finish state if surface created, may take a frame or two until the android UI thread callbacks fire - if (_glSurfaceAvailable) + if (_eglSurface != null) { // must resume openAL device here Microsoft.Xna.Platform.Audio.AudioService.Resume(); @@ -286,13 +285,9 @@ void ForceSurfaceRecreation() // needed at app start if (_eglContext != null && _androidSurfaceAvailable) { - if (_eglSurface != null && _eglSurface != EGL10.EglNoSurface) - { - ClearCurrentContext(); - DestroyGLSurface(); - } + ClearCurrentContext(); + DestroyGLSurface(); _eglSurface = null; - _glSurfaceAvailable = false; CreateGLSurface(); @@ -342,16 +337,12 @@ void processStateRunning() void processStatePausing() { - if (_glSurfaceAvailable) + // Surface we are using needs to go away + if (_eglSurface != null) { - // Surface we are using needs to go away - if (_eglSurface != null && _eglSurface != EGL10.EglNoSurface) - { - ClearCurrentContext(); - DestroyGLSurface(); - } + ClearCurrentContext(); + DestroyGLSurface(); _eglSurface = null; - _glSurfaceAvailable = false; } // must pause openAL device here @@ -430,7 +421,7 @@ private void DestroyGLDisplay() protected void DestroyGLSurface() { - System.Diagnostics.Debug.Assert(_eglSurface != null && _eglSurface != EGL10.EglNoSurface); + System.Diagnostics.Debug.Assert(_eglSurface != null); if (!_egl.EglDestroySurface(_eglDisplay, _eglSurface)) Log.Verbose("AndroidGameView", "Could not destroy EGL surface" + GetErrorAsString()); @@ -567,30 +558,29 @@ private string GetErrorAsString() protected void CreateGLSurface() { - System.Diagnostics.Debug.Assert(_glSurfaceAvailable == false); - try { // If there is an existing surface, destroy the old one - if (_eglSurface != null && _eglSurface != EGL10.EglNoSurface) + if (_eglSurface != null) { ClearCurrentContext(); DestroyGLSurface(); } _eglSurface = null; - _glSurfaceAvailable = false; /* Cardboard: Surface was created by GLSurfaceView. _eglSurface = _egl.EglCreateWindowSurface(_eglDisplay, _eglConfig, (Java.Lang.Object)this.Holder, null); - if (_eglSurface == null || _eglSurface == EGL10.EglNoSurface) + + if (_eglSurface == EGL10.EglNoSurface) + _eglSurface = null; + + if (_eglSurface == null) throw new Exception("Could not create EGL window surface" + GetErrorAsString()); if (!_egl.EglMakeCurrent(_eglDisplay, _eglSurface, _eglSurface, _eglContext)) throw new Exception("Could not make EGL current" + GetErrorAsString()); */ - _glSurfaceAvailable = true; - // Must set viewport after creation, the viewport has correct values in it already as we call it, but // the surface is created after the correct viewport is already applied so we must do it again. GraphicsDeviceManager gdm = ((IPlatformGame)_game).GetStrategy().GraphicsDeviceManager; @@ -604,7 +594,7 @@ protected void CreateGLSurface() } catch (Exception ex) { - _glSurfaceAvailable = false; + _eglSurface = null; Log.Error("AndroidGameView", ex.ToString()); } }