Use quad batch for path drawing

This commit is contained in:
Andrei Zavatski
2026-01-02 16:32:33 +03:00
parent 44725d0b2a
commit 16ba5e1067

View File

@@ -28,7 +28,7 @@ namespace osu.Framework.Graphics.Lines
private float radius;
private IShader? pathShader;
private IVertexBatch<PathVertex>? triangleBatch;
private IVertexBatch<PathVertex>? quadBatch;
public PathDrawNode(Path source)
: base(source)
@@ -53,10 +53,10 @@ namespace osu.Framework.Graphics.Lines
if (segments.Count == 0 || pathShader == null || radius == 0f)
return;
// We multiply the size args by 3 such that the amount of vertices is a multiple of the amount of vertices
// per primitive (triangles in this case). Otherwise overflowing the batch will result in wrong
// Size must be divisible by 4 such that the amount of vertices is a multiple of the amount of vertices
// per primitive (quads in this case). Otherwise overflowing the batch will result in wrong
// grouping of vertices into primitives.
triangleBatch ??= renderer.CreateLinearBatch<PathVertex>(9000, 10, PrimitiveTopology.Triangles);
quadBatch ??= renderer.CreateQuadBatch<PathVertex>(9000, 10);
renderer.PushLocalMatrix(DrawInfo.Matrix);
@@ -156,15 +156,12 @@ namespace osu.Framework.Graphics.Lines
private void drawQuad(Vector2 topLeft, Vector2 topRight, Vector2 bottomLeft, Vector2 bottomRight, Vector2 start, Vector2 end)
{
Debug.Assert(triangleBatch != null);
Debug.Assert(quadBatch != null);
triangleBatch.Add(new PathVertex(topLeft, start, end, radius));
triangleBatch.Add(new PathVertex(topRight, start, end, radius));
triangleBatch.Add(new PathVertex(bottomLeft, start, end, radius));
triangleBatch.Add(new PathVertex(bottomLeft, start, end, radius));
triangleBatch.Add(new PathVertex(topRight, start, end, radius));
triangleBatch.Add(new PathVertex(bottomRight, start, end, radius));
quadBatch.Add(new PathVertex(topLeft, start, end, radius));
quadBatch.Add(new PathVertex(topRight, start, end, radius));
quadBatch.Add(new PathVertex(bottomRight, start, end, radius));
quadBatch.Add(new PathVertex(bottomLeft, start, end, radius));
}
private void updateVertexBuffer()
@@ -237,7 +234,7 @@ namespace osu.Framework.Graphics.Lines
{
base.Dispose(isDisposing);
triangleBatch?.Dispose();
quadBatch?.Dispose();
}
private enum SegmentStartLocation