QuadHelper.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. namespace Ryujinx.Graphics
  3. {
  4. static class QuadHelper
  5. {
  6. public static int ConvertIbSizeQuadsToTris(int Size)
  7. {
  8. return Size <= 0 ? 0 : (Size / 4) * 6;
  9. }
  10. public static int ConvertIbSizeQuadStripToTris(int Size)
  11. {
  12. return Size <= 1 ? 0 : ((Size - 2) / 2) * 6;
  13. }
  14. public static byte[] ConvertIbQuadsToTris(byte[] Data, int EntrySize, int Count)
  15. {
  16. int PrimitivesCount = Count / 4;
  17. int QuadPrimSize = 4 * EntrySize;
  18. int TrisPrimSize = 6 * EntrySize;
  19. byte[] Output = new byte[PrimitivesCount * 6 * EntrySize];
  20. for (int Prim = 0; Prim < PrimitivesCount; Prim++)
  21. {
  22. void AssignIndex(int Src, int Dst, int CopyCount = 1)
  23. {
  24. Src = Prim * QuadPrimSize + Src * EntrySize;
  25. Dst = Prim * TrisPrimSize + Dst * EntrySize;
  26. Buffer.BlockCopy(Data, Src, Output, Dst, CopyCount * EntrySize);
  27. }
  28. //0 1 2 -> 0 1 2.
  29. AssignIndex(0, 0, 3);
  30. //2 3 -> 3 4.
  31. AssignIndex(2, 3, 2);
  32. //0 -> 5.
  33. AssignIndex(0, 5);
  34. }
  35. return Output;
  36. }
  37. public static byte[] ConvertIbQuadStripToTris(byte[] Data, int EntrySize, int Count)
  38. {
  39. int PrimitivesCount = (Count - 2) / 2;
  40. int QuadPrimSize = 2 * EntrySize;
  41. int TrisPrimSize = 6 * EntrySize;
  42. byte[] Output = new byte[PrimitivesCount * 6 * EntrySize];
  43. for (int Prim = 0; Prim < PrimitivesCount; Prim++)
  44. {
  45. void AssignIndex(int Src, int Dst, int CopyCount = 1)
  46. {
  47. Src = Prim * QuadPrimSize + Src * EntrySize + 2 * EntrySize;
  48. Dst = Prim * TrisPrimSize + Dst * EntrySize;
  49. Buffer.BlockCopy(Data, Src, Output, Dst, CopyCount * EntrySize);
  50. }
  51. //-2 -1 0 -> 0 1 2.
  52. AssignIndex(-2, 0, 3);
  53. //0 1 -> 3 4.
  54. AssignIndex(0, 3, 2);
  55. //-2 -> 5.
  56. AssignIndex(-2, 5);
  57. }
  58. return Output;
  59. }
  60. }
  61. }