QOpenGLPaintDevice Class

The QOpenGLPaintDevice class enables painting to an OpenGL context using QPainter. More...

Header: #include <QOpenGLPaintDevice>
qmake: QT += gui
Since: Qt 5.0
Inherits: QPaintDevice

This class was introduced in Qt 5.0.

Detailed Description

The QOpenGLPaintDevice uses the current QOpenGL context to render QPainter draw commands. The context is captured upon construction. It requires support for OpenGL (ES) 2.0 or higher.

Performance

The QOpenGLPaintDevice is almost always hardware accelerated and has the potential of being much faster than software rasterization. However, it is more sensitive to state changes, and therefore requires the drawing commands to be carefully ordered to achieve optimal performance.

Antialiasing and Quality

Antialiasing in the OpenGL paint engine is done using multisampling. Most hardware require significantly more memory to do multisampling and the resulting quality is not on par with the quality of the software paint engine. The OpenGL paint engine's strength lies in its performance, not its visual rendering quality.

State Changes

When painting to a QOpenGLPaintDevice using QPainter, the state of the current OpenGL context will be altered by the paint engine to reflect its needs. Applications should not rely upon the OpenGL state being reset to its original conditions, particularly the current shader program, OpenGL viewport, texture units, and drawing modes.

Mixing QPainter and OpenGL

When intermixing QPainter and OpenGL, it is important to notify QPainter that the OpenGL state may have been cluttered so it can restore its internal state. This is achieved by calling QPainter::beginNativePainting() before starting the OpenGL rendering and calling QPainter::endNativePainting() after finishing.

See also OpenGL Window Example.