|
|
@@ -1,9 +1,9 @@
|
|
|
-using System;
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
+using System;
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
{
|
|
|
- abstract class OGLStreamBuffer : IDisposable
|
|
|
+ class OGLStreamBuffer : IDisposable
|
|
|
{
|
|
|
public int Handle { get; protected set; }
|
|
|
|
|
|
@@ -11,53 +11,25 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
|
|
|
protected BufferTarget Target { get; private set; }
|
|
|
|
|
|
- private bool Mapped = false;
|
|
|
-
|
|
|
- public OGLStreamBuffer(BufferTarget Target, int MaxSize)
|
|
|
+ public OGLStreamBuffer(BufferTarget Target, int Size)
|
|
|
{
|
|
|
- Handle = 0;
|
|
|
- Mapped = false;
|
|
|
-
|
|
|
this.Target = Target;
|
|
|
- this.Size = MaxSize;
|
|
|
- }
|
|
|
+ this.Size = Size;
|
|
|
|
|
|
- public static OGLStreamBuffer Create(BufferTarget Target, int MaxSize)
|
|
|
- {
|
|
|
- //TODO: Query here for ARB_buffer_storage and use when available
|
|
|
- return new SubDataBuffer(Target, MaxSize);
|
|
|
- }
|
|
|
-
|
|
|
- public byte[] Map(int Size)
|
|
|
- {
|
|
|
- if (Handle == 0 || Mapped || Size > this.Size)
|
|
|
- {
|
|
|
- throw new InvalidOperationException();
|
|
|
- }
|
|
|
+ Handle = GL.GenBuffer();
|
|
|
|
|
|
- byte[] Memory = InternMap(Size);
|
|
|
-
|
|
|
- Mapped = true;
|
|
|
+ GL.BindBuffer(Target, Handle);
|
|
|
|
|
|
- return Memory;
|
|
|
+ GL.BufferData(Target, Size, IntPtr.Zero, BufferUsageHint.StreamDraw);
|
|
|
}
|
|
|
|
|
|
- public void Unmap(int UsedSize)
|
|
|
+ public void SetData(int Size, IntPtr HostAddress)
|
|
|
{
|
|
|
- if (Handle == 0 || !Mapped)
|
|
|
- {
|
|
|
- throw new InvalidOperationException();
|
|
|
- }
|
|
|
-
|
|
|
- InternUnmap(UsedSize);
|
|
|
+ GL.BindBuffer(Target, Handle);
|
|
|
|
|
|
- Mapped = false;
|
|
|
+ GL.BufferSubData(Target, IntPtr.Zero, Size, HostAddress);
|
|
|
}
|
|
|
|
|
|
- protected abstract byte[] InternMap(int Size);
|
|
|
-
|
|
|
- protected abstract void InternUnmap(int UsedSize);
|
|
|
-
|
|
|
public void Dispose()
|
|
|
{
|
|
|
Dispose(true);
|
|
|
@@ -73,41 +45,4 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- class SubDataBuffer : OGLStreamBuffer
|
|
|
- {
|
|
|
- private byte[] Memory;
|
|
|
-
|
|
|
- public SubDataBuffer(BufferTarget Target, int MaxSize)
|
|
|
- : base(Target, MaxSize)
|
|
|
- {
|
|
|
- Memory = new byte[MaxSize];
|
|
|
-
|
|
|
- GL.GenBuffers(1, out int Handle);
|
|
|
-
|
|
|
- GL.BindBuffer(Target, Handle);
|
|
|
-
|
|
|
- GL.BufferData(Target, Size, IntPtr.Zero, BufferUsageHint.StreamDraw);
|
|
|
-
|
|
|
- this.Handle = Handle;
|
|
|
- }
|
|
|
-
|
|
|
- protected override byte[] InternMap(int Size)
|
|
|
- {
|
|
|
- return Memory;
|
|
|
- }
|
|
|
-
|
|
|
- protected override void InternUnmap(int UsedSize)
|
|
|
- {
|
|
|
- GL.BindBuffer(Target, Handle);
|
|
|
-
|
|
|
- unsafe
|
|
|
- {
|
|
|
- fixed (byte* MemoryPtr = Memory)
|
|
|
- {
|
|
|
- GL.BufferSubData(Target, IntPtr.Zero, UsedSize, (IntPtr)MemoryPtr);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|