2018-10-13 03:37:01 +02:00
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics
|
|
|
|
{
|
|
|
|
static class QuadHelper
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
public static int ConvertSizeQuadsToTris(int size)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return size <= 0 ? 0 : (size / 4) * 6;
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static int ConvertSizeQuadStripToTris(int size)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return size <= 1 ? 0 : ((size - 2) / 2) * 6;
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static byte[] ConvertQuadsToTris(byte[] data, int entrySize, int count)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int primitivesCount = count / 4;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int quadPrimSize = 4 * entrySize;
|
|
|
|
int trisPrimSize = 6 * entrySize;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
byte[] output = new byte[primitivesCount * 6 * entrySize];
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int prim = 0; prim < primitivesCount; prim++)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
void AssignIndex(int src, int dst, int copyCount = 1)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
src = prim * quadPrimSize + src * entrySize;
|
|
|
|
dst = prim * trisPrimSize + dst * entrySize;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
Buffer.BlockCopy(data, src, output, dst, copyCount * entrySize);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//0 1 2 -> 0 1 2.
|
|
|
|
AssignIndex(0, 0, 3);
|
|
|
|
|
|
|
|
//2 3 -> 3 4.
|
|
|
|
AssignIndex(2, 3, 2);
|
|
|
|
|
|
|
|
//0 -> 5.
|
|
|
|
AssignIndex(0, 5);
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return output;
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static byte[] ConvertQuadStripToTris(byte[] data, int entrySize, int count)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int primitivesCount = (count - 2) / 2;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
int quadPrimSize = 2 * entrySize;
|
|
|
|
int trisPrimSize = 6 * entrySize;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
byte[] output = new byte[primitivesCount * 6 * entrySize];
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
for (int prim = 0; prim < primitivesCount; prim++)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
void AssignIndex(int src, int dst, int copyCount = 1)
|
2018-10-13 03:37:01 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
src = prim * quadPrimSize + src * entrySize + 2 * entrySize;
|
|
|
|
dst = prim * trisPrimSize + dst * entrySize;
|
2018-10-13 03:37:01 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
Buffer.BlockCopy(data, src, output, dst, copyCount * entrySize);
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//-2 -1 0 -> 0 1 2.
|
|
|
|
AssignIndex(-2, 0, 3);
|
|
|
|
|
|
|
|
//0 1 -> 3 4.
|
|
|
|
AssignIndex(0, 3, 2);
|
|
|
|
|
|
|
|
//-2 -> 5.
|
|
|
|
AssignIndex(-2, 5);
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return output;
|
2018-10-13 03:37:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|