OGLStreamBuffer.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. namespace Ryujinx.Graphics.Gal.OpenGL
  4. {
  5. class OGLStreamBuffer : IDisposable
  6. {
  7. public int Handle { get; protected set; }
  8. public long Size { get; protected set; }
  9. protected BufferTarget Target { get; private set; }
  10. public OGLStreamBuffer(BufferTarget Target, long Size)
  11. {
  12. this.Target = Target;
  13. this.Size = Size;
  14. Handle = GL.GenBuffer();
  15. GL.BindBuffer(Target, Handle);
  16. GL.BufferData(Target, (IntPtr)Size, IntPtr.Zero, BufferUsageHint.StreamDraw);
  17. }
  18. public void SetData(long Size, IntPtr HostAddress)
  19. {
  20. GL.BindBuffer(Target, Handle);
  21. GL.BufferSubData(Target, IntPtr.Zero, (IntPtr)Size, HostAddress);
  22. }
  23. public void Dispose()
  24. {
  25. Dispose(true);
  26. }
  27. protected virtual void Dispose(bool Disposing)
  28. {
  29. if (Disposing && Handle != 0)
  30. {
  31. GL.DeleteBuffer(Handle);
  32. Handle = 0;
  33. }
  34. }
  35. }
  36. }