TextureWriter.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Graphics.Gal;
  3. using System;
  4. namespace Ryujinx.Graphics.Gpu
  5. {
  6. public static class TextureWriter
  7. {
  8. public static void Write(AMemory Memory, Texture Texture, byte[] Data)
  9. {
  10. switch (Texture.Format)
  11. {
  12. case GalTextureFormat.A8B8G8R8: Write4Bpp(Memory, Texture, Data); break;
  13. default:
  14. throw new NotImplementedException(Texture.Format.ToString());
  15. }
  16. }
  17. private unsafe static void Write4Bpp(AMemory Memory, Texture Texture, byte[] Data)
  18. {
  19. int Width = Texture.Width;
  20. int Height = Texture.Height;
  21. ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 4);
  22. fixed (byte* BuffPtr = Data)
  23. {
  24. long InOffs = 0;
  25. for (int Y = 0; Y < Height; Y++)
  26. for (int X = 0; X < Width; X++)
  27. {
  28. long Offset = (uint)Swizzle.GetSwizzleOffset(X, Y);
  29. int Pixel = *(int*)(BuffPtr + InOffs);
  30. Memory.WriteInt32Unchecked(Texture.Position + Offset, Pixel);
  31. InOffs += 4;
  32. }
  33. }
  34. }
  35. }
  36. }