Efficient off-screen rendering of QPainterPaths (OpenGL and non-OpenGL solution required)

Viewed 4869
  1. In my application, I paint a street map using QPainter on a widget
    • made by QPainterPaths that contain precalculated paths to be drawn
    • the widget is currently a QWidget, not a QGLWidget, but this might change.
  2. I'm trying to move the painting off-screen and split it into chunked jobs
    • I want to paint each chunk onto a QImage and finally draw all images onto the widget
    • QPainterPaths are already chunked, so this is not the problem
    • problem is, that drawing on QImages is about 5 times slower than drawing on QWidget
  3. Some benchmark testing I've done
    • time values are rounded averages over multiple runs
    • test chunk contains 100 QPainterPaths that have about 150 linear line segments each
    • the roughly 15k paths are drawn with QPainter::Antialiasing render hint, QPen uses round cap and round join
  4. Remember that my source are QPainterPaths (and line width + color; some drawn, some filled)
    • I don't need all the other types of drawing QPainter supports
    • Can QPainterPaths be converted to something else which can be drawn on a OpenGL buffer, this would be a good solution.
    • I'm not familiar with OpenGL off-screen rendering and I know that there are different types of OpenGL buffers, of which most of them aren't for 2D image rendering but for vertex data.
Paint Device for chunk | Rendering the chunk itself | Painting chunk on QWidget
-----------------------+----------------------------+--------------------------
QImage                 |                    2000 ms |                   < 10 ms
QPixmap (*)            |                     250 ms |                   < 10 ms
QGLFramebufferObj. (*) |                      50 ms |                   < 10 ms
QPicture               |                      50 ms |                    400 ms
-----------------------+----------------------------+--------------------------
none (directly on a QWidget in paintEvent)          |                    400 ms
----------------------------------------------------+--------------------------

(*) These 2 lines have been added afterwards and are solutions to the problem!

It would be nice if you can tell me a non-OpenGL-based solution, too, as I want to compile my application in two versions: OpenGL and non-OpenGL version.
Also, I want the solution to be able to render in a non-GUI thread.


Is there a good way to efficiently draw the chunks off-screen?
Is there an off-screen counter part of QGLWidget (an OpenGL off-screen buffer) which can be used as a paint device for QPainter?

1 Answers
Related