Qml界面渲染机制



  • 渲染层次:

    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

    1. 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.
    2. The render thread prepares to draw a new frame and makes the OpenGL context current and initiates a block on the GUI thread.
    3. 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.
    4. GUI thread is blocked.
    5. 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().
    6. 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.
    7. GUI thread block is released.
    8. The scene graph is rendered:
    9. 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.
    10. Items that have specified QSGNode::UsePreprocess, will have their QSGNode::preprocess() function invoked.
    11. The renderer processes the nodes and calls OpenGL functions.
    12. 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.
    13. The rendered frame is swapped and QQuickWindow::frameSwapped() is emitted.
    14. 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}");



  • @青山白云 对,Qt Quick内部实现还是根据屏幕的刷新率来的。不这么做的话,在不同平台上使用Animator做动画速度会出现不一致的现象。所以Qt的Animation Driver也是按照这样的思路规定16.67ms。


Log in to reply
 

最近的回复

  • E

    是不是好久都没有人了,站主找到工作了,还是说划水了

    read more
  • 请问一下如果原Qt桌面软件支持拖拽外部文件进去(比如把在用资源管理器里的一张图片拖拽到软件界面上就会显示这张图片),转成Webassembly之后这种拖拽操作还是否有效?劳烦大佬帮我试试看,可以的话我就学QML了

    read more
  • H
    Toou 2D 拿来即用,为简单而生。

    简称T2D,是一款采用自身模块规范编写的轻量级UI框架,遵循Qt书写与组织形式门槛极低无需深入学习简单易用可拿来即用,丰富的控件模块适合界面的快速开发,让程序人员拥有更多的精力来实现业务逻辑与算法。

    统一交互规范,丰富的Ui控件几十种常用控件放弃了Qt Controls 及 Controls 2 来提高性能。

    完善的主题系统,业务逻辑与界面主题设计分离,可通过简单修改变量自定义主题皮肤。灵活的多主题皮肤绑定机制、在不需要重启App即实现一键换肤

    ini皮肤配置规则与每一个控件融合。可在应用内配置也可在应用外动态扩展配置。

    框架自动化安装支持动态库、静态库多模式编译。使用方便更安全更自由。

    提供丰富Demo、全面的帮助文档,Api查阅快速方便。项目必备开源框架!

    已经集成最新版 Font Awesome 4.7

    开源地址:https://github.com/ShowFL/Toou-2D

    read more
  • 刚刚毕业,工作用QT开发,以后有问题多多请教各位前辈😬 抱拳了。

    read more

关注我们

微博
QQ群