I’m trying to draw a large amount of arcs with the painter API and is running into the 65535 vertices limit. For lines, it is easy to split the data into multiple stroke as the vertex count is predictable. But for arcs, it is unclear how many vertices will be generated for each arc.
Is there a way to solve this without using a very conservative limit per stroke? It would be nice if there’s a way to query the current vertex count, as well as a way to handle the error gracefully.
Can you give more details about how you use the Painter2D API? Do you create a bunch of arcs and stroke them all at once? If so, stroking each arc may be a viable solution. The actual stroke tessellation will be jobified behind the scene, so you may even get a perf boost by doing individual strokes.
Right now I’m just pushing the limit of the API. The goal is to draw a scatter plot.
Stroking each individual arc is what I tried at first, and it is significantly slower for me.
using UnityEngine;
using UnityEngine.UIElements;
namespace MyGameUILibrary
{
[UxmlElement]
public partial class RadialProgress : VisualElement
{
public RadialProgress()
{
RegisterCallback<ClickEvent>(evt => MarkDirtyRepaint());
RegisterCallback<MouseMoveEvent>(evt => MarkDirtyRepaint());
generateVisualContent += GenerateVisualContent;
}
void GenerateVisualContent(MeshGenerationContext context)
{
float width = contentRect.width;
float height = contentRect.height;
var painter = context.painter2D;
// for (int il = 0; il < 8; il++)
// {
// painter.BeginPath();
// for (int ix = 0; ix < 2000; ix++)
// {
// var coord = new Vector2(Random.value * width, Random.value * height);
// painter.MoveTo(coord + Vector2.right * 4);
// painter.Arc(coord, 4, 0, 360);
// }
// painter.Stroke();
// }
for (int ix = 0; ix < 8 * 2000; ix++)
{
painter.BeginPath();
var coord = new Vector2(Random.value * width, Random.value * height);
painter.MoveTo(coord + Vector2.right * 4);
painter.Arc(coord, 4, 0, 360);
painter.Stroke();
}
}
}
}
As a side note, small arcs are currently drawn with tiny triangles. Since UI Toolkit uber shader can already draw circle, may be it wouldn’t be too much work to emit less triangles and draw the arc in the pixel shader instead?
I’ll give it a shot to see where the bottleneck is. In the short-term, it may make sense to do a compromise and trigger a stroke every hundred arc, or something like that.
Yes I think that would make sense to have an optimized path for that. Thanks!