[Interest] Custom QQuickItem and Geometry Batching

Gunnar Sletta gunnar at sletta.org
Tue Oct 7 12:46:16 CEST 2014


On 07 Oct 2014, at 12:36, Andreas Schuller <andreas.schuller at student.tugraz.at> wrote:

> Hi,
> 
> I would like to implement a QQuickItem, that draws up to thousand 
> objects where each object is composed of a position marker (symbol), a 
> framed text label and a line connecting the marker and the label.
> 
> For the sake of efficiency, I would like to create a geometry node for 
> each type of element (e.g. one node for all lines) and batch together 
> the vertices of the lines, markers (realized as point sprites), and 
> labels (textured quads).
> 
> But doing it this way, the "natural" drawing order (objects should be 
> drawn on top of each other) get lost. I would like to utilize the 
> z-coordinate of the vertices to preserve the drawing order, e.g. by 
> assigning a z-coordinate to each object. But I don't know how to achieve 
> this, since the scene graph renderer also makes use of the z-coordinate 
> and adjusts the model-view-projection matrix accordingly.
> 
> Is it possible to utilize the z-coordinate of the vertices for this 
> purpose (within a QuickItem)? Or is there a better solution?

You have two options. Either you rely on scene graph's internal batching algorithm, (which will probably be sufficient) or you hook your GL up to beforeRendering and do custom GL behind the UI.

If you choose to rely on the internal batching, the only thing you need to take care of is that your lines's materials are equal (QSGMaterial::compare() for all instances will return 0), that your labels compare return 0. The markers need to be changed from point sprites to triangles to allow batching though. We only try to batch GL_TRIANGLE and GL_TRIANGLE_STRIP. 

cheers,
Gunnar

> 
> Thanks,
> 
> Andreas
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest




More information about the Interest mailing list