Skip to content

Commit

Permalink
_lastVertexAttribs (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkast authored May 24, 2024
1 parent d72976c commit 4e97bb2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal sealed class ConcreteGraphicsContext : GraphicsContextStrategy
private int _activeBufferBindingInfosCount;
internal bool[] _newEnabledVertexAttributes;
private readonly HashSet<int> _enabledVertexAttributesSet = new HashSet<int>();
private bool _attribsDirty;
private int _lastVertexAttribs; // 0 = dirty, 1 = last set by PlatformApplyVertexBuffers, 2 = last set by PlatformApplyUserVertexData

private DepthStencilState _clearDepthStencilState = new DepthStencilState { StencilEnable = true };

Expand Down Expand Up @@ -384,7 +384,7 @@ private void PlatformApplyVertexBuffers(int baseVertex)
int maxVertexBufferSlots = ((IPlatformGraphicsContext)this.Context).DeviceStrategy.Capabilities.MaxVertexBufferSlots;
VertexDeclarationAttributeInfo vertexAttribInfo = vertexShaderStrategy.GetVertexAttribInfo(vertexDeclaration, maxVertexBufferSlots);

if (_attribsDirty
if (_lastVertexAttribs != 1
|| _bufferBindingInfos[slot].GLVertexBuffer != ((IPlatformVertexBuffer)vertexBufferBinding.VertexBuffer).Strategy
|| !ReferenceEquals(_bufferBindingInfos[slot].AttributeInfo, vertexAttribInfo)
|| _bufferBindingInfos[slot].VertexOffset != vertexOffset
Expand Down Expand Up @@ -428,8 +428,6 @@ private void PlatformApplyVertexBuffers(int baseVertex)
}
}

_attribsDirty = false;

if (bindingsChanged)
{
for (int eva = 0; eva < _newEnabledVertexAttributes.Length; eva++)
Expand Down Expand Up @@ -468,6 +466,7 @@ private void PlatformApplyVertexBuffers(int baseVertex)
}
}
}
_lastVertexAttribs = 1;
}

internal void PlatformApplyUserVertexData(VertexDeclaration vertexDeclaration, int baseVertex)
Expand Down Expand Up @@ -521,7 +520,7 @@ internal void PlatformApplyUserVertexData(VertexDeclaration vertexDeclaration, i
}
}
}
_attribsDirty = true;
_lastVertexAttribs = 2;
}

private static WebGLPrimitiveType PrimitiveTypeGL(PrimitiveType primitiveType)
Expand Down
13 changes: 6 additions & 7 deletions MonoGame.Framework/Graphics/.GL/ConcreteGraphicsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ internal abstract class ConcreteGraphicsContextGL : GraphicsContextStrategy
private int _activeBufferBindingInfosCount;
internal bool[] _newEnabledVertexAttributes;
private readonly HashSet<int> _enabledVertexAttributesSet = new HashSet<int>();
private bool _attribsDirty;
private int _lastVertexAttribs; // 0 = dirty, 1 = last set by PlatformApplyVertexBuffers, 2 = last set by PlatformApplyUserVertexData

// Keeps track of last applied state to avoid redundant OpenGL calls
private Vector4 _lastClearColor = Vector4.Zero;
Expand Down Expand Up @@ -431,7 +431,7 @@ private void PlatformApplyVertexBuffers(int baseVertex)
int maxVertexBufferSlots = ((IPlatformGraphicsContext)this.Context).DeviceStrategy.Capabilities.MaxVertexBufferSlots;
VertexDeclarationAttributeInfo vertexAttribInfo = vertexShaderStrategy.GetVertexAttribInfo(vertexDeclaration, maxVertexBufferSlots);

if (_attribsDirty
if (_lastVertexAttribs != 1
|| _bufferBindingInfos[slot].GLVertexBuffer != ((IPlatformVertexBuffer)vertexBufferBinding.VertexBuffer).Strategy
|| !ReferenceEquals(_bufferBindingInfos[slot].AttributeInfo, vertexAttribInfo)
|| _bufferBindingInfos[slot].VertexOffset != vertexOffset
Expand Down Expand Up @@ -474,8 +474,6 @@ private void PlatformApplyVertexBuffers(int baseVertex)
}
}

_attribsDirty = false;

if (bindingsChanged)
{
for (int eva = 0; eva < _newEnabledVertexAttributes.Length; eva++)
Expand Down Expand Up @@ -514,6 +512,7 @@ private void PlatformApplyVertexBuffers(int baseVertex)
}
}
}
_lastVertexAttribs = 1;
}

internal void PlatformApplyUserVertexData(VertexDeclaration vertexDeclaration, IntPtr baseVertex)
Expand Down Expand Up @@ -568,7 +567,7 @@ internal void PlatformApplyUserVertexData(VertexDeclaration vertexDeclaration, I
}
}
}
_attribsDirty = true;
_lastVertexAttribs = 2;
}

private static GLPrimitiveType PrimitiveTypeGL(PrimitiveType primitiveType)
Expand Down Expand Up @@ -1184,8 +1183,8 @@ internal void Cardboard_ResetContext()
//invalidate scissor
_scissorRectangleDirty = true;

//invalidate index buffer
_attribsDirty = true;
//invalidate vertex and index buffer
_lastVertexAttribs = 0;
_indexBufferDirty = true;

//invalidate shaders
Expand Down

0 comments on commit 4e97bb2

Please sign in to comment.