Skip to content

Commit

Permalink
move SurfaceConfig struct (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast authored May 20, 2024
1 parent b853547 commit 7d23c1b
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void InitConfigs()
Log.Verbose("AndroidGameView", "Device Supports");
foreach (EGLConfig eglConfig in _eglConfigs)
{
Log.Verbose("AndroidGameView", string.Format(" {0}", AndroidSurfaceView.SurfaceConfig.FromEGLConfig(eglConfig, _ogl.Egl, _eglDisplay)));
Log.Verbose("AndroidGameView", string.Format(" {0}", SurfaceConfig.FromEGLConfig(eglConfig, _ogl.Egl, _eglDisplay)));
}

}
Expand Down
103 changes: 103 additions & 0 deletions MonoGame.Framework/Graphics/.GL.Android/SurfaceConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.

// Copyright (C)2024 Nick Kastellanos

using System;
using System.Collections.Generic;
using Javax.Microedition.Khronos.Egl;

namespace Microsoft.Xna.Platform.Graphics
{
internal struct SurfaceConfig
{
public int Red;
public int Green;
public int Blue;
public int Alpha;

public int Depth;
public int Stencil;

public int SampleBuffers;
public int Samples;

public int[] ToConfigAttribs()
{
List<int> attribs = new List<int>();
if (Red != 0)
{
attribs.Add(EGL11.EglRedSize);
attribs.Add(Red);
}
if (Green != 0)
{
attribs.Add(EGL11.EglGreenSize);
attribs.Add(Green);
}
if (Blue != 0)
{
attribs.Add(EGL11.EglBlueSize);
attribs.Add(Blue);
}
if (Alpha != 0)
{
attribs.Add(EGL11.EglAlphaSize);
attribs.Add(Alpha);
}
if (Depth != 0)
{
attribs.Add(EGL11.EglDepthSize);
attribs.Add(Depth);
}
if (Stencil != 0)
{
attribs.Add(EGL11.EglStencilSize);
attribs.Add(Stencil);
}
if (SampleBuffers != 0)
{
attribs.Add(EGL11.EglSampleBuffers);
attribs.Add(SampleBuffers);
}
if (Samples != 0)
{
attribs.Add(EGL11.EglSamples);
attribs.Add(Samples);
}
attribs.Add(EGL11.EglRenderableType);
attribs.Add(4);
attribs.Add(EGL11.EglNone);

return attribs.ToArray();
}

static int GetAttribute(EGLConfig config, IEGL10 egl, EGLDisplay eglDisplay,int attribute)
{
int[] data = new int[1];
egl.EglGetConfigAttrib(eglDisplay, config, attribute, data);
return data[0];
}

public static SurfaceConfig FromEGLConfig(EGLConfig config, IEGL10 egl, EGLDisplay eglDisplay)
{
return new SurfaceConfig()
{
Red = GetAttribute(config, egl, eglDisplay, EGL11.EglRedSize),
Green = GetAttribute(config, egl, eglDisplay, EGL11.EglGreenSize),
Blue = GetAttribute(config, egl, eglDisplay, EGL11.EglBlueSize),
Alpha = GetAttribute(config, egl, eglDisplay, EGL11.EglAlphaSize),
Depth = GetAttribute(config, egl, eglDisplay, EGL11.EglDepthSize),
Stencil = GetAttribute(config, egl, eglDisplay, EGL11.EglStencilSize),
SampleBuffers = GetAttribute(config, egl, eglDisplay, EGL11.EglSampleBuffers),
Samples = GetAttribute(config, egl, eglDisplay, EGL11.EglSamples)
};
}

public override string ToString()
{
return string.Format("Red:{0} Green:{1} Blue:{2} Alpha:{3} Depth:{4} Stencil:{5} SampleBuffers:{6} Samples:{7}", Red, Green, Blue, Alpha, Depth, Stencil, SampleBuffers, Samples);
}
}
}
1 change: 1 addition & 0 deletions MonoGame.Framework/MonoGame.Framework.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="Graphics\.GL.Android\ConcreteGraphicsContext.Android.cs" />
<Compile Include="Graphics\.GL.Android\ConcreteGraphicsDevice.Android.cs" />
<Compile Include="Graphics\.GL.Android\OpenGL.Android.cs" />
<Compile Include="Graphics\.GL.Android\SurfaceConfig.cs" />
<Compile Include="Graphics\.GL\OpenGL.Common.cs" />
<Compile Include="Graphics\.Common\SpriteBatcher.cs" />
</ItemGroup>
Expand Down
89 changes: 0 additions & 89 deletions MonoGame.Framework/Platform/Android/AndroidSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,95 +355,6 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

