渲染层次:
0_1531798264848_48a56a99-a2a7-4a1e-8d0e-f12d889d74a1-image.png渲染循环分三种,basic, windows, and threaded,其中Basic和Windows是单线程的,threaded在单独线程里面渲染场景,qt会根据平台自动选择一种,我电脑上已经验证是threaded
qt.scenegraph.general: threaded render loop qt.scenegraph.general: Using sg animation driver qt.scenegraph.general: Animation Driver: using vsync: 16.67 ms
同时可以知道画面垂直同步是16.67 ms,理论60Hz
线程渲染循环中如何完成一帧
0_1531798407892_935d0c1f-554a-4cbb-999a-a0966484548d-image.png- A change occurs in the QML scene, causing QQuickItem::update() to be called. This can be the result of for instance an animation or user input. An event is posted to the render thread to initiate a new frame.
- The render thread prepares to draw a new frame and makes the OpenGL context current and initiates a block on the GUI thread.
- While the render thread is preparing the new frame, the GUI thread calls QQuickItem::updatePolish() to do final touch-up of items before they are rendered.
- GUI thread is blocked.
- The QQuickWindow::beforeSynchronizing() signal is emitted. Applications can make direct connections (using Qt::DirectConnection) to this signal to do any preparation required before calls to QQuickItem::updatePaintNode().
- Synchronization of the QML state into the scene graph. This is done by calling the QQuickItem::updatePaintNode() function on all items that have changed since the previous frame. This is the only time the QML items and the nodes in the scene graph interact.
- GUI thread block is released.
- The scene graph is rendered:
- The QQuickWindow::beforeRendering() signal is emitted. Applications can make direct connections (using Qt::DirectConnection) to this signal to use custom OpenGL calls which will then stack visually beneath the QML scene.
- Items that have specified QSGNode::UsePreprocess, will have their QSGNode::preprocess() function invoked.
- The renderer processes the nodes and calls OpenGL functions.
- The QQuickWindow::afterRendering() signal is emitted. Applications can make direct connections (using Qt::DirectConnection) to this signal to use custom OpenGL calls which will then stack visually over the QML scene.
- The rendered frame is swapped and QQuickWindow::frameSwapped() is emitted.
- While the render thread is rendering, the GUI is free to advance animations, process events, etc.
The threaded renderer is currently used by default on Windows with opengl32.dll, Linux with non-Mesa based drivers, macOS, mobile platforms, and Embedded Linux with EGLFS but this is subject to change. It is possible to force use of the threaded renderer by setting QSG_RENDER_LOOP=threaded in the environment.
非线程渲染
0_1531798434302_91612780-f2cf-4fdb-b5a1-aeb004a1e7a2-image.png查看渲染方式:
QLoggingCategory::setFilterRules(QStringLiteral("qt.scenegraph.general=true")); qSetMessagePattern("%{category}: %{message}");
网友评论