Qt5: Drawing non-convex Polygons
I want to draw a map consisting of hundreds of polygons in a Qt Quick scene (Qt5). To the best of my knowledge, the most convenient way to do that is to use QQuickPaintedItem. I have read in the documentation that using this class in new code is discouraged: "QQuickPaintedItem is meant to make it easier to port old code that is using the QPainter API to the QML Scene Graph API and it should be used only for that purpose."
I would love to use the new scene graph approach but I do not see an easy way of drawing a non-convex polygon. In the Qt5 code base, I found things like QTriangulator and QTriangulatingStroker. Both are part of the private API thus not really a choice.
GLU provides gluTessellate for triangulating polygons and of course there are other 3rd-party libraries which can do that. Is this the way to go at the moment?
Well, QQuickPaintedItem is sometimes the best way to do some things, still.
The other option is to use the Canvas element - it provides a HTML5-like canvas. I'm not sure how performance will be, but ISTR in our internal benchmarks it performed very well (comparatively to browser-based canvas rendering).
See "Canvas":http://doc-snapshot.qt-project.org/5.0/qtquick/qml-qtquick2-canvas.html and "Context2D":http://doc-snapshot.qt-project.org/5.0/qtquick/qml-qtquick2-context2d.html documentation for more info.
The only way to know how big of an impact, is to benchmark it, I guess.
If you want to use pure open gl with QtQuick, I think the best way is to: render to a GL framebuffer object, and define your own QML-registered type which defines its own scene graph geometry node - the material in the node should be the GL framebuffer object to which you're drawing.
Take a look at the Qt3D module in Qt5 for an example of that sort of thing.
Unfortunately I can't help you much beyond what I've already said (as I don't know much about the scene graph extension points or open GL in general, unfortunately), but there are some blog posts by Gunnar Sletta and Kim Kalland which will prove illuminating if you're interested.