Skip to content

Commit

Permalink
extract ChooseGLConfig (#1592)
Browse files Browse the repository at this point in the history
* compact _eglContext check

* set _eglConfig

* extract ChooseGLConfig()

* move ChooseGLConfig()
  • Loading branch information
nkast authored May 21, 2024
1 parent 63eb7aa commit 492bac9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
21 changes: 15 additions & 6 deletions MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ void ProcessStateResumed()
_isGLContextLost = false;
}

if (_eglConfig == null)
{
ChooseGLConfig();
}

// create context if not available
if (_eglContext == null)
{
Expand Down Expand Up @@ -382,7 +387,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

protected void CreateGLContext()
protected void ChooseGLConfig()
{
var adapter = ((IPlatformGraphicsAdapter)GraphicsAdapter.DefaultAdapter).Strategy.ToConcrete<ConcreteGraphicsAdapter>();
var GL = adapter.Ogl;
Expand Down Expand Up @@ -458,12 +463,19 @@ 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<ConcreteGraphicsAdapter>();
var GL = adapter.Ogl;

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)
{
Expand All @@ -475,14 +487,11 @@ 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());

Log.Verbose("AndroidGameView", "Created GLES {0} Context", _glesVersion);
_eglConfig = results[0];
}

protected EGLSurface CreatePBufferSurface(EGLConfig config, int[] attribList)
Expand Down
5 changes: 5 additions & 0 deletions MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ void ProcessStateResumed()
_isGLContextLost = false;
}

if (_eglConfig == null)
{
//ChooseGLConfig();
}

// create context if not available
if (_eglContext == null)
{
Expand Down

0 comments on commit 492bac9

Please sign in to comment.