aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.OpenGL/Pipeline.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-01-12 19:14:50 -0300
committerjduncanator <1518948+jduncanator@users.noreply.github.com>2020-01-13 09:14:50 +1100
commit8b90924c1ebf7e65d1f170df5dd1ac6c2596926f (patch)
tree5c10741b0a7e8efc836568c586832d6cc739ee72 /Ryujinx.Graphics.OpenGL/Pipeline.cs
parent2bb39ff03e7f8b4f3383d5a5383dc9cbd808f0b6 (diff)
Support instanced draw of quads" (#881)
Diffstat (limited to 'Ryujinx.Graphics.OpenGL/Pipeline.cs')
-rw-r--r--Ryujinx.Graphics.OpenGL/Pipeline.cs117
1 files changed, 85 insertions, 32 deletions
diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs
index c9d8186f..e308becf 100644
--- a/Ryujinx.Graphics.OpenGL/Pipeline.cs
+++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs
@@ -170,26 +170,35 @@ namespace Ryujinx.Graphics.OpenGL
int firstVertex,
int firstInstance)
{
- // TODO: Instanced rendering.
int quadsCount = (vertexCount - 2) / 2;
- int[] firsts = new int[quadsCount];
- int[] counts = new int[quadsCount];
-
- firsts[0] = firstVertex;
- counts[0] = 4;
-
- for (int quadIndex = 1; quadIndex < quadsCount; quadIndex++)
+ if (firstInstance != 0 || instanceCount != 1)
{
- firsts[quadIndex] = firstVertex + quadIndex * 2;
- counts[quadIndex] = 4;
+ for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
+ {
+ GL.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, instanceCount, firstInstance);
+ }
}
+ else
+ {
+ int[] firsts = new int[quadsCount];
+ int[] counts = new int[quadsCount];
- GL.MultiDrawArrays(
- PrimitiveType.TriangleFan,
- firsts,
- counts,
- quadsCount);
+ firsts[0] = firstVertex;
+ counts[0] = 4;
+
+ for (int quadIndex = 1; quadIndex < quadsCount; quadIndex++)
+ {
+ firsts[quadIndex] = firstVertex + quadIndex * 2;
+ counts[quadIndex] = 4;
+ }
+
+ GL.MultiDrawArrays(
+ PrimitiveType.TriangleFan,
+ firsts,
+ counts,
+ quadsCount);
+ }
}
private void DrawImpl(
@@ -282,31 +291,75 @@ namespace Ryujinx.Graphics.OpenGL
int firstVertex,
int firstInstance)
{
- // TODO: Instanced rendering.
int quadsCount = indexCount / 4;
- IntPtr[] indices = new IntPtr[quadsCount];
+ if (firstInstance != 0 || instanceCount != 1)
+ {
+ if (firstVertex != 0 && firstInstance != 0)
+ {
+ for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
+ {
+ 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];
- int[] counts = new int[quadsCount];
+ int[] counts = new int[quadsCount];
- int[] baseVertices = new int[quadsCount];
+ int[] baseVertices = new int[quadsCount];
- for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
- {
- indices[quadIndex] = indexBaseOffset + quadIndex * 4 * indexElemSize;
+ for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++)
+ {
+ indices[quadIndex] = indexBaseOffset + quadIndex * 4 * indexElemSize;
- counts[quadIndex] = 4;
+ counts[quadIndex] = 4;
- baseVertices[quadIndex] = firstVertex;
- }
+ baseVertices[quadIndex] = firstVertex;
+ }
- GL.MultiDrawElementsBaseVertex(
- PrimitiveType.TriangleFan,
- counts,
- _elementsType,
- indices,
- quadsCount,
- baseVertices);
+ GL.MultiDrawElementsBaseVertex(
+ PrimitiveType.TriangleFan,
+ counts,
+ _elementsType,
+ indices,
+ quadsCount,
+ baseVertices);
+ }
}
private void DrawQuadStripIndexedImpl(