internal struct SurfaceConfig
{
public int Red;
public int Green;
public int Blue;
public int Alpha;
public int Depth;
public int Stencil;
public int SampleBuffers;
public int Samples;

public int[] ToConfigAttribs()
{
List<int> attribs = new List<int>();
if (Red != 0)
{
attribs.Add(EGL11.EglRedSize);
attribs.Add(Red);
}
if (Green != 0)
{
attribs.Add(EGL11.EglGreenSize);
attribs.Add(Green);
}
if (Blue != 0)
{
attribs.Add(EGL11.EglBlueSize);
attribs.Add(Blue);
}
if (Alpha != 0)
{
attribs.Add(EGL11.EglAlphaSize);
attribs.Add(Alpha);
}
if (Depth != 0)
{
attribs.Add(EGL11.EglDepthSize);
attribs.Add(Depth);
}
if (Stencil != 0)
{
attribs.Add(EGL11.EglStencilSize);
attribs.Add(Stencil);
}
if (SampleBuffers != 0)
{
attribs.Add(EGL11.EglSampleBuffers);
attribs.Add(SampleBuffers);
}
if (Samples != 0)
{
attribs.Add(EGL11.EglSamples);
attribs.Add(Samples);
}
attribs.Add(EGL11.EglRenderableType);
attribs.Add(4);
attribs.Add(EGL11.EglNone);

return attribs.ToArray();
}

static int GetAttribute(EGLConfig config, IEGL10 egl, EGLDisplay eglDisplay,int attribute)
{
int[] data = new int[1];
egl.EglGetConfigAttrib(eglDisplay, config, attribute, data);
return data[0];
}

public static SurfaceConfig FromEGLConfig(EGLConfig config, IEGL10 egl, EGLDisplay eglDisplay)
{
return new SurfaceConfig()
{
Red = GetAttribute(config, egl, eglDisplay, EGL11.EglRedSize),
Green = GetAttribute(config, egl, eglDisplay, EGL11.EglGreenSize),
Blue = GetAttribute(config, egl, eglDisplay, EGL11.EglBlueSize),
Alpha = GetAttribute(config, egl, eglDisplay, EGL11.EglAlphaSize),
Depth = GetAttribute(config, egl, eglDisplay, EGL11.EglDepthSize),
Stencil = GetAttribute(config, egl, eglDisplay, EGL11.EglStencilSize),
SampleBuffers = GetAttribute(config, egl, eglDisplay, EGL11.EglSampleBuffers),
Samples = GetAttribute(config, egl, eglDisplay, EGL11.EglSamples)
};
}

public override string ToString()
{
return string.Format("Red:{0} Green:{1} Blue:{2} Alpha:{3} Depth:{4} Stencil:{5} SampleBuffers:{6} Samples:{7}", Red, Green, Blue, Alpha, Depth, Stencil, SampleBuffers, Samples);
}
}

