Qt 3D:多视口 QML 示例
演示从多个视口渲染场景图的 QML 示例。
多视口(Multi Viewport)可将场景图从四个虚拟摄像机的视角渲染到窗口的四个象限。这是三维 CAD 或建模工具的常用配置,也可进行调整,以帮助渲染赛车游戏中的后视镜或 CCTV 摄像机显示。
更多信息,请参阅多视口框架图。
运行示例
运行示例 Qt Creator,打开Welcome 模式,然后从Examples 中选择示例。更多信息,请参阅Qt Creator: 教程:构建并运行。
创建多个渲染视图
使用Framegraph Rules 中定义的规则,我们将从 FrameGraph 中构建五个 RenderView 对象:
Viewport { id: mainViewport normalizedRect: Qt.rect(0, 0, 1, 1) ClearBuffers { buffers: ClearBuffers.ColorDepthBuffer clearColor: Qt.rgba(0.6, 0.6, 0.6, 1.0) } Viewport { id: topLeftViewport normalizedRect: Qt.rect(0, 0, 0.5, 0.5) CameraSelector { id: cameraSelectorTopLeftViewport } } Viewport { id: topRightViewport normalizedRect: Qt.rect(0.5, 0, 0.5, 0.5) CameraSelector { id: cameraSelectorTopRightViewport } } Viewport { id: bottomLeftViewport normalizedRect: Qt.rect(0, 0.5, 0.5, 0.5) CameraSelector { id: cameraSelectorBottomLeftViewport } } Viewport { id: bottomRightViewport normalizedRect: Qt.rect(0.5, 0.5, 0.5, 0.5) CameraSelector { id: cameraSelectorBottomRightViewport } } }
顺序很重要。如果ClearBuffers 节点是最后一个而不是第一个,就会导致黑屏,原因很简单,所有内容都会在精心渲染后被立即清除。出于同样的原因,也不能将 节点作为 FrameGraph 的根节点,因为这样会导致调用清除每个视口的整个屏幕。
虽然 FrameGraph 的声明顺序很重要,但Qt 3D 可以并行处理每个渲染视图,因为每个渲染视图都独立于其他渲染视图,以便在渲染视图的状态有效时生成一组需要提交的渲染命令。
Qt 3D 渲染引擎使用基于任务的并行方法,这自然会随着可用内核数量的增加而增加。RenderView 的 RenderCommands 可以在多个内核上并行生成,只要我们注意在专用的 OpenGL 提交线程上以正确的顺序提交 RenderView,就能正确渲染生成的场景。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.