Qt5 QPainter vs. QML & Scene Graph.

Document created by Francisco Alberto Carrillo Dominguez Employee on Mar 11, 2013Last modified by Francisco Alberto Carrillo Dominguez Employee on Aug 21, 2013
Version 4Show Document
  • View in full screen mode

With Qt5  you will find the addition of new technologies that will make your development much easier.

 

  • Qtquick2
  • SceneGraph
  • Qml

 

Qt5 is backwards compatible,  that means you can run your Qt 4.8 applications, But that doesn't mean they will have the best performance, sometimes it is better to do a porting to use the newest features.

 

Qt5, has two options to paint components into the screen. Painting in Qt 5 is primarily done either with:

 

  • The imperative QPainter API
  • Qt’s declarative UI language, QML, and its scene graph back-end.


QPainter

As this document mentions  Qt5GraphicsOverview | Qt Wiki | Qt Project  The Qpainter engine uses software to paint, and is used when drawing Qimages or Qwidgets. Its  advantage over OpenGL is the high quality when antialiasing is enabled, and a complete feature set.

The Qpainter can use an OpenGL engine, but as the document mentions it is more suceptible to state changes. And has to be used carefully.


QML & Scene Graph.


All visual QML items are rendered using the scene graph, a low-level, high-performance rendering stack, closely tied to OpenGL.


Qt Quick 2 makes use of a dedicated scene graph based on OpenGL ES 2.0 or OpenGL 2.0 for its rendering. Using a scene graph for graphics rather than the traditional imperative painting systems (QPainter and similar), means the scene to be rendered can be retained between frames and the complete set of primitives to render is known before rendering starts. This opens up for a number of optimizations, such as batch rendering to minimize state changes and discarding obscured primitives.


The QML scene graph is a new back-end for QML in Qt 5, and is based on OpenGL. It generally improves the performance of QML significantly over the QPainter-based back-end used in Qt 4. It achieves better performance in a number of ways:


  • The scene graph uses OpenGL directly instead of going though a QPainter which could be using either the raster or OpenGL paint engine. This means that all the resources, like geometry, textures and shaders can be stored in a format suitable for OpenGL rather than using classes such as QPainterPath, QPixmap, QBrush, or QPen, which the QPainter would need to translate into OpenGL primitives and possibly cache.
  • QML, being a declarative language, defines how the end result should look like, but it doesn’t define how and in which order each individual element is drawn. The drawing can therefore be reordered to reduce the number of state changes, or merged to reduce the number of draw calls.
  • The scene graph uses a separate render thread, and synchronizes the animations with the vertical retrace on platforms where this can be supported. The render thread allows the preparation of the next frame to be done at the same time the current frame is being rendered. This has a positive effect also on single-core systems, since the render thread might block on OpenGL commands. The synchronization with the vertical retrace improves the perceived smoothness of the animations.

 

 

We have tested on i.MX6 Both options, having the best results using QML Qtquick2 elements. When we tried using QtPainter via Widgets we face the problem that if not using a windowing system like X11 or Wayland the painter wont work well and will only show the QtGLWidget.

 

With QML scene graph we are able to have an OpenGL element and a Qt element on the same environment, and there is an easy way to communicate one with the other and share variables.  Please look at the example results here: I.MX6 scene graph Qt5 - YouTube

 

And the great advantage, the sceneGraph is all accelerated via OpenGL.

Attachments

    Outcomes