From 5011640b3086b86b0f0b39b60fdb2aa946d4f5c8 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sat, 23 May 2020 06:46:09 -0300 Subject: Spanify Graphics Abstraction Layer (#1226) * Spanify Graphics Abstraction Layer * Be explicit about BufferHandle size --- Ryujinx.Graphics.OpenGL/Buffer.cs | 43 ++++++++++++++------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'Ryujinx.Graphics.OpenGL/Buffer.cs') 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(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 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 data) + public static void SetData(BufferHandle buffer, int offset, ReadOnlySpan 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()); } } } -- cgit v1.2.3