DrawPoints (large array)

174 views
Skip to first unread message

Tiko Tiko

unread,
Apr 28, 2024, 10:29:51 AM4/28/24
to skia-discuss
Hello,

I am writing a control that will be used to display a scatter plot of points, the points need to be drawn with transparency so that you can see where they congregate. The control also supports zoom and pan so the user can explore the data.

To draw the points, I am using SkCanvas Drawpoints, which from SkiaSharp is exposed via https://learn.microsoft.com/en-us/dotnet/api/skiasharp.skcanvas.drawpoints?view=skiasharp-2.88

I am using Points for the mode, and a stroke cap of round so I get nice round points.

However, performance isn't great for large arrays (upwards of 100k points).

I can improve the performance by using a stroke cap of square, but I was wondering if there is another approach I could be using for this? From the documentation, it says that points are drawn one at a time, so was wondering if there is a better way to do it?

Thank you

Untitled.png

Brian Osman

unread,
Apr 28, 2024, 10:40:12 AM4/28/24
to skia-d...@googlegroups.com
I haven't verified this, but I suspect that using DrawAtlas [1] will be quicker for your situation. You'd make a single circle image (just draw a circle to a small bitmap object), and then specify a rectangle for each data point you want to draw, with the "rotation/scale" matrix object just being the identity. That should produce a single draw call (or perhaps just a few, depending on vertex count limits), effectively applying the circle image as a texture to each square.


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/f1d94e0d-8b26-4c39-8568-5b62dba12e51n%40googlegroups.com.

Tiko Tiko

unread,
Apr 28, 2024, 1:03:13 PM4/28/24
to skia-discuss
Thanks for this. 

It did indeed give it a performance boost (about 3 times quicker)

Oh, and it was the other way around for the rects/Transforms :)

Tiko Tiko

unread,
Apr 29, 2024, 5:48:41 AM4/29/24
to skia-discuss
I have just been looking at the C++ source for Draw Atlas and internally, it just uses DrawVertices.

Although the DrawAtlas performs better, it's still a little laggy. I think one of the inefficiencies is that every time I have to update it,  DrawVertices is rebuilding the vertex buffer.

I was wondering if the following is possible?

- Create a fixed vertex buffer with all 200k points (this wont change)
- Have the shader render all points, transforming them into the correct view space using zoom/pan shader transform params

Basically, instead of doing the Zoom/Pan on the CPU and creating a new vertex buffer each time, create a "static" vertex buffer that is instead transformed in the shader? That way, the only thing that needs updating on the GPU is the Zoom/Pan tranforms?

I have found examples of screen space effects using skia shaders, but haven't found anything like the above that works with a vertex buffer? Is this possible with Skia do you know?  

Thanks
Ben
Reply all
Reply to author
Forward
0 new messages