Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QQuickRenderControl class provides a mechanism for rendering the Qt Quick scenegraph onto an offscreen render target in a fully application-controlled manner. More...
#include <qquickrendercontrol.h>
Signals | |
void | renderRequested () |
This signal is emitted when the scene graph needs to be rendered. | |
void | sceneChanged () |
This signal is emitted when the scene graph is updated, meaning that polishItems() and sync() needs to be called. | |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QQuickRenderControl (QObject *parent=nullptr) | |
Constructs a QQuickRenderControl object, with parent object parent. | |
~QQuickRenderControl () override | |
Destroys the instance. | |
void | prepareThread (QThread *targetThread) |
Prepares rendering the Qt Quick scene outside the GUI thread. | |
void | setSamples (int sampleCount) |
Sets the number of samples to use for multisampling. | |
int | samples () const |
bool | initialize () |
Initializes the scene graph resources. | |
void | invalidate () |
Stop rendering and release resources. | |
void | beginFrame () |
Specifies the start of a graphics frame. | |
void | endFrame () |
Specifies the end of a graphics frame. | |
void | polishItems () |
This function should be called as late as possible before sync(). | |
bool | sync () |
This function is used to synchronize the QML scene with the rendering scene graph. | |
void | render () |
Renders the scenegraph using the current context. | |
virtual QWindow * | renderWindow (QPoint *offset) |
Reimplemented in subclasses to return the real window this render control is rendering into. | |
QQuickWindow * | window () const |
QRhi * | rhi () const |
QRhiCommandBuffer * | commandBuffer () const |
Public Member Functions inherited from QObject | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
bool | moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL) |
Changes the thread affinity for this object and its children and returns true on success. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
void | killTimer (Qt::TimerId id) |
template<typename T > | |
T | findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
T | findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Static Public Member Functions | |
static QWindow * | renderWindowFor (QQuickWindow *win, QPoint *offset=nullptr) |
Returns the real window that win is being rendered to, if any. | |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Protected Member Functions | |
QQuickRenderControl (QQuickRenderControlPrivate &dd, QObject *parent=nullptr) | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
\threadsafe | |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Properties inherited from QObject | |
QString | objectName |
the name of this object | |
Related Symbols inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
The QQuickRenderControl class provides a mechanism for rendering the Qt Quick scenegraph onto an offscreen render target in a fully application-controlled manner.
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, Vulkan, Metal, or Direct 3D renderers, it can be useful to get the scene into a texture that can then be used in arbitrary ways by the external rendering engine. Such a mechanism is also essential when integrating with a VR framework. 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 must not be \l{QWindow::show()}{shown} (it will not be visible on-screen) and there will not be an underlying native window for it. Instead, the QQuickWindow instance is associated with the render control object, using the overload of the QQuickWindow constructor, and a texture or image object specified via QQuickWindow::setRenderTarget(). The QQuickWindow object is still essential, because it represents the Qt Quick scene and provides the bulk of the scene management and event delivery mechanisms. It does not however act as a real on-screen window from the windowing system's perspective.
Management of the graphics devices, contexts, image and texture objects is up to the application. The device or context that will be used by Qt Quick must be created before calling initialize(). The creation of the texture 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. For Vulkan, Metal, and Direct 3D there are no Qt-provided wrappers for device objects, so existing ones can be passed as-is via QQuickWindow::setGraphicsDevice().
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:
\list
\endlist
To send events, for example mouse or keyboard events, to the scene, use QCoreApplication::sendEvent() with the QQuickWindow instance as the receiver.
For key events it may be also necessary to set the focus manually on the desired item. In practice this involves calling \l{QQuickItem::forceActiveFocus()}{forceActiveFocus()} on the desired item, for example the scene's root item, once it is associated with the scene (the QQuickWindow).
\inmodule QtQuick
Definition at line 20 of file qquickrendercontrol.h.
Constructs a QQuickRenderControl object, with parent object parent.
Definition at line 144 of file qquickrendercontrol.cpp.
|
override |
Destroys the instance.
Releases all scenegraph resources.
Definition at line 162 of file qquickrendercontrol.cpp.
|
explicitprotected |
Definition at line 152 of file qquickrendercontrol.cpp.
void QQuickRenderControl::beginFrame | ( | ) |
Specifies the start of a graphics frame.
Calls to sync() or render() must be enclosed by calls to beginFrame() and endFrame().
Unlike the earlier OpenGL-only world of Qt 5, rendering with other graphics APIs requires more well-defined points of starting and ending a frame. When manually driving the rendering loop via QQuickRenderControl, it now falls to the user of QQuickRenderControl to specify these points.
A typical update step, including initialization of rendering into an existing texture, could look like the following. The example snippet assumes Direct3D 11 but the same concepts apply other graphics APIs as well.
software
adaptation of Qt Quick.Definition at line 685 of file qquickrendercontrol.cpp.
QRhiCommandBuffer * QQuickRenderControl::commandBuffer | ( | ) | const |
Once beginFrame() is called, a QRhiCommandBuffer is set up automatically. That is the command buffer Qt Quick scenegraph uses, but in some cases applications may also want to query it, for example to issue resource updates (for example, a texture readback).
The returned command buffer reference should only be used between beginFrame() and endFrame(). There are specific exceptions, for example calling \l{QRhiCommandBuffer::lastCompletedGpuTime()}{lastCompletedGpuTime()} on the command buffer right after endFrame(), but before the next beginFrame(), is valid.
software
adaptation of Qt Quick.Definition at line 630 of file qquickrendercontrol.cpp.
void QQuickRenderControl::endFrame | ( | ) |
Specifies the end of a graphics frame.
Calls to sync() or render() must be enclosed by calls to beginFrame() and endFrame().
When this function is called, any graphics commands enqueued by the scenegraph are submitted to the context or command queue, whichever is applicable.
software
adaptation of Qt Quick.Definition at line 737 of file qquickrendercontrol.cpp.
bool QQuickRenderControl::initialize | ( | ) |
Initializes the scene graph resources.
When using a graphics API, such as Vulkan, Metal, OpenGL, or Direct3D, for Qt Quick rendering, QQuickRenderControl will set up an appropriate rendering engine when this function is called. This rendering infrastructure exists as long as the QQuickRenderControl exists.
To control what graphics API Qt Quick uses, call QQuickWindow::setGraphicsApi() with one of the QSGRendererInterface:GraphicsApi constants. That must be done before calling this function.
To prevent the scenegraph from creating its own device and context objects, specify an appropriate QQuickGraphicsDevice, wrapping existing graphics objects, by calling QQuickWindow::setGraphicsDevice().
To configure which device extensions to enable (for example, for Vulkan), call QQuickWindow::setGraphicsConfiguration() before this function.
Returns true
on success, false
otherwise.
software
adaptation of Qt Quick.With the default Qt Quick adaptation this function creates a new \l QRhi object, similarly to what would happen with an on-screen QQuickWindow when QQuickRenderControl was not used. To make this new QRhi object adopt some existing device or context resource (e.g. use an existing QOpenGLContext instead of creating a new one), use QQuickWindow::setGraphicsDevice() as mentioned above. When the application wants to make the Qt Quick rendering use an already existing \l QRhi object, that is possible as well via \l QQuickGraphicsDevice::fromRhi(). When such a QQuickGraphicsDevice, referencing an already existing QRhi, is set, there will be no new, dedicated \l QRhi object created in initialize().
Definition at line 299 of file qquickrendercontrol.cpp.
void QQuickRenderControl::invalidate | ( | ) |
Stop rendering and release resources.
This is the equivalent of the cleanup operations that happen with a real QQuickWindow when the window becomes hidden.
This function is called from the destructor. Therefore there will typically be no need to call it directly.
Once invalidate() has been called, it is possible to reuse the QQuickRenderControl instance by calling initialize() again.
Definition at line 401 of file qquickrendercontrol.cpp.
void QQuickRenderControl::polishItems | ( | ) |
This function should be called as late as possible before sync().
In a threaded scenario, rendering can happen in parallel with this function.
Definition at line 334 of file qquickrendercontrol.cpp.
Prepares rendering the Qt Quick scene outside the GUI thread.
targetThread specifies the thread on which synchronization and rendering will happen. There is no need to call this function in a single threaded scenario.
Definition at line 215 of file qquickrendercontrol.cpp.
void QQuickRenderControl::render | ( | ) |
Renders the scenegraph using the current context.
Definition at line 426 of file qquickrendercontrol.cpp.
|
signal |
This signal is emitted when the scene graph needs to be rendered.
It is not necessary to call sync().
Reimplemented in subclasses to return the real window this render control is rendering into.
If offset is non-null, it is set to the offset of the control inside the window.
Reimplemented in QQuickWidgetRenderControl, and QQuickWidgetRenderControl.
Definition at line 45 of file qquickrendercontrol.h.
|
static |
Returns the real window that win is being rendered to, if any.
If offset is non-null, it is set to the offset of the rendering inside its window.
Definition at line 546 of file qquickrendercontrol.cpp.
QRhi * QQuickRenderControl::rhi | ( | ) | const |
software
adaptation of Qt Quick.Definition at line 602 of file qquickrendercontrol.cpp.
int QQuickRenderControl::samples | ( | ) | const |
Definition at line 246 of file qquickrendercontrol.cpp.
|
signal |
This signal is emitted when the scene graph is updated, meaning that polishItems() and sync() needs to be called.
If sync() returns true, then render() needs to be called.
void QQuickRenderControl::setSamples | ( | int | sampleCount | ) |
Sets the number of samples to use for multisampling.
When sampleCount is 0 or 1, multisampling is disabled.
Definition at line 235 of file qquickrendercontrol.cpp.
bool QQuickRenderControl::sync | ( | ) |
This function is used to synchronize the QML scene with the rendering scene graph.
If a dedicated render thread is used, the GUI thread should be blocked for the duration of this call.
Definition at line 357 of file qquickrendercontrol.cpp.
QQuickWindow * QQuickRenderControl::window | ( | ) | const |
Definition at line 583 of file qquickrendercontrol.cpp.