TextureBuffer.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using OpenTK.Graphics.OpenGL;
  2. using Ryujinx.Graphics.GAL;
  3. using System;
  4. namespace Ryujinx.Graphics.OpenGL.Image
  5. {
  6. class TextureBuffer : TextureBase, ITexture
  7. {
  8. private int _bufferOffset;
  9. private int _bufferSize;
  10. private BufferHandle _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(_buffer, _bufferOffset, _bufferSize);
  27. }
  28. public void SetData(ReadOnlySpan<byte> data)
  29. {
  30. Buffer.SetData(_buffer, _bufferOffset, data.Slice(0, Math.Min(data.Length, _bufferSize)));
  31. }
  32. public void SetStorage(BufferRange buffer)
  33. {
  34. if (buffer.Handle == _buffer &&
  35. buffer.Offset == _bufferOffset &&
  36. buffer.Size == _bufferSize)
  37. {
  38. return;
  39. }
  40. _buffer = buffer.Handle;
  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.ToInt32(), (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. public void Release()
  56. {
  57. Dispose();
  58. }
  59. }
  60. }