protected void CreateGLContext()
{
var adapter = ((IPlatformGraphicsAdapter)GraphicsAdapter.DefaultAdapter).Strategy.ToConcrete<ConcreteGraphicsAdapter>();
Expand Down
89 changes: 0 additions & 89 deletions MonoGame.Framework/Platform/Cardboard/AndroidSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,95 +302,6 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

internal struct SurfaceConfig
{
public int Red;
public int Green;
public int Blue;
public int Alpha;
public int Depth;
public int Stencil;
public int SampleBuffers;
public int Samples;

public int[] ToConfigAttribs()
{
List<int> attribs = new List<int>();
if (Red != 0)
{
attribs.Add(EGL11.EglRedSize);
attribs.Add(Red);
}
if (Green != 0)
{
attribs.Add(EGL11.EglGreenSize);
attribs.Add(Green);
}
if (Blue != 0)
{
attribs.Add(EGL11.EglBlueSize);
attribs.Add(Blue);
}
if (Alpha != 0)
{
attribs.Add(EGL11.EglAlphaSize);
attribs.Add(Alpha);
}
if (Depth != 0)
{
attribs.Add(EGL11.EglDepthSize);
attribs.Add(Depth);
}
if (Stencil != 0)
{
attribs.Add(EGL11.EglStencilSize);
attribs.Add(Stencil);
}
if (SampleBuffers != 0)
{
attribs.Add(EGL11.EglSampleBuffers);
attribs.Add(SampleBuffers);
}
if (Samples != 0)
{
attribs.Add(EGL11.EglSamples);
attribs.Add(Samples);
}
attribs.Add(EGL11.EglRenderableType);
attribs.Add(4);
attribs.Add(EGL11.EglNone);

return attribs.ToArray();
}

static int GetAttribute(EGLConfig config, IEGL10 egl, EGLDisplay eglDisplay,int attribute)
{
int[] data = new int[1];
egl.EglGetConfigAttrib(eglDisplay, config, attribute, data);
return data[0];
}

public static SurfaceConfig FromEGLConfig(EGLConfig config, IEGL10 egl, EGLDisplay eglDisplay)
{
return new SurfaceConfig()
{
Red = GetAttribute(config, egl, eglDisplay, EGL11.EglRedSize),
Green = GetAttribute(config, egl, eglDisplay, EGL11.EglGreenSize),
Blue = GetAttribute(config, egl, eglDisplay, EGL11.EglBlueSize),
Alpha = GetAttribute(config, egl, eglDisplay, EGL11.EglAlphaSize),
Depth = GetAttribute(config, egl, eglDisplay, EGL11.EglDepthSize),
Stencil = GetAttribute(config, egl, eglDisplay, EGL11.EglStencilSize),
SampleBuffers = GetAttribute(config, egl, eglDisplay, EGL11.EglSampleBuffers),
Samples = GetAttribute(config, egl, eglDisplay, EGL11.EglSamples)
};
}

public override string ToString()
{
return string.Format("Red:{0} Green:{1} Blue:{2} Alpha:{3} Depth:{4} Stencil:{5} SampleBuffers:{6} Samples:{7}", Red, Green, Blue, Alpha, Depth, Stencil, SampleBuffers, Samples);
}
}

protected void CreateGLSurface()
{
try
Expand Down
1 change: 1 addition & 0 deletions MonoGame.Framework/XNA.Framework.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="Graphics\.GL.Android\ConcreteGraphicsContext.Android.cs" />
<Compile Include="Graphics\.GL.Android\ConcreteGraphicsDevice.Android.cs" />
<Compile Include="Graphics\.GL.Android\OpenGL.Android.cs" />
<Compile Include="Graphics\.GL.Android\SurfaceConfig.cs" />
<Compile Include="Graphics\.GL\OpenGL.Common.cs" />
<Compile Include="Graphics\.Common\SpriteBatcher.cs" />

Expand Down
1 change: 1 addition & 0 deletions MonoGame.Framework/XNA.Framework.Cardboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="Graphics\.GL.Android\ConcreteGraphicsContext.Android.cs" />
<Compile Include="Graphics\.GL.Android\ConcreteGraphicsDevice.Android.cs" />
<Compile Include="Graphics\.GL.Android\OpenGL.Android.cs" />
<Compile Include="Graphics\.GL.Android\SurfaceConfig.cs" />
<Compile Include="Graphics\.GL\OpenGL.Common.cs" />
<Compile Include="Graphics\.Common\SpriteBatcher.cs" />

Expand Down

0 comments on commit 7d23c1b

Please sign in to comment.