Qt5 QPainter vs. QML & Scene Graph.

cancel
Showing results for 
Search instead for 
Did you mean: 

Qt5 QPainter vs. QML & Scene Graph.

No ratings

Qt5 QPainter vs. QML & Scene Graph.

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.

Comments

FranciscoCarrillo, can you please move this document to the public i.MX Community so that your document there does not point to a doc in a place that external members cannot access?  And then add a post to the below public discussion that reported this problem?

Linked article says "Access to this place or content is restricted..."                    

This question is Not Answered.(Mark as assumed answered)

Stephen Langstaff     Level 1

I'm seeing "Access to this place or content is restricted. If you think this is a mistake, please contact your administrator or the person who directed you here." when trying to access https://community.freescale.com/docs/DOC-94234, pointed to from QT5 Demo Errors on EGLFS.


Thanks,

Grant

hello

I am porting to iMX6 with Qt5.1 a large application, originally based on Qt4.7 and running on iMX35.

My legacy application has lots of 2D drawing based on the QPainter API.

I was hoping to replace QWidget with QGLWidget and get hardware accelerated QPainter API; it looks like this is not the case.

I stay with QPainter I only get software rendering like with Qt 4.7

If I want hardware accelerated 2D rendering then I have to rewrite all drawing code using the gl API.

Is my understanding correct?

Fabio

Version history
Revision #:
1 of 1
Last update:
‎03-11-2013 10:21 AM
Updated by: