Skip to content

Commit

Permalink
refactor GL graphics (#2164)
Browse files Browse the repository at this point in the history
* whitespaces

* refactor DrawElementsBaseVertex

* clean up ConcreteSamplerState
  • Loading branch information
nkast authored Jan 1, 2025
1 parent 5735ab5 commit 2af773b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Platforms/Graphics/.GL/ConcreteGraphicsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public override void PlatformSetup()
this._newEnabledVertexAttributes = new bool[base.Capabilities.MaxVertexBufferSlots];

if (((ConcreteGraphicsCapabilities)base.Capabilities).SupportsFramebufferObjectARB
|| ((ConcreteGraphicsCapabilities)base.Capabilities).SupportsFramebufferObjectEXT)
|| ((ConcreteGraphicsCapabilities)base.Capabilities).SupportsFramebufferObjectEXT)
{
this._supportsBlitFramebuffer = GL.BlitFramebuffer != null;
this._supportsInvalidateFramebuffer = GL.InvalidateFramebuffer != null;
Expand Down
9 changes: 7 additions & 2 deletions Platforms/Graphics/.GL/OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1492,8 +1492,13 @@ private void LoadEntryPoints()
DrawElements = LoadFunctionOrNull<DrawElementsDelegate>("glDrawElements");
DrawArrays = LoadFunctionOrNull<DrawArraysDelegate>("glDrawArrays");

// OpenGL >= 2.0, GLES >= 3.0
DrawRangeElements = LoadFunctionOrNull<DrawRangeElementsDelegate>("glDrawRangeElements");

// OpenGL >= 3.2, GLES >= 3.2 or GL_ARB_draw_elements_base_vertex
DrawElementsBaseVertex = LoadFunctionOrNull<DrawElementsBaseVertexDelegate>("glDrawElementsBaseVertex");
DrawRangeElementsBaseVertex = LoadFunctionOrNull<DrawRangeElementsBaseVertexDelegate>("glDrawRangeElementsBaseVertex");

// uniforms OpenGL Version >= 2.0
Uniform1i = LoadFunctionOrNull<Uniform1iDelegate>("glUniform1i");
Uniform1f = LoadFunctionOrNull<Uniform1fDelegate>("glUniform1f");
Expand Down Expand Up @@ -1719,9 +1724,9 @@ internal void InitExtensions()
if (BlendEquationSeparatei == null && Extensions.Contains("GL_ARB_draw_buffers_blend"))
BlendEquationSeparatei = LoadFunctionOrNull<OGL.BlendEquationSeparateiDelegate>("BlendEquationSeparateiARB");

//if (Extensions.Contains("GL_ARB_draw_elements_base_vertex"))
if (DrawElementsBaseVertex == null && Extensions.Contains("GL_ARB_draw_elements_base_vertex"))
DrawElementsBaseVertex = LoadFunctionOrNull<DrawElementsBaseVertexDelegate>("glDrawElementsBaseVertex");
//if (Extensions.Contains("GL_ARB_draw_elements_base_vertex"))
if (DrawRangeElementsBaseVertex == null && Extensions.Contains("GL_ARB_draw_elements_base_vertex"))
DrawRangeElementsBaseVertex = LoadFunctionOrNull<DrawRangeElementsBaseVertexDelegate>("glDrawRangeElementsBaseVertex");
}

Expand Down
10 changes: 2 additions & 8 deletions Platforms/Graphics/.GL/States/ConcreteSamplerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Platform.Graphics.OpenGL;
using ExtTextureFilterAnisotropic = Microsoft.Xna.Platform.Graphics.OpenGL.TextureParameterName;



namespace Microsoft.Xna.Platform.Graphics
Expand All @@ -21,10 +19,6 @@ internal class ConcreteSamplerState : ResourceSamplerStateStrategy
{
private readonly float[] _openGLBorderColor = new float[4];

internal const TextureParameterName TextureParameterNameTextureMaxAnisotropy = (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt;
internal const TextureParameterName TextureParameterNameTextureMaxLevel = TextureParameterName.TextureMaxLevel;


internal ConcreteSamplerState(GraphicsContextStrategy contextStrategy, ISamplerStateStrategy source)
: base(contextStrategy, source)
{
Expand Down Expand Up @@ -94,7 +88,7 @@ internal void PlatformApplyState(ConcreteGraphicsContextGL cgraphicsContext, Tex
}
if (cgraphicsContext.Capabilities.SupportsTextureFilterAnisotropic)
{
GL.TexParameter(target, TextureParameterNameTextureMaxAnisotropy, textureMaxAnisotropy);
GL.TexParameter(target, TextureParameterName.TextureMaxAnisotropyExt, textureMaxAnisotropy);
GL.CheckGLError();
}
GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)textureMinFilter);
Expand Down Expand Up @@ -143,7 +137,7 @@ internal void PlatformApplyState(ConcreteGraphicsContextGL cgraphicsContext, Tex
int textureMaxLevel = 1000;
if (this.MaxMipLevel > 0)
textureMaxLevel = this.MaxMipLevel;
GL.TexParameter(TextureTarget.Texture2D, TextureParameterNameTextureMaxLevel, textureMaxLevel);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, textureMaxLevel);
GL.CheckGLError();
}
}
Expand Down

0 comments on commit 2af773b

Please sign in to comment.