TextureBuffer.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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, int srcLayer, int dstLayer, int srcLevel, int dstLevel)
  17. {
  18. throw new NotSupportedException();
  19. }
  20. public void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter)
  21. {
  22. throw new NotSupportedException();
  23. }
  24. public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel)
  25. {
  26. throw new NotSupportedException();
  27. }
  28. public byte[] GetData()
  29. {
  30. return Buffer.GetData(_buffer, _bufferOffset, _bufferSize);
  31. }
  32. public void SetData(ReadOnlySpan<byte> data)
  33. {
  34. Buffer.SetData(_buffer, _bufferOffset, data.Slice(0, Math.Min(data.Length, _bufferSize)));
  35. }
  36. public void SetData(ReadOnlySpan<byte> data, int layer, int level)
  37. {
  38. throw new NotSupportedException();
  39. }
  40. public void SetStorage(BufferRange buffer)
  41. {
  42. if (buffer.Handle == _buffer &&
  43. buffer.Offset == _bufferOffset &&
  44. buffer.Size == _bufferSize)
  45. {
  46. return;
  47. }
  48. _buffer = buffer.Handle;
  49. _bufferOffset = buffer.Offset;
  50. _bufferSize = buffer.Size;
  51. Bind(0);
  52. SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).PixelInternalFormat;
  53. GL.TexBufferRange(TextureBufferTarget.TextureBuffer, format, _buffer.ToInt32(), (IntPtr)buffer.Offset, buffer.Size);
  54. }
  55. public void Dispose()
  56. {
  57. if (Handle != 0)
  58. {
  59. GL.DeleteTexture(Handle);
  60. Handle = 0;
  61. }
  62. }
  63. public void Release()
  64. {
  65. Dispose();
  66. }
  67. }
  68. }