From 2af773b421cd193e80a3aa78e3a7634e027a01e6 Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Wed, 1 Jan 2025 08:39:03 +0200 Subject: [PATCH] refactor GL graphics (#2164) * whitespaces * refactor DrawElementsBaseVertex * clean up ConcreteSamplerState --- Platforms/Graphics/.GL/ConcreteGraphicsContext.cs | 2 +- Platforms/Graphics/.GL/OpenGL.cs | 9 +++++++-- Platforms/Graphics/.GL/States/ConcreteSamplerState.cs | 10 ++-------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Platforms/Graphics/.GL/ConcreteGraphicsContext.cs b/Platforms/Graphics/.GL/ConcreteGraphicsContext.cs index f961ba32141..bda8e5ba71f 100644 --- a/Platforms/Graphics/.GL/ConcreteGraphicsContext.cs +++ b/Platforms/Graphics/.GL/ConcreteGraphicsContext.cs @@ -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; diff --git a/Platforms/Graphics/.GL/OpenGL.cs b/Platforms/Graphics/.GL/OpenGL.cs index dd5947f891c..4f68406365e 100644 --- a/Platforms/Graphics/.GL/OpenGL.cs +++ b/Platforms/Graphics/.GL/OpenGL.cs @@ -1492,8 +1492,13 @@ private void LoadEntryPoints() DrawElements = LoadFunctionOrNull("glDrawElements"); DrawArrays = LoadFunctionOrNull("glDrawArrays"); + // OpenGL >= 2.0, GLES >= 3.0 DrawRangeElements = LoadFunctionOrNull("glDrawRangeElements"); + // OpenGL >= 3.2, GLES >= 3.2 or GL_ARB_draw_elements_base_vertex + DrawElementsBaseVertex = LoadFunctionOrNull("glDrawElementsBaseVertex"); + DrawRangeElementsBaseVertex = LoadFunctionOrNull("glDrawRangeElementsBaseVertex"); + // uniforms OpenGL Version >= 2.0 Uniform1i = LoadFunctionOrNull("glUniform1i"); Uniform1f = LoadFunctionOrNull("glUniform1f"); @@ -1719,9 +1724,9 @@ internal void InitExtensions() if (BlendEquationSeparatei == null && Extensions.Contains("GL_ARB_draw_buffers_blend")) BlendEquationSeparatei = LoadFunctionOrNull("BlendEquationSeparateiARB"); - //if (Extensions.Contains("GL_ARB_draw_elements_base_vertex")) + if (DrawElementsBaseVertex == null && Extensions.Contains("GL_ARB_draw_elements_base_vertex")) DrawElementsBaseVertex = LoadFunctionOrNull("glDrawElementsBaseVertex"); - //if (Extensions.Contains("GL_ARB_draw_elements_base_vertex")) + if (DrawRangeElementsBaseVertex == null && Extensions.Contains("GL_ARB_draw_elements_base_vertex")) DrawRangeElementsBaseVertex = LoadFunctionOrNull("glDrawRangeElementsBaseVertex"); } diff --git a/Platforms/Graphics/.GL/States/ConcreteSamplerState.cs b/Platforms/Graphics/.GL/States/ConcreteSamplerState.cs index cfe83de94e2..0fe7720385d 100644 --- a/Platforms/Graphics/.GL/States/ConcreteSamplerState.cs +++ b/Platforms/Graphics/.GL/States/ConcreteSamplerState.cs @@ -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 @@ -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) { @@ -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); @@ -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(); } }