aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-03-29 23:11:24 -0300
committerGitHub <noreply@github.com>2020-03-30 13:11:24 +1100
commit9948a7be53a9846b9de493653aa76819ff1b9bd3 (patch)
treee5a60c309ac22d3077e6d80c67e03bb4920c0b42
parent8f21db810d0e8dc5577780dee3001117084768d4 (diff)
Support constant attributes (with a value of zero) (#1066)
* Support constant attributes (with a value of zero) * Remove extra line
-rw-r--r--Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs5
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Methods.cs1
-rw-r--r--Ryujinx.Graphics.Gpu/State/VertexAttribState.cs9
-rw-r--r--Ryujinx.Graphics.OpenGL/VertexArray.cs15
4 files changed, 26 insertions, 4 deletions
diff --git a/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs b/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs
index 34daff57..1547658e 100644
--- a/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs
+++ b/Ryujinx.Graphics.GAL/VertexAttribDescriptor.cs
@@ -5,12 +5,15 @@ namespace Ryujinx.Graphics.GAL
public int BufferIndex { get; }
public int Offset { get; }
+ public bool IsZero { get; }
+
public Format Format { get; }
- public VertexAttribDescriptor(int bufferIndex, int offset, Format format)
+ public VertexAttribDescriptor(int bufferIndex, int offset, bool isZero, Format format)
{
BufferIndex = bufferIndex;
Offset = offset;
+ IsZero = isZero;
Format = format;
}
}
diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs
index 0b30e61d..18720440 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs
@@ -532,6 +532,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
vertexAttribs[index] = new VertexAttribDescriptor(
vertexAttrib.UnpackBufferIndex(),
vertexAttrib.UnpackOffset(),
+ vertexAttrib.UnpackIsConstant(),
format);
}
diff --git a/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs b/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs
index 897da797..c22b1ca9 100644
--- a/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs
+++ b/Ryujinx.Graphics.Gpu/State/VertexAttribState.cs
@@ -17,6 +17,15 @@ namespace Ryujinx.Graphics.Gpu.State
}
/// <summary>
+ /// Unpacks the attribute constant flag.
+ /// </summary>
+ /// <returns>True if the attribute is constant, false otherwise</returns>
+ public bool UnpackIsConstant()
+ {
+ return (Attribute & 0x40) != 0;
+ }
+
+ /// <summary>
/// Unpacks the offset, in bytes, of the attribute on the vertex buffer.
/// </summary>
/// <returns>Attribute offset in bytes</returns>
diff --git a/Ryujinx.Graphics.OpenGL/VertexArray.cs b/Ryujinx.Graphics.OpenGL/VertexArray.cs
index 721a90f0..43d200a4 100644
--- a/Ryujinx.Graphics.OpenGL/VertexArray.cs
+++ b/Ryujinx.Graphics.OpenGL/VertexArray.cs
@@ -58,8 +58,17 @@ namespace Ryujinx.Graphics.OpenGL
{
FormatInfo fmtInfo = FormatTable.GetFormatInfo(attrib.Format);
- GL.EnableVertexAttribArray(attribIndex);
-
+ if (attrib.IsZero)
+ {
+ // Disabling the attribute causes the shader to read a constant value.
+ // The value is configurable, but by default is a vector of (0, 0, 0, 1).
+ GL.DisableVertexAttribArray(attribIndex);
+ }
+ else
+ {
+ GL.EnableVertexAttribArray(attribIndex);
+ }
+
int offset = attrib.Offset;
int size = fmtInfo.Components;
@@ -117,7 +126,7 @@ namespace Ryujinx.Graphics.OpenGL
continue;
}
- if (_needsAttribsUpdate)
+ if (_needsAttribsUpdate && !attrib.IsZero)
{
GL.EnableVertexAttribArray(attribIndex);
}