aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.OpenGL
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
parentcc8dbdd3fb58a02e1c3fc3b9d0b1c35bc7b9d00f (diff)
Spanify Graphics Abstraction Layer (#1226)
* Spanify Graphics Abstraction Layer * Be explicit about BufferHandle size
Diffstat (limited to 'Ryujinx.Graphics.OpenGL')
-rw-r--r--Ryujinx.Graphics.OpenGL/Buffer.cs43
-rw-r--r--Ryujinx.Graphics.OpenGL/Constants.cs10
-rw-r--r--Ryujinx.Graphics.OpenGL/Framebuffer.cs1
-rw-r--r--Ryujinx.Graphics.OpenGL/Handle.cs23
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/Sampler.cs (renamed from Ryujinx.Graphics.OpenGL/Sampler.cs)2
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureBase.cs (renamed from Ryujinx.Graphics.OpenGL/TextureBase.cs)5
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs (renamed from Ryujinx.Graphics.OpenGL/TextureBuffer.cs)14
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs (renamed from Ryujinx.Graphics.OpenGL/TextureCopy.cs)2
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureCopyUnscaled.cs (renamed from Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs)2
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs (renamed from Ryujinx.Graphics.OpenGL/TextureStorage.cs)2
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureView.cs (renamed from Ryujinx.Graphics.OpenGL/TextureView.cs)2
-rw-r--r--Ryujinx.Graphics.OpenGL/Pipeline.cs51
-rw-r--r--Ryujinx.Graphics.OpenGL/Renderer.cs20
-rw-r--r--Ryujinx.Graphics.OpenGL/VertexArray.cs64
-rw-r--r--Ryujinx.Graphics.OpenGL/Window.cs1
15 files changed, 147 insertions, 95 deletions
diff --git a/Ryujinx.Graphics.OpenGL/Buffer.cs b/Ryujinx.Graphics.OpenGL/Buffer.cs
index db3e94ba..e8fd9a6b 100644
--- a/Ryujinx.Graphics.OpenGL/Buffer.cs
+++ b/Ryujinx.Graphics.OpenGL/Buffer.cs
@@ -4,22 +4,22 @@ using System;
namespace Ryujinx.Graphics.OpenGL
{
- class Buffer : IBuffer
+ static class Buffer
{
- public int Handle { get; }
-
- public Buffer(int size)
+ public static BufferHandle Create(int size)
{
- Handle = GL.GenBuffer();
+ int handle = GL.GenBuffer();
- GL.BindBuffer(BufferTarget.CopyWriteBuffer, Handle);
+ GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle);
GL.BufferData(BufferTarget.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageHint.DynamicDraw);
+
+ return Handle.FromInt32<BufferHandle>(handle);
}
- public void CopyTo(IBuffer destination, int srcOffset, int dstOffset, int size)
+ public static void Copy(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size)
{
- GL.BindBuffer(BufferTarget.CopyReadBuffer, Handle);
- GL.BindBuffer(BufferTarget.CopyWriteBuffer, ((Buffer)destination).Handle);
+ GL.BindBuffer(BufferTarget.CopyReadBuffer, source.ToInt32());
+ GL.BindBuffer(BufferTarget.CopyWriteBuffer, destination.ToInt32());
GL.CopyBufferSubData(
BufferTarget.CopyReadBuffer,
@@ -29,9 +29,9 @@ namespace Ryujinx.Graphics.OpenGL
(IntPtr)size);
}
- public byte[] GetData(int offset, int size)
+ public static byte[] GetData(BufferHandle buffer, int offset, int size)
{
- GL.BindBuffer(BufferTarget.CopyReadBuffer, Handle);
+ GL.BindBuffer(BufferTarget.CopyReadBuffer, buffer.ToInt32());
byte[] data = new byte[size];
@@ -40,22 +40,9 @@ namespace Ryujinx.Graphics.OpenGL
return data;
}
- public void SetData(ReadOnlySpan<byte> data)
- {
- unsafe
- {
- GL.BindBuffer(BufferTarget.CopyWriteBuffer, Handle);
-
- fixed (byte* ptr = data)
- {
- GL.BufferData(BufferTarget.CopyWriteBuffer, data.Length, (IntPtr)ptr, BufferUsageHint.DynamicDraw);
- }
- }
- }
-
- public void SetData(int offset, ReadOnlySpan<byte> data)
+ public static void SetData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
{
- GL.BindBuffer(BufferTarget.CopyWriteBuffer, Handle);
+ GL.BindBuffer(BufferTarget.CopyWriteBuffer, buffer.ToInt32());
unsafe
{
@@ -66,9 +53,9 @@ namespace Ryujinx.Graphics.OpenGL
}
}
- public void Dispose()
+ public static void Delete(BufferHandle buffer)
{
- GL.DeleteBuffer(Handle);
+ GL.DeleteBuffer(buffer.ToInt32());
}
}
}
diff --git a/Ryujinx.Graphics.OpenGL/Constants.cs b/Ryujinx.Graphics.OpenGL/Constants.cs
new file mode 100644
index 00000000..9775b240
--- /dev/null
+++ b/Ryujinx.Graphics.OpenGL/Constants.cs
@@ -0,0 +1,10 @@
+namespace Ryujinx.Graphics.OpenGL
+{
+ static class Constants
+ {
+ public const int MaxRenderTargets = 8;
+ public const int MaxViewports = 16;
+ public const int MaxVertexAttribs = 16;
+ public const int MaxVertexBuffers = 16;
+ }
+}
diff --git a/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/Ryujinx.Graphics.OpenGL/Framebuffer.cs
index 23f015b1..e66dcaca 100644
--- a/Ryujinx.Graphics.OpenGL/Framebuffer.cs
+++ b/Ryujinx.Graphics.OpenGL/Framebuffer.cs
@@ -1,5 +1,6 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
+using Ryujinx.Graphics.OpenGL.Image;
using System;
namespace Ryujinx.Graphics.OpenGL
diff --git a/Ryujinx.Graphics.OpenGL/Handle.cs b/Ryujinx.Graphics.OpenGL/Handle.cs
new file mode 100644
index 00000000..4b2f05e6
--- /dev/null
+++ b/Ryujinx.Graphics.OpenGL/Handle.cs
@@ -0,0 +1,23 @@
+using Ryujinx.Graphics.GAL;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+namespace Ryujinx.Graphics.OpenGL
+{
+ static class Handle
+ {
+ public static T FromInt32<T>(int handle) where T : unmanaged
+ {
+ Debug.Assert(Unsafe.SizeOf<T>() == sizeof(ulong));
+
+ ulong handle64 = (uint)handle;
+
+ return Unsafe.As<ulong, T>(ref handle64);
+ }
+
+ public static int ToInt32(this BufferHandle handle)
+ {
+ return (int)Unsafe.As<BufferHandle, ulong>(ref handle);
+ }
+ }
+}
diff --git a/Ryujinx.Graphics.OpenGL/Sampler.cs b/Ryujinx.Graphics.OpenGL/Image/Sampler.cs
index 674fc797..e13f0da3 100644
--- a/Ryujinx.Graphics.OpenGL/Sampler.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/Sampler.cs
@@ -1,7 +1,7 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
-namespace Ryujinx.Graphics.OpenGL
+namespace Ryujinx.Graphics.OpenGL.Image
{
class Sampler : ISampler
{
diff --git a/Ryujinx.Graphics.OpenGL/TextureBase.cs b/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs
index f4ab0bda..a4209ea1 100644
--- a/Ryujinx.Graphics.OpenGL/TextureBase.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs
@@ -1,10 +1,7 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
-using System;
-using System.Collections.Generic;
-using System.Text;
-namespace Ryujinx.Graphics.OpenGL
+namespace Ryujinx.Graphics.OpenGL.Image
{
class TextureBase
{
diff --git a/Ryujinx.Graphics.OpenGL/TextureBuffer.cs b/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs
index fb18c6ee..2c69571c 100644
--- a/Ryujinx.Graphics.OpenGL/TextureBuffer.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs
@@ -2,14 +2,14 @@
using Ryujinx.Graphics.GAL;
using System;
-namespace Ryujinx.Graphics.OpenGL
+namespace Ryujinx.Graphics.OpenGL.Image
{
class TextureBuffer : TextureBase, ITexture
{
private int _bufferOffset;
private int _bufferSize;
- private Buffer _buffer;
+ private BufferHandle _buffer;
public TextureBuffer(TextureCreateInfo info) : base(info) {}
@@ -30,24 +30,24 @@ namespace Ryujinx.Graphics.OpenGL
public byte[] GetData()
{
- return _buffer?.GetData(_bufferOffset, _bufferSize);
+ return Buffer.GetData(_buffer, _bufferOffset, _bufferSize);
}
public void SetData(ReadOnlySpan<byte> data)
{
- _buffer?.SetData(_bufferOffset, data.Slice(0, Math.Min(data.Length, _bufferSize)));
+ Buffer.SetData(_buffer, _bufferOffset, data.Slice(0, Math.Min(data.Length, _bufferSize)));
}
public void SetStorage(BufferRange buffer)
{
- if (buffer.Buffer == _buffer &&
+ if (buffer.Handle == _buffer &&
buffer.Offset == _bufferOffset &&
buffer.Size == _bufferSize)
{
return;
}
- _buffer = (Buffer)buffer.Buffer;
+ _buffer = buffer.Handle;
_bufferOffset = buffer.Offset;
_bufferSize = buffer.Size;
@@ -55,7 +55,7 @@ namespace Ryujinx.Graphics.OpenGL
SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).PixelInternalFormat;
- GL.TexBufferRange(TextureBufferTarget.TextureBuffer, format, _buffer.Handle, (IntPtr)buffer.Offset, buffer.Size);
+ GL.TexBufferRange(TextureBufferTarget.TextureBuffer, format, _buffer.ToInt32(), (IntPtr)buffer.Offset, buffer.Size);
}
public void Dispose()
diff --git a/Ryujinx.Graphics.OpenGL/TextureCopy.cs b/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs
index 59db94a4..1cef61a9 100644
--- a/Ryujinx.Graphics.OpenGL/TextureCopy.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs
@@ -2,7 +2,7 @@ using Ryujinx.Graphics.GAL;
using OpenTK.Graphics.OpenGL;
using System;
-namespace Ryujinx.Graphics.OpenGL
+namespace Ryujinx.Graphics.OpenGL.Image
{
class TextureCopy : IDisposable
{
diff --git a/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs b/Ryujinx.Graphics.OpenGL/Image/TextureCopyUnscaled.cs
index 5ae75d9c..28401138 100644
--- a/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureCopyUnscaled.cs
@@ -3,7 +3,7 @@ using Ryujinx.Common;
using Ryujinx.Graphics.GAL;
using System;
-namespace Ryujinx.Graphics.OpenGL
+namespace Ryujinx.Graphics.OpenGL.Image
{
static class TextureCopyUnscaled
{
diff --git a/Ryujinx.Graphics.OpenGL/TextureStorage.cs b/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs
index b680f3a6..baf8e65d 100644
--- a/Ryujinx.Graphics.OpenGL/TextureStorage.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs
@@ -2,7 +2,7 @@ using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
-namespace Ryujinx.Graphics.OpenGL
+namespace Ryujinx.Graphics.OpenGL.Image
{
class TextureStorage
{
diff --git a/Ryujinx.Graphics.OpenGL/TextureView.cs b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
index 0ab59d42..0b24a296 100644
--- a/Ryujinx.Graphics.OpenGL/TextureView.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
@@ -2,7 +2,7 @@ using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
using System;
-namespace Ryujinx.Graphics.OpenGL
+namespace Ryujinx.Graphics.OpenGL.Image
{
class TextureView : TextureBase, ITexture
{
diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs
index 80b07108..05383f5d 100644
--- a/Ryujinx.Graphics.OpenGL/Pipeline.cs
+++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs
@@ -1,6 +1,7 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
+using Ryujinx.Graphics.OpenGL.Image;
using Ryujinx.Graphics.OpenGL.Queries;
using Ryujinx.Graphics.Shader;
using System;
@@ -32,7 +33,7 @@ namespace Ryujinx.Graphics.OpenGL
private ClipOrigin _clipOrigin;
private ClipDepthMode _clipDepthMode;
- private uint[] _componentMasks;
+ private readonly uint[] _componentMasks;
private bool _scissor0Enable = false;
@@ -43,6 +44,13 @@ namespace Ryujinx.Graphics.OpenGL
_rasterizerDiscard = false;
_clipOrigin = ClipOrigin.LowerLeft;
_clipDepthMode = ClipDepthMode.NegativeOneToOne;
+
+ _componentMasks = new uint[Constants.MaxRenderTargets];
+
+ for (int index = 0; index < Constants.MaxRenderTargets; index++)
+ {
+ _componentMasks[index] = 0xf;
+ }
}
public void Barrier()
@@ -112,6 +120,11 @@ namespace Ryujinx.Graphics.OpenGL
_framebuffer.SignalModified();
}
+ public void CopyBuffer(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size)
+ {
+ Buffer.Copy(source, destination, srcOffset, dstOffset, size);
+ }
+
public void DispatchCompute(int groupsX, int groupsY, int groupsZ)
{
if (!_program.IsLinked)
@@ -631,7 +644,7 @@ namespace Ryujinx.Graphics.OpenGL
EnsureVertexArray();
- _vertexArray.SetIndexBuffer((Buffer)buffer.Buffer);
+ _vertexArray.SetIndexBuffer(buffer.Handle);
}
public void SetPointSize(float size)
@@ -661,7 +674,6 @@ namespace Ryujinx.Graphics.OpenGL
public void SetProgram(IProgram program)
{
_program = (Program)program;
-
_program.Bind();
}
@@ -679,12 +691,12 @@ namespace Ryujinx.Graphics.OpenGL
_rasterizerDiscard = discard;
}
- public void SetRenderTargetColorMasks(uint[] componentMasks)
+ public void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMasks)
{
- _componentMasks = (uint[])componentMasks.Clone();
-
for (int index = 0; index < componentMasks.Length; index++)
{
+ _componentMasks[index] = componentMasks[index];
+
RestoreComponentMask(index);
}
}
@@ -823,21 +835,21 @@ namespace Ryujinx.Graphics.OpenGL
GL.Enable(EnableCap.ClipDistance0 + index);
}
- public void SetVertexAttribs(VertexAttribDescriptor[] vertexAttribs)
+ public void SetVertexAttribs(ReadOnlySpan<VertexAttribDescriptor> vertexAttribs)
{
EnsureVertexArray();
_vertexArray.SetVertexAttributes(vertexAttribs);
}
- public void SetVertexBuffers(VertexBufferDescriptor[] vertexBuffers)
+ public void SetVertexBuffers(ReadOnlySpan<VertexBufferDescriptor> vertexBuffers)
{
EnsureVertexArray();
_vertexArray.SetVertexBuffers(vertexBuffers);
}
- public void SetViewports(int first, Viewport[] viewports)
+ public void SetViewports(int first, ReadOnlySpan<Viewport> viewports)
{
bool flipY = false;
@@ -906,18 +918,16 @@ namespace Ryujinx.Graphics.OpenGL
? BufferRangeTarget.ShaderStorageBuffer
: BufferRangeTarget.UniformBuffer;
- if (buffer.Buffer == null)
+ if (buffer.Handle == null)
{
GL.BindBufferRange(target, bindingPoint, 0, IntPtr.Zero, 0);
return;
}
- int bufferHandle = ((Buffer)buffer.Buffer).Handle;
-
IntPtr bufferOffset = (IntPtr)buffer.Offset;
- GL.BindBufferRange(target, bindingPoint, bufferHandle, bufferOffset, buffer.Size);
+ GL.BindBufferRange(target, bindingPoint, buffer.Handle.ToInt32(), bufferOffset, buffer.Size);
}
private void SetOrigin(ClipOrigin origin)
@@ -997,15 +1007,12 @@ namespace Ryujinx.Graphics.OpenGL
private void RestoreComponentMask(int index)
{
- if (_componentMasks != null)
- {
- GL.ColorMask(
- index,
- (_componentMasks[index] & 1u) != 0,
- (_componentMasks[index] & 2u) != 0,
- (_componentMasks[index] & 4u) != 0,
- (_componentMasks[index] & 8u) != 0);
- }
+ GL.ColorMask(
+ index,
+ (_componentMasks[index] & 1u) != 0,
+ (_componentMasks[index] & 2u) != 0,
+ (_componentMasks[index] & 4u) != 0,
+ (_componentMasks[index] & 8u) != 0);
}
public void RestoreScissor0Enable()
diff --git a/Ryujinx.Graphics.OpenGL/Renderer.cs b/Ryujinx.Graphics.OpenGL/Renderer.cs
index b3ae8c33..15b223f5 100644
--- a/Ryujinx.Graphics.OpenGL/Renderer.cs
+++ b/Ryujinx.Graphics.OpenGL/Renderer.cs
@@ -1,6 +1,7 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
+using Ryujinx.Graphics.OpenGL.Image;
using Ryujinx.Graphics.OpenGL.Queries;
using Ryujinx.Graphics.Shader;
using System;
@@ -38,9 +39,9 @@ namespace Ryujinx.Graphics.OpenGL
return new Shader(shader);
}
- public IBuffer CreateBuffer(int size)
+ public BufferHandle CreateBuffer(int size)
{
- return new Buffer(size);
+ return Buffer.Create(size);
}
public IProgram CreateProgram(IShader[] shaders)
@@ -58,6 +59,16 @@ namespace Ryujinx.Graphics.OpenGL
return info.Target == Target.TextureBuffer ? new TextureBuffer(info) : new TextureStorage(this, info).CreateDefaultView();
}
+ public void DeleteBuffer(BufferHandle buffer)
+ {
+ Buffer.Delete(buffer);
+ }
+
+ public byte[] GetBufferData(BufferHandle buffer, int offset, int size)
+ {
+ return Buffer.GetData(buffer, offset, size);
+ }
+
public Capabilities GetCapabilities()
{
return new Capabilities(
@@ -68,6 +79,11 @@ namespace Ryujinx.Graphics.OpenGL
HwCapabilities.MaxSupportedAnisotropy);
}
+ public void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan<byte> data)
+ {
+ Buffer.SetData(buffer, offset, data);
+ }
+
public void UpdateCounters()
{
_counters.Update();
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);
diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs
index 9f0007c4..6e7ddbac 100644
--- a/Ryujinx.Graphics.OpenGL/Window.cs
+++ b/Ryujinx.Graphics.OpenGL/Window.cs
@@ -1,5 +1,6 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
+using Ryujinx.Graphics.OpenGL.Image;
using System;
namespace Ryujinx.Graphics.OpenGL