QQuickFramebufferObject Class

QQuickFramebufferObject 类是一个方便的类,用于将使用帧缓冲对象(FBO)的 OpenGL 渲染与Qt Quick 集成。更多

头文件: #include <QQuickFramebufferObject>
CMake: find_package(Qt6 REQUIRED COMPONENTS Quick)
target_link_libraries(mytarget PRIVATE Qt6::Quick)
qmake: QT += quick
继承: QQuickItem

公共类型

class Renderer

属性

公共函数

QQuickFramebufferObject(QQuickItem *parent = nullptr)
virtual QQuickFramebufferObject::Renderer *createRenderer() const = 0
bool mirrorVertically() const
void setMirrorVertically(bool enable)
void setTextureFollowsItemSize(bool follows)
bool textureFollowsItemSize() const

重新实现的公共函数

virtual bool isTextureProvider() const override
virtual void releaseResources() override
virtual QSGTextureProvider *textureProvider() const override

信号

详细说明

警告: 该类仅在Qt Quick 通过 OpenGL 进行渲染时有效。它与其他图形 API(如 Vulkan 或 Metal)不兼容。应将其视为一个遗留类,它的存在只是为了让 Qt 5 应用程序能够在与 OpenGL 绑定的情况下运行,而不会出现源代码兼容性中断。

在大多数平台上,渲染将在专用线程上进行。因此,QQuickFramebufferObject 类将项目实现与 FBO 渲染严格分开。所有项目逻辑,如 QML 所需的属性和 UI 相关辅助函数,都应位于 QQuickFramebufferObject 类的子类中。所有与渲染有关的内容都必须位于QQuickFramebufferObject::Renderer 类中。

为避免两个线程的竞赛条件和读写问题,渲染器和项目绝不能读写共享变量。项目与呈现器之间的通信应主要通过QQuickFramebufferObject::Renderer::synchronize() 函数进行。该函数将在 GUI 线程阻塞时在呈现线程上调用。

也可以使用队列连接或事件在项目和呈现器之间进行通信。

渲染器和 FBO 都在内部进行内存管理。

要渲染到 FBO 中,用户应子类化渲染器类并重新实现其Renderer::render() 函数。createRenderer() 会返回渲染器子类。

默认情况下,FBO 的大小将与项目的大小相适应。如果希望使用固定尺寸,可将textureFollowsItemSize 设置为false ,并从QQuickFramebufferObject::Renderer::createFramebufferObject() 返回您选择的纹理。

从 Qt 5.4 开始,QQuickFramebufferObject 类是一个texture provider ,可直接用于ShaderEffects 和其他消耗纹理提供程序的类。

另请参阅 场景图和渲染

属性文档

mirrorVertically : bool

该属性控制绘制时 FBO 内容的大小是否应垂直镜像。这样就可以轻松集成不遵循标准预期的第三方渲染代码。

默认值为false

访问功能:

bool mirrorVertically() const
void setMirrorVertically(bool enable)

通知信号:

void mirrorVerticallyChanged(bool)

textureFollowsItemSize : bool

该属性控制 FBO 纹理的大小是否应遵循QQuickFramebufferObject 项目的尺寸。该属性为假时,FBO 将在首次显示时创建一次。如果设置为 "true",则每次项目的尺寸发生变化时,都将重新创建 FBO。

默认值为true

访问功能:

bool textureFollowsItemSize() const
void setTextureFollowsItemSize(bool follows)

Notifier 信号:

void textureFollowsItemSizeChanged(bool)

成员函数 文档

QQuickFramebufferObject::QQuickFramebufferObject(QQuickItem *parent = nullptr)

通过父parent 构建一个新的 QQuickFramebufferObject。

[pure virtual] QQuickFramebufferObject::Renderer *QQuickFramebufferObject::createRenderer() const

重新实现此函数可创建一个用于渲染到 FBO 的渲染器。

该函数将在 GUI 线程阻塞时在呈现线程上调用。

[override virtual] bool QQuickFramebufferObject::isTextureProvider() const

重实现:QQuickItem::isTextureProvider() const.

[override virtual] void QQuickFramebufferObject::releaseResources()

重新实现:QQuickItem::releaseResources().

[override virtual] QSGTextureProvider *QQuickFramebufferObject::textureProvider() const

重实现:QQuickItem::textureProvider() const.

© 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.