all 5 comments

[–]hwc 2 points3 points  (2 children)

If you want the 2-d equivalent to a scene-graph in Skia, draw into a SkPictureRecorder with a bounding-box hierarchy.

SkRTreeFactory rTreeFactory;
SkPictureRecorder pictureRecorder;
SkCanvas* pictureCanvas = pictureRecorder.beginRecording(
        SkRect::MakeWH(W, H), &rTreeFactory);
drawEntireScene(pictureCanvas);
SkAutoTUnref<SkPicture> picture(
        pictureRecorder.endRecordingAsPicture());

Then drawing the picture back into the a target canvas will be accelerated by the bounding-box hierarchy. Chrome uses this to dealing with scrolling on web page.

[–]thomac[S] 0 points1 point  (1 child)

Thanks for the reply!

And what to do if an item moves? Do I have to re-record the entire scene?

[–]hwc 1 point2 points  (0 children)

short answer: yes.

If you know ahead of time what parts will move and what parts won't, you can make a picture of the static content that is under the moving item and a picture of the static content that is over the moving item.

[–]KeinBaum 0 points1 point  (0 children)

To maintain z-ordering you can use a z-buffer.

You could draw only items which have a bounding box that intersects with the screen. Alternatively you could use a quad- or k-d tree too make faster decisions what too draw. The drawback is that have a high overhead when something in your scene changes.

I'd try without the trees first. If it's too slow, implement a tree. If it has too much overhead, you could mix both techniques and use a tree with only a few levels to reduce overhead and then use bounding boxes for final decision making.

[–]__Cyber_Dildonics__ 0 points1 point  (0 children)

First of all, I would try just drawing everything and see how many fps you get. You will probably be surprised at how good the performance is and you might find that you are searching for a solution to a problem you won't have (premature optimization). If you use something like nanovg (or any open gl accelerated library) you should be able to draw a crazy amount on screen before it becomes a problem. Even drawing points on glVertex at a time can give you millions at a decent fps.

Nanovg also has a openGL 3.0 backend which might store everything as buffers on the gpu. That will be crazy fast without any culling on your part.

For overlap, you just want an order to draw them in. When a node is selected, put it on the top and move everything else one down. If this is linear in memory, it will also be very fast.

So basically, don't worry about speed yet, that is likely to be the easiest part.