diff --git a/MonoGame.Framework/Graphics/.BlazorGL/ConcreteGraphicsContext.cs b/MonoGame.Framework/Graphics/.BlazorGL/ConcreteGraphicsContext.cs index c2501f86236..9d450f715f8 100644 --- a/MonoGame.Framework/Graphics/.BlazorGL/ConcreteGraphicsContext.cs +++ b/MonoGame.Framework/Graphics/.BlazorGL/ConcreteGraphicsContext.cs @@ -28,7 +28,7 @@ internal sealed class ConcreteGraphicsContext : GraphicsContextStrategy internal BufferBindingInfo[] _bufferBindingInfos; private int _activeBufferBindingInfosCount; internal bool[] _newEnabledVertexAttributes; - internal readonly HashSet _enabledVertexAttributes = new HashSet(); + private readonly HashSet _enabledVertexAttributesSet = new HashSet(); private bool _attribsDirty; private DepthStencilState _clearDepthStencilState = new DepthStencilState { StencilEnable = true }; @@ -373,29 +373,6 @@ public WebGLUniformLocation GetUniformLocation(ShaderProgram shaderProgram, stri return location; } - private void SetVertexAttributeArray(bool[] attrs) - { - for (int x = 0; x < attrs.Length; x++) - { - if (attrs[x]) - { - if (_enabledVertexAttributes.Add(x)) - { - GL.EnableVertexAttribArray(x); - GL.CheckGLError(); - } - } - else - { - if (_enabledVertexAttributes.Remove(x)) - { - GL.DisableVertexAttribArray(x); - GL.CheckGLError(); - } - } - } - } - private void PlatformApplyVertexBuffersAttribs(int baseVertex) { ConcreteVertexShader vertexShaderStrategy = ((IPlatformShader)this.VertexShader).Strategy.ToConcrete(); @@ -461,6 +438,7 @@ private void PlatformApplyVertexBuffersAttribs(int baseVertex) { for (int eva = 0; eva < _newEnabledVertexAttributes.Length; eva++) _newEnabledVertexAttributes[eva] = false; + for (int slot = 0; slot < _vertexBuffers.Count; slot++) { for (int e = 0; e < _bufferBindingInfos[slot].AttributeInfo.Elements.Count; e++) @@ -472,7 +450,28 @@ private void PlatformApplyVertexBuffersAttribs(int baseVertex) _activeBufferBindingInfosCount = _vertexBuffers.Count; } - SetVertexAttributeArray(_newEnabledVertexAttributes); + // SetVertexAttributeArray + { + for (int x = 0; x < _newEnabledVertexAttributes.Length; x++) + { + if (_newEnabledVertexAttributes[x] == true) + { + if (_enabledVertexAttributesSet.Add(x)) + { + GL.EnableVertexAttribArray(x); + GL.CheckGLError(); + } + } + else // (_newEnabledVertexAttributes[x] == false) + { + if (_enabledVertexAttributesSet.Remove(x)) + { + GL.DisableVertexAttribArray(x); + GL.CheckGLError(); + } + } + } + } } internal void PlatformApplyUserVertexDataAttribs(VertexDeclaration vertexDeclaration, int baseVertex) @@ -504,7 +503,28 @@ internal void PlatformApplyUserVertexDataAttribs(VertexDeclaration vertexDeclara } } - SetVertexAttributeArray(vertexAttribInfo.EnabledAttributes); + // SetVertexAttributeArray + { + for (int x = 0; x < vertexAttribInfo.EnabledAttributes.Length; x++) + { + if (vertexAttribInfo.EnabledAttributes[x] == true) + { + if (_enabledVertexAttributesSet.Add(x)) + { + GL.EnableVertexAttribArray(x); + GL.CheckGLError(); + } + } + else // (vertexAttribInfo.EnabledAttributes[x] == false) + { + if (_enabledVertexAttributesSet.Remove(x)) + { + GL.DisableVertexAttribArray(x); + GL.CheckGLError(); + } + } + } + } _attribsDirty = true; } diff --git a/MonoGame.Framework/Graphics/.GL/ConcreteGraphicsContext.cs b/MonoGame.Framework/Graphics/.GL/ConcreteGraphicsContext.cs index ef8e7d2e195..4982eeef539 100644 --- a/MonoGame.Framework/Graphics/.GL/ConcreteGraphicsContext.cs +++ b/MonoGame.Framework/Graphics/.GL/ConcreteGraphicsContext.cs @@ -40,7 +40,7 @@ internal abstract class ConcreteGraphicsContextGL : GraphicsContextStrategy internal BufferBindingInfo[] _bufferBindingInfos; private int _activeBufferBindingInfosCount; internal bool[] _newEnabledVertexAttributes; - internal readonly HashSet _enabledVertexAttributes = new HashSet(); + private readonly HashSet _enabledVertexAttributesSet = new HashSet(); private bool _attribsDirty; // Keeps track of last applied state to avoid redundant OpenGL calls @@ -419,29 +419,6 @@ internal int GetUniformLocation(ShaderProgram shaderProgram, string name) return location; } - private void SetVertexAttributeArray(bool[] attrs) - { - for (int x = 0; x < attrs.Length; x++) - { - if (attrs[x]) - { - if (_enabledVertexAttributes.Add(x)) - { - GL.EnableVertexAttribArray(x); - GL.CheckGLError(); - } - } - else - { - if (_enabledVertexAttributes.Remove(x)) - { - GL.DisableVertexAttribArray(x); - GL.CheckGLError(); - } - } - } - } - private void PlatformApplyVertexBuffersAttribs(int baseVertex) { ConcreteVertexShader vertexShaderStrategy = ((IPlatformShader)this.VertexShader).Strategy.ToConcrete(); @@ -507,6 +484,7 @@ private void PlatformApplyVertexBuffersAttribs(int baseVertex) { for (int eva = 0; eva < _newEnabledVertexAttributes.Length; eva++) _newEnabledVertexAttributes[eva] = false; + for (int slot = 0; slot < _vertexBuffers.Count; slot++) { for (int e = 0; e < _bufferBindingInfos[slot].AttributeInfo.Elements.Count; e++) @@ -518,7 +496,28 @@ private void PlatformApplyVertexBuffersAttribs(int baseVertex) _activeBufferBindingInfosCount = _vertexBuffers.Count; } - SetVertexAttributeArray(_newEnabledVertexAttributes); + // SetVertexAttributeArray + { + for (int x = 0; x < _newEnabledVertexAttributes.Length; x++) + { + if (_newEnabledVertexAttributes[x] == true) + { + if (_enabledVertexAttributesSet.Add(x)) + { + GL.EnableVertexAttribArray(x); + GL.CheckGLError(); + } + } + else // (_newEnabledVertexAttributes[x] == false) + { + if (_enabledVertexAttributesSet.Remove(x)) + { + GL.DisableVertexAttribArray(x); + GL.CheckGLError(); + } + } + } + } } internal void PlatformApplyUserVertexDataAttribs(VertexDeclaration vertexDeclaration, IntPtr baseVertex) @@ -551,7 +550,28 @@ internal void PlatformApplyUserVertexDataAttribs(VertexDeclaration vertexDeclara #endif } - SetVertexAttributeArray(vertexAttribInfo.EnabledAttributes); + // SetVertexAttributeArray + { + for (int x = 0; x < vertexAttribInfo.EnabledAttributes.Length; x++) + { + if (vertexAttribInfo.EnabledAttributes[x] == true) + { + if (_enabledVertexAttributesSet.Add(x)) + { + GL.EnableVertexAttribArray(x); + GL.CheckGLError(); + } + } + else // (vertexAttribInfo.EnabledAttributes[x] == false) + { + if (_enabledVertexAttributesSet.Remove(x)) + { + GL.DisableVertexAttribArray(x); + GL.CheckGLError(); + } + } + } + } _attribsDirty = true; } @@ -1184,7 +1204,7 @@ internal void Cardboard_ResetContext() _shaderProgram = null; //invalidate VertexAttributes - _enabledVertexAttributes.Clear(); + _enabledVertexAttributesSet.Clear(); //invalidate textures ((IPlatformTextureCollection)this.Textures).Strategy.Clear();