Implement vertex instancing (#381)
This commit is contained in:
parent
da7e702751
commit
a42ab2e40c
7 changed files with 82 additions and 20 deletions
|
@ -126,9 +126,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
|
||||
BindVertexLayout(New);
|
||||
|
||||
if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY)
|
||||
if (New.FlipX != Old.FlipX || New.FlipY != Old.FlipY || New.Instance != Old.Instance)
|
||||
{
|
||||
Shader.SetFlip(New.FlipX, New.FlipY);
|
||||
Shader.SetExtraData(New.FlipX, New.FlipY, New.Instance);
|
||||
}
|
||||
|
||||
//Note: Uncomment SetFrontFace and SetCullFace when flipping issues are solved
|
||||
|
@ -290,8 +290,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
|
||||
private void BindConstBuffers(GalPipelineState New)
|
||||
{
|
||||
//Index 0 is reserved
|
||||
int FreeBinding = 1;
|
||||
int FreeBinding = OGLShader.ReservedCbufCount;
|
||||
|
||||
void BindIfNotNull(OGLShaderStage Stage)
|
||||
{
|
||||
|
@ -385,6 +384,15 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
{
|
||||
GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Binding.Stride, Offset);
|
||||
}
|
||||
|
||||
if (Binding.Instanced && Binding.Divisor != 0)
|
||||
{
|
||||
GL.VertexAttribDivisor(Attrib.Index, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
GL.VertexAttribDivisor(Attrib.Index, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,10 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
{
|
||||
class OGLShader : IGalShader
|
||||
{
|
||||
public const int ReservedCbufCount = 1;
|
||||
|
||||
private const int ExtraDataSize = 4;
|
||||
|
||||
public OGLShaderProgram Current;
|
||||
|
||||
private ConcurrentDictionary<long, OGLShaderStage> Stages;
|
||||
|
@ -96,7 +100,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
return Enumerable.Empty<ShaderDeclInfo>();
|
||||
}
|
||||
|
||||
public unsafe void SetFlip(float X, float Y)
|
||||
public unsafe void SetExtraData(float FlipX, float FlipY, int Instance)
|
||||
{
|
||||
BindProgram();
|
||||
|
||||
|
@ -104,14 +108,15 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
|
||||
GL.BindBuffer(BufferTarget.UniformBuffer, ExtraUboHandle);
|
||||
|
||||
float* Data = stackalloc float[4];
|
||||
Data[0] = X;
|
||||
Data[1] = Y;
|
||||
float* Data = stackalloc float[ExtraDataSize];
|
||||
Data[0] = FlipX;
|
||||
Data[1] = FlipY;
|
||||
Data[2] = BitConverter.Int32BitsToSingle(Instance);
|
||||
|
||||
//Invalidate buffer
|
||||
GL.BufferData(BufferTarget.UniformBuffer, 4 * sizeof(float), IntPtr.Zero, BufferUsageHint.StreamDraw);
|
||||
GL.BufferData(BufferTarget.UniformBuffer, ExtraDataSize * sizeof(float), IntPtr.Zero, BufferUsageHint.StreamDraw);
|
||||
|
||||
GL.BufferSubData(BufferTarget.UniformBuffer, IntPtr.Zero, 4 * sizeof(float), (IntPtr)Data);
|
||||
GL.BufferSubData(BufferTarget.UniformBuffer, IntPtr.Zero, ExtraDataSize * sizeof(float), (IntPtr)Data);
|
||||
}
|
||||
|
||||
public void Bind(long Key)
|
||||
|
@ -197,7 +202,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
|
||||
GL.BindBuffer(BufferTarget.UniformBuffer, ExtraUboHandle);
|
||||
|
||||
GL.BufferData(BufferTarget.UniformBuffer, 4 * sizeof(float), IntPtr.Zero, BufferUsageHint.StreamDraw);
|
||||
GL.BufferData(BufferTarget.UniformBuffer, ExtraDataSize * sizeof(float), IntPtr.Zero, BufferUsageHint.StreamDraw);
|
||||
|
||||
GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, ExtraUboHandle);
|
||||
}
|
||||
|
@ -219,8 +224,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
|
|||
|
||||
GL.UniformBlockBinding(ProgramHandle, ExtraBlockindex, 0);
|
||||
|
||||
//First index is reserved
|
||||
int FreeBinding = 1;
|
||||
int FreeBinding = ReservedCbufCount;
|
||||
|
||||
void BindUniformBlocksIfNotNull(OGLShaderStage Stage)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue