Skip to content

Commit

Permalink
TriangleStrip batching
Browse files Browse the repository at this point in the history
  • Loading branch information
Terria-K committed Jan 21, 2025
1 parent 8081d1f commit 34482e0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Riateu/Core/GameContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal static void Init(GraphicsDevice device, Window mainWindow)
))
.SetDepthStenctilState(DepthStencilState.DepthReadWrite)
.SetMultisampleState(MultisampleState.None)
.SetPrimitiveType(PrimitiveType.TriangleList)
.SetPrimitiveType(PrimitiveType.TriangleStrip)
.SetRasterizerState(RasterizerState.CCW_CullNone)

.Build(device)
Expand Down
2 changes: 1 addition & 1 deletion Riateu/Core/Graphics/Batch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void Render(RenderPass renderPass)
renderPass.BindStorageVertexBuffer(batchBuffer);
renderPass.BindFragmentSampler(start.Binding);
start.Material.BindUniforms(new UniformBinder());
renderPass.DrawPrimitives(start.Count * 6u, 1, start.Offset * 6);
renderPass.DrawPrimitives(4, start.Count, 0, start.Offset);

start = ref Unsafe.Add(ref start, 1);
}
Expand Down
Binary file modified Riateu/Core/Misc/Compiled/Spritebatch.vert.spv
Binary file not shown.
9 changes: 4 additions & 5 deletions Riateu/Core/Misc/Shaders/Spritebatch.vert.slang
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ static const float2 vertices[4] = {
{ 0.0f, 1.0f },
{ 1.0f, 1.0f },
};
static const uint indices[6] = { 0, 1, 2, 2, 1, 3 };

[shader("vertex")]
VertexOutput main(uint id: SV_VertexID)
VertexOutput main(uint id: SV_VertexID, uint instanceID: SV_InstanceID)
{
uint spriteIndex = id / 6;
SpriteBatchData sprite = BatchDataBuffer[spriteIndex];
uint spriteIndex = id / 4;
SpriteBatchData sprite = BatchDataBuffer[instanceID];

uint vert = indices[id - spriteIndex * 6];
uint vert = id - spriteIndex * 4;

float c = cos(sprite.Rotation);
float s = sin(sprite.Rotation);
Expand Down

0 comments on commit 34482e0

Please sign in to comment.