aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.OpenGL/VertexArray.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-05-23 06:46:09 -0300
committerGitHub <noreply@github.com>2020-05-23 11:46:09 +0200
commit5011640b3086b86b0f0b39b60fdb2aa946d4f5c8 (patch)
tree1bd60b7714886dfe282ca1e52cfa6fca97912cdf /Ryujinx.Graphics.OpenGL/VertexArray.cs
parentcc8dbdd3fb58a02e1c3fc3b9d0b1c35bc7b9d00f (diff)
Spanify Graphics Abstraction Layer (#1226)
* Spanify Graphics Abstraction Layer * Be explicit about BufferHandle size
Diffstat (limited to 'Ryujinx.Graphics.OpenGL/VertexArray.cs')
-rw-r--r--Ryujinx.Graphics.OpenGL/VertexArray.cs64
1 files changed, 37 insertions, 27 deletions
diff --git a/Ryujinx.Graphics.OpenGL/VertexArray.cs b/Ryujinx.Graphics.OpenGL/VertexArray.cs
index 43d200a4..cc352761 100644
--- a/Ryujinx.Graphics.OpenGL/VertexArray.cs
+++ b/Ryujinx.Graphics.OpenGL/VertexArray.cs
@@ -10,12 +10,18 @@ namespace Ryujinx.Graphics.OpenGL
private bool _needsAttribsUpdate;
- private VertexBufferDescriptor[] _vertexBuffers;
- private VertexAttribDescriptor[] _vertexAttribs;
+ private readonly VertexAttribDescriptor[] _vertexAttribs;
+ private readonly VertexBufferDescriptor[] _vertexBuffers;
+
+ private int _vertexAttribsCount;
+ private int _vertexBuffersCount;
public VertexArray()
{
Handle = GL.GenVertexArray();
+
+ _vertexAttribs = new VertexAttribDescriptor[Constants.MaxVertexAttribs];
+ _vertexBuffers = new VertexBufferDescriptor[Constants.MaxVertexBuffers];
}
public void Bind()
@@ -23,17 +29,17 @@ namespace Ryujinx.Graphics.OpenGL
GL.BindVertexArray(Handle);
}
- public void SetVertexBuffers(VertexBufferDescriptor[] vertexBuffers)
+ public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
{
int bindingIndex = 0;
- foreach (VertexBufferDescriptor vb in vertexBuffers)
+ for (int index = 0; index < vertexBuffers.Length; index++)
{
- if (vb.Buffer.Buffer != null)
- {
- int bufferHandle = ((Buffer)vb.Buffer.Buffer).Handle;
+ VertexBufferDescriptor vb = vertexBuffers[index];
- GL.BindVertexBuffer(bindingIndex, bufferHandle, (IntPtr)vb.Buffer.Offset, vb.Stride);
+ if (vb.Buffer.Handle != null)
+ {
+ GL.BindVertexBuffer(bindingIndex, vb.Buffer.Handle.ToInt32(), (IntPtr)vb.Buffer.Offset, vb.Stride);
GL.VertexBindingDivisor(bindingIndex, vb.Divisor);
}
@@ -42,31 +48,35 @@ namespace Ryujinx.Graphics.OpenGL
GL.BindVertexBuffer(bindingIndex, 0, IntPtr.Zero, 0);
}
+ _vertexBuffers[index] = vb;
+
bindingIndex++;
}
- _vertexBuffers = vertexBuffers;
+ _vertexBuffersCount = bindingIndex;
_needsAttribsUpdate = true;
}
- public void SetVertexAttributes(VertexAttribDescriptor[] vertexAttribs)
+ public void SetVertexAttributes(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
{
- int attribIndex = 0;
+ int index = 0;
- foreach (VertexAttribDescriptor attrib in vertexAttribs)
+ for (; index < vertexAttribs.Length; index++)
{
+ VertexAttribDescriptor attrib = vertexAttribs[index];
+
FormatInfo fmtInfo = FormatTable.GetFormatInfo(attrib.Format);
if (attrib.IsZero)
{
// Disabling the attribute causes the shader to read a constant value.
// The value is configurable, but by default is a vector of (0, 0, 0, 1).
- GL.DisableVertexAttribArray(attribIndex);
+ GL.DisableVertexAttribArray(index);
}
else
{
- GL.EnableVertexAttribArray(attribIndex);
+ GL.EnableVertexAttribArray(index);
}
int offset = attrib.Offset;
@@ -79,47 +89,47 @@ namespace Ryujinx.Graphics.OpenGL
{
VertexAttribType type = (VertexAttribType)fmtInfo.PixelType;
- GL.VertexAttribFormat(attribIndex, size, type, fmtInfo.Normalized, offset);
+ GL.VertexAttribFormat(index, size, type, fmtInfo.Normalized, offset);
}
else
{
VertexAttribIntegerType type = (VertexAttribIntegerType)fmtInfo.PixelType;
- GL.VertexAttribIFormat(attribIndex, size, type, offset);
+ GL.VertexAttribIFormat(index, size, type, offset);
}
- GL.VertexAttribBinding(attribIndex, attrib.BufferIndex);
+ GL.VertexAttribBinding(index, attrib.BufferIndex);
- attribIndex++;
+ _vertexAttribs[index] = attrib;
}
- for (; attribIndex < 16; attribIndex++)
+ _vertexAttribsCount = index;
+
+ for (; index < Constants.MaxVertexAttribs; index++)
{
- GL.DisableVertexAttribArray(attribIndex);
+ GL.DisableVertexAttribArray(index);
}
-
- _vertexAttribs = vertexAttribs;
}
- public void SetIndexBuffer(Buffer indexBuffer)
+ public void SetIndexBuffer(BufferHandle buffer)
{
- GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer?.Handle ?? 0);
+ GL.BindBuffer(BufferTarget.ElementArrayBuffer, buffer.ToInt32());
}
public void Validate()
{
- for (int attribIndex = 0; attribIndex < _vertexAttribs.Length; attribIndex++)
+ for (int attribIndex = 0; attribIndex < _vertexAttribsCount; attribIndex++)
{
VertexAttribDescriptor attrib = _vertexAttribs[attribIndex];
- if ((uint)attrib.BufferIndex >= _vertexBuffers.Length)
+ if ((uint)attrib.BufferIndex >= _vertexBuffersCount)
{
GL.DisableVertexAttribArray(attribIndex);
continue;
}
- if (_vertexBuffers[attrib.BufferIndex].Buffer.Buffer == null)
+ if (_vertexBuffers[attrib.BufferIndex].Buffer.Handle == null)
{
GL.DisableVertexAttribArray(attribIndex);