QQuickRenderControl Class
The QQuickRenderControl class provides a mechanism for rendering the Qt Quick scenegraph onto an offscreen render target in a fully application-controlled manner. More...
| Header: | #include <QQuickRenderControl> |
| qmake: | QT += quick |
| Since: | Qt 5.4 |
| Inherits: | QObject |
This class was introduced in Qt 5.4.
Detailed Description
QQuickWindow and QQuickView and their associated internal render loops render the Qt Quick scene onto a native window. In some cases, for example when integrating with 3rd party OpenGL renderers, it might be beneficial to get the scene into a texture that can then be used in arbitrary ways by the external rendering engine. QQuickRenderControl makes this possible in a hardware accelerated manner, unlike the performance-wise limited alternative of using QQuickWindow::grabWindow()
When using a QQuickRenderControl, the QQuickWindow does not have to be shown or even created at all. This means there will not be an underlying native window for it. Instead, the QQuickWindow instance is associated with the render control, using the overload of the QQuickWindow constructor, and an OpenGL framebuffer object by calling QQuickWindow::setRenderTarget().
Management of the context and framebuffer object is up to the application. The context that will be used by Qt Quick must be created before calling initialize(). The creation of the framebuffer object can be deferred, see below. Qt 5.4 introduces the ability for QOpenGLContext to adopt existing native contexts. Together with QQuickRenderControl this makes it possible to create a QOpenGLContext that shares with an external rendering engine's existing context. This new QOpenGLContext can then be used to render the Qt Quick scene into a texture that is accessible by the other engine's context too.
Loading and instantiation of the QML components happen by using a QQmlEngine. Once the root object is created, it will need to be parented to the QQuickWindow's contentItem().
Applications will usually have to connect to 4 important signals:
- QQuickWindow::sceneGraphInitialized() Emitted at some point after calling QQuickRenderControl::initialize(). Upon this signal, the application is expected to create its framebuffer object and associate it with the QQuickWindow.
- QQuickWindow::sceneGraphInvalidated() When the scenegraph resources are released, the framebuffer object can be destroyed too.
- QQuickRenderControl::renderRequested() Indicates that the scene has to be rendered by calling render(). After making the context current, applications are expected to call render().
- QQuickRenderControl::sceneChanged() Indicates that the scene has changed meaning that, before rendering, polishing and synchronizing is also necessary.
To send events, for example mouse or keyboard events, to the scene, use QCoreApplication::sendEvent() with the QQuickWindow instance as the receiver.
Note: In general QQuickRenderControl is supported in combination with all Qt Quick backends. However, some functionality, in particular grab(), may not be available in all cases.