mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-28 10:00:50 +01:00
Support instanced draw of quads" (#881)
This commit is contained in:
parent
2bb39ff03e
commit
8b90924c1e
@ -170,26 +170,35 @@ namespace Ryujinx.Graphics.OpenGL
|
|||||||
int firstVertex,
|
int firstVertex,
|
||||||
int firstInstance)
|
int firstInstance)
|
||||||
{
|
{
|
||||||
// TODO: Instanced rendering.
|
|
||||||
int quadsCount = (vertexCount - 2) / 2;
|
int quadsCount = (vertexCount - 2) / 2;
|
||||||
|
|
||||||
int[] firsts = new int[quadsCount];
|
if (firstInstance != 0 || instanceCount != 1)
|
||||||
int[] counts = new int[quadsCount];
|
|
||||||
|
|
||||||
firsts[0] = firstVertex;
|
|
||||||
counts[0] = 4;
|
|
||||||
|
|
||||||
for (int quadIndex = 1; quadIndex < quadsCount; quadIndex++)
|
|
||||||
{
|
{
|
||||||
firsts[quadIndex] = firstVertex + quadIndex * 2;
|
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
|
||||||
counts[quadIndex] = 4;
|
{
|
||||||
|
GL.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, instanceCount, firstInstance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int[] firsts = new int[quadsCount];
|
||||||
|
int[] counts = new int[quadsCount];
|
||||||
|
|
||||||
GL.MultiDrawArrays(
|
firsts[0] = firstVertex;
|
||||||
PrimitiveType.TriangleFan,
|
counts[0] = 4;
|
||||||
firsts,
|
|
||||||
counts,
|
for (int quadIndex = 1; quadIndex < quadsCount; quadIndex++)
|
||||||
quadsCount);
|
{
|
||||||
|
firsts[quadIndex] = firstVertex + quadIndex * 2;
|
||||||
|
counts[quadIndex] = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
GL.MultiDrawArrays(
|
||||||
|
PrimitiveType.TriangleFan,
|
||||||
|
firsts,
|
||||||
|
counts,
|
||||||
|
quadsCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawImpl(
|
private void DrawImpl(
|
||||||
@ -282,31 +291,75 @@ namespace Ryujinx.Graphics.OpenGL
|
|||||||
int firstVertex,
|
int firstVertex,
|
||||||
int firstInstance)
|
int firstInstance)
|
||||||
{
|
{
|
||||||
// TODO: Instanced rendering.
|
|
||||||
int quadsCount = indexCount / 4;
|
int quadsCount = indexCount / 4;
|
||||||
|
|
||||||
IntPtr[] indices = new IntPtr[quadsCount];
|
if (firstInstance != 0 || instanceCount != 1)
|
||||||
|
|
||||||
int[] counts = new int[quadsCount];
|
|
||||||
|
|
||||||
int[] baseVertices = new int[quadsCount];
|
|
||||||
|
|
||||||
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
|
|
||||||
{
|
{
|
||||||
indices[quadIndex] = indexBaseOffset + quadIndex * 4 * indexElemSize;
|
if (firstVertex != 0 && firstInstance != 0)
|
||||||
|
{
|
||||||
counts[quadIndex] = 4;
|
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
|
||||||
|
{
|
||||||
baseVertices[quadIndex] = firstVertex;
|
GL.DrawElementsInstancedBaseVertexBaseInstance(
|
||||||
|
PrimitiveType.TriangleFan,
|
||||||
|
4,
|
||||||
|
_elementsType,
|
||||||
|
indexBaseOffset + quadIndex * 4 * indexElemSize,
|
||||||
|
instanceCount,
|
||||||
|
firstVertex,
|
||||||
|
firstInstance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (firstInstance != 0)
|
||||||
|
{
|
||||||
|
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
|
||||||
|
{
|
||||||
|
GL.DrawElementsInstancedBaseInstance(
|
||||||
|
PrimitiveType.TriangleFan,
|
||||||
|
4,
|
||||||
|
_elementsType,
|
||||||
|
indexBaseOffset + quadIndex * 4 * indexElemSize,
|
||||||
|
instanceCount,
|
||||||
|
firstInstance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
|
||||||
|
{
|
||||||
|
GL.DrawElementsInstanced(
|
||||||
|
PrimitiveType.TriangleFan,
|
||||||
|
4,
|
||||||
|
_elementsType,
|
||||||
|
indexBaseOffset + quadIndex * 4 * indexElemSize,
|
||||||
|
instanceCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IntPtr[] indices = new IntPtr[quadsCount];
|
||||||
|
|
||||||
GL.MultiDrawElementsBaseVertex(
|
int[] counts = new int[quadsCount];
|
||||||
PrimitiveType.TriangleFan,
|
|
||||||
counts,
|
int[] baseVertices = new int[quadsCount];
|
||||||
_elementsType,
|
|
||||||
indices,
|
for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
|
||||||
quadsCount,
|
{
|
||||||
baseVertices);
|
indices[quadIndex] = indexBaseOffset + quadIndex * 4 * indexElemSize;
|
||||||
|
|
||||||
|
counts[quadIndex] = 4;
|
||||||
|
|
||||||
|
baseVertices[quadIndex] = firstVertex;
|
||||||
|
}
|
||||||
|
|
||||||
|
GL.MultiDrawElementsBaseVertex(
|
||||||
|
PrimitiveType.TriangleFan,
|
||||||
|
counts,
|
||||||
|
_elementsType,
|
||||||
|
indices,
|
||||||
|
quadsCount,
|
||||||
|
baseVertices);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawQuadStripIndexedImpl(
|
private void DrawQuadStripIndexedImpl(
|
||||||
|
Loading…
Reference in New Issue
Block a user