TextureBuffer.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using OpenTK.Graphics.OpenGL;
  2. using Ryujinx.Graphics.GAL;
  3. using System;
  4. namespace Ryujinx.Graphics.OpenGL
  5. {
  6. class TextureBuffer : TextureBase, ITexture
  7. {
  8. private int _bufferOffset;
  9. private int _bufferSize;
  10. private Buffer _buffer;
  11. public TextureBuffer(TextureCreateInfo info) : base(info) {}
  12. public void CopyTo(ITexture destination, int firstLayer, int firstLevel)
  13. {
  14. throw new NotSupportedException();
  15. }
  16. public void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter)
  17. {
  18. throw new NotSupportedException();
  19. }
  20. public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel)
  21. {
  22. throw new NotSupportedException();
  23. }
  24. public byte[] GetData()
  25. {
  26. return _buffer?.GetData(_bufferOffset, _bufferSize);
  27. }
  28. public void SetData(ReadOnlySpan<byte> data)
  29. {
  30. _buffer?.SetData(_bufferOffset, data.Slice(0, Math.Min(data.Length, _bufferSize)));
  31. }
  32. public void SetStorage(BufferRange buffer)
  33. {
  34. if (buffer.Buffer == _buffer &&
  35. buffer.Offset == _bufferOffset &&
  36. buffer.Size == _bufferSize)
  37. {
  38. return;
  39. }
  40. _buffer = (Buffer)buffer.Buffer;
  41. _bufferOffset = buffer.Offset;
  42. _bufferSize = buffer.Size;
  43. Bind(0);
  44. SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).PixelInternalFormat;
  45. GL.TexBufferRange(TextureBufferTarget.TextureBuffer, format, _buffer.Handle, (IntPtr)buffer.Offset, buffer.Size);
  46. }
  47. public void Dispose()
  48. {
  49. if (Handle != 0)
  50. {
  51. GL.DeleteTexture(Handle);
  52. Handle = 0;
  53. }
  54. }
  55. }
  56. }