2018-06-26 05:10:54 +00:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
2018-07-19 19:02:51 +00:00
|
|
|
using System;
|
2018-06-26 05:10:54 +00:00
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
class OglStreamBuffer : IDisposable
|
2018-06-26 05:10:54 +00:00
|
|
|
{
|
|
|
|
public int Handle { get; protected set; }
|
|
|
|
|
2018-08-10 04:09:40 +00:00
|
|
|
public long Size { get; protected set; }
|
2018-06-26 05:10:54 +00:00
|
|
|
|
|
|
|
protected BufferTarget Target { get; private set; }
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public OglStreamBuffer(BufferTarget target, long size)
|
2018-06-26 05:10:54 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
Target = target;
|
|
|
|
Size = size;
|
2018-06-26 05:10:54 +00:00
|
|
|
|
2018-07-19 19:02:51 +00:00
|
|
|
Handle = GL.GenBuffer();
|
2018-06-26 05:10:54 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GL.BindBuffer(target, Handle);
|
2018-06-26 05:10:54 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GL.BufferData(target, (IntPtr)size, IntPtr.Zero, BufferUsageHint.StreamDraw);
|
2018-06-26 05:10:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public void SetData(long size, IntPtr hostAddress)
|
2018-06-26 05:10:54 +00:00
|
|
|
{
|
2018-07-19 19:02:51 +00:00
|
|
|
GL.BindBuffer(Target, Handle);
|
2018-06-26 05:10:54 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GL.BufferSubData(Target, IntPtr.Zero, (IntPtr)size, hostAddress);
|
2018-06-26 05:10:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public void SetData(byte[] data)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
|
|
|
GL.BindBuffer(Target, Handle);
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GL.BufferSubData(Target, IntPtr.Zero, (IntPtr)data.Length, data);
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 05:10:54 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-06-26 05:10:54 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (disposing && Handle != 0)
|
2018-06-26 05:10:54 +00:00
|
|
|
{
|
|
|
|
GL.DeleteBuffer(Handle);
|
|
|
|
|
|
|
|
Handle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-26 05:30:46 +00:00
|
|
|
}
|