ImageArray.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using OpenTK.Graphics.OpenGL;
  2. using Ryujinx.Graphics.GAL;
  3. using System;
  4. namespace Ryujinx.Graphics.OpenGL.Image
  5. {
  6. class ImageArray : IImageArray
  7. {
  8. private record struct TextureRef
  9. {
  10. public int Handle;
  11. public Format Format;
  12. }
  13. private readonly TextureRef[] _images;
  14. public ImageArray(int size)
  15. {
  16. _images = new TextureRef[size];
  17. }
  18. public void SetFormats(int index, GAL.Format[] imageFormats)
  19. {
  20. for (int i = 0; i < imageFormats.Length; i++)
  21. {
  22. _images[index + i].Format = imageFormats[i];
  23. }
  24. }
  25. public void SetImages(int index, ITexture[] images)
  26. {
  27. for (int i = 0; i < images.Length; i++)
  28. {
  29. ITexture image = images[i];
  30. if (image is TextureBase imageBase)
  31. {
  32. _images[index + i].Handle = imageBase.Handle;
  33. }
  34. else
  35. {
  36. _images[index + i].Handle = 0;
  37. }
  38. }
  39. }
  40. public void Bind(int baseBinding)
  41. {
  42. for (int i = 0; i < _images.Length; i++)
  43. {
  44. if (_images[i].Handle == 0)
  45. {
  46. GL.BindImageTexture(baseBinding + i, 0, 0, true, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8);
  47. }
  48. else
  49. {
  50. SizedInternalFormat format = FormatTable.GetImageFormat(_images[i].Format);
  51. if (format != 0)
  52. {
  53. GL.BindImageTexture(baseBinding + i, _images[i].Handle, 0, true, 0, TextureAccess.ReadWrite, format);
  54. }
  55. }
  56. }
  57. }
  58. public void Dispose()
  59. {
  60. }
  61. }
  62. }