Skip to content

Commit

Permalink
initialize _eglConfigs in GraphicsAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast committed May 19, 2024
1 parent 4ea4bc0 commit 12142b9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
24 changes: 24 additions & 0 deletions MonoGame.Framework/Graphics/.GL.Android/ConcreteGraphicsAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Xna.Platform.Graphics.OpenGL;
using GetParamName = Microsoft.Xna.Platform.Graphics.OpenGL.GetPName;
using Javax.Microedition.Khronos.Egl;
using Android.Util;


namespace Microsoft.Xna.Platform.Graphics
Expand Down Expand Up @@ -115,9 +116,12 @@ public override GraphicsBackend Backend

OGL_DROID _ogl;
EGLDisplay _eglDisplay;
EGLConfig[] _eglConfigs;

internal OGL_DROID Ogl { get { return _ogl; } }
internal EGLDisplay EglDisplay { get { return _eglDisplay; } }
internal EGLConfig[] EglConfig { get { return _eglConfigs; } }


internal ConcreteGraphicsAdapter()
{
Expand All @@ -137,6 +141,9 @@ internal ConcreteGraphicsAdapter()
if (!_ogl.Egl.EglInitialize(_eglDisplay, version))
throw new Exception("Could not initialize EGL display" + _ogl.GetEglErrorAsString());
#endif

InitConfigs();

}

~ConcreteGraphicsAdapter()
Expand All @@ -152,6 +159,23 @@ internal ConcreteGraphicsAdapter()
#endif
}

private void InitConfigs()
{
int[] numConfigs = new int[1];
if (!_ogl.Egl.EglGetConfigs(_eglDisplay, null, 0, numConfigs))
throw new Exception("Could not get config count. " + _ogl.GetEglErrorAsString());

_eglConfigs = new EGLConfig[numConfigs[0]];
_ogl.Egl.EglGetConfigs(_eglDisplay, _eglConfigs, numConfigs[0], numConfigs);

Log.Verbose("AndroidGameView", "Device Supports");
foreach (EGLConfig eglConfig in _eglConfigs)
{
Log.Verbose("AndroidGameView", string.Format(" {0}", AndroidSurfaceView.SurfaceConfig.FromEGLConfig(eglConfig, _ogl.Egl, _eglDisplay)));
}

}

public override bool Platform_IsProfileSupported(GraphicsProfile graphicsProfile)
{
if (GraphicsAdapter.UseReferenceDevice)
Expand Down
16 changes: 1 addition & 15 deletions MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,24 +500,10 @@ protected void CreateGLContext()
surfaceConfigs.Add(new SurfaceConfig() { Red = 5, Green = 6, Blue = 5 });
}
surfaceConfigs.Add(new SurfaceConfig() { Red = 4, Green = 4, Blue = 4 });
int[] numConfigs = new int[1];
EGLConfig[] results = new EGLConfig[1];

if (!GL.Egl.EglGetConfigs(adapter.EglDisplay, null, 0, numConfigs))
{
throw new Exception("Could not get config count. " + GL.GetEglErrorAsString());
}

EGLConfig[] eglConfigs = new EGLConfig[numConfigs[0]];
GL.Egl.EglGetConfigs(adapter.EglDisplay, eglConfigs, numConfigs[0], numConfigs);
Log.Verbose("AndroidGameView", "Device Supports");
foreach (EGLConfig eglConfig in eglConfigs)
{
Log.Verbose("AndroidGameView", string.Format(" {0}", SurfaceConfig.FromEGLConfig(eglConfig, GL.Egl, adapter.EglDisplay)));
}

bool found = false;
numConfigs[0] = 0;
int[] numConfigs = new int[] { 0 };
foreach (SurfaceConfig surfaceConfig in surfaceConfigs)
{
Log.Verbose("AndroidGameView", string.Format("Checking Config : {0}", surfaceConfig));
Expand Down

0 comments on commit 12142b9

Please sign in to comment.