Support constant attributes (with a value of zero)

This commit is contained in:
gdkchan 2020-03-28 19:14:05 -03:00
commit c7f3b337f0
4 changed files with 26 additions and 3 deletions

View file

@ -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;
}
}

View file

@ -506,6 +506,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
vertexAttribs[index] = new VertexAttribDescriptor(
vertexAttrib.UnpackBufferIndex(),
vertexAttrib.UnpackOffset(),
vertexAttrib.UnpackIsConstant(),
format);
}

View file

@ -16,6 +16,15 @@ namespace Ryujinx.Graphics.Gpu.State
return (int)(Attribute & 0x1f);
}
/// <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>

View file

@ -58,7 +58,17 @@ namespace Ryujinx.Graphics.OpenGL
{
FormatInfo fmtInfo = FormatTable.GetFormatInfo(attrib.Format);
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 +127,7 @@ namespace Ryujinx.Graphics.OpenGL
continue;
}
if (_needsAttribsUpdate)
if (_needsAttribsUpdate && !attrib.IsZero)
{
GL.EnableVertexAttribArray(attribIndex);
}