Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract ChooseGLConfig #1592

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading