QRhiResource Class
封装本地资源对象的基类。更多
头文件: | #include <rhi/qrhi.h> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate) |
qmake: | QT += gui-private |
自 | Qt 6.6 |
继承于 |
公共类型
enum | Type { Buffer, Texture, Sampler, RenderBuffer, RenderPassDescriptor, …, ShadingRateMap } |
公共函数
virtual | ~QRhiResource() |
void | deleteLater() |
virtual void | destroy() = 0 |
quint64 | globalResourceId() const |
QByteArray | name() const |
virtual QRhiResource::Type | resourceType() const = 0 |
QRhi * | rhi() const |
void | setName(const QByteArray &name) |
详细说明
注: 这是一个 RHI API,具有有限的兼容性保证,详情请参见QRhi 。
成员类型文档
enum QRhiResource::Type
指定资源类型。
常数 | 值 |
---|---|
QRhiResource::Buffer | 0 |
QRhiResource::Texture | 1 |
QRhiResource::Sampler | 2 |
QRhiResource::RenderBuffer | 3 |
QRhiResource::RenderPassDescriptor | 4 |
QRhiResource::SwapChainRenderTarget | 5 |
QRhiResource::TextureRenderTarget | 6 |
QRhiResource::ShaderResourceBindings | 7 |
QRhiResource::GraphicsPipeline | 8 |
QRhiResource::SwapChain | 9 |
QRhiResource::ComputePipeline | 10 |
QRhiResource::CommandBuffer | 11 |
QRhiResource::ShadingRateMap | 12 |
成员函数文档
[virtual noexcept]
QRhiResource::~QRhiResource()
销毁器
释放(或请求延迟释放)底层本地图形资源(如果有的话)。
注意: 在通过QRhi::endFrame() 提交帧之前,不应释放当前帧的命令所引用的资源。
另请参见 destroy()。
void QRhiResource::deleteLater()
在没有记录帧的情况下调用该函数,相当于删除对象。但在QRhi::beginFrame() 和QRhi::endFrame() 之间,行为则有所不同:在通过QRhi::endFrame() 提交帧之前,QRhiResource 不会被销毁,从而满足了QRhi 的要求,即不会更改被正在记录的帧引用的QRhiResource 对象。
如果创建该对象的QRhi 已被销毁,则会立即删除该对象。
在许多情况下,使用 deleteLater() 可以带来极大的便利,它提供了一种方法来确保 C++ 对象实例(QRhiBuffer 、QRhiTexture 等)本身在当前帧结束前一直有效,从而补充了底层保证(底层本地图形对象在安全的情况下永远不会被销毁,并且可以确定 GPU 在飞行中的帧中不会使用这些对象)。
下面的示例展示了一种便捷的方法,即创建一个仅在一帧中使用的可丢弃缓冲区,并在 endFrame() 中自动释放。(当涉及到底层本地缓冲区时,通常的保证也适用:QRhi 后台会推迟释放这些缓冲区,直到保证 GPU 访问缓冲区的帧已经完成为止)
rhi->beginFrame(swapchain); QRhiBuffer *buf = rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, 256); buf->deleteLater(); // ! u = rhi->nextResourceUpdateBatch(); u->uploadStaticBuffer(buf, data); // ... draw with buf rhi->endFrame();
另请参见 destroy().
[pure virtual]
void QRhiResource::destroy()
释放(或请求延迟释放)底层本地图形资源。可以安全地多次调用,但随后的调用将是无效的。
一旦 destroy() 被调用,就可以通过再次调用create()
来重新使用QRhiResource 实例。这样就会在下面创建新的本地图形资源。
注意: 在QRhi::endFrame() 提交帧之前,不应释放当前帧命令引用的资源。
QRhiResource 析构函数也执行相同的任务,因此在删除QRhiResource 之前无需调用该函数。
另请参阅 deleteLater()。
quint64 QRhiResource::globalResourceId() const
返回QRhiResource 的全局唯一标识符。
用户代码很少需要直接处理该值。它在内部用于跟踪和记账目的。
QByteArray QRhiResource::name() const
返回当前设置的对象名称。默认情况下,名称为空。
另请参见 setName()。
[pure virtual]
QRhiResource::Type QRhiResource::resourceType() const
返回资源的类型。
QRhi *QRhiResource::rhi() const
返回创建此资源的QRhi 。
如果创建此对象的QRhi 已被销毁,则结果为nullptr
。
void QRhiResource::setName(const QByteArray &name)
为对象设置name 。
这样就能为图形调试工具(如RenderDoc和XCode)中可见的本地图形资源获取描述性名称。
在通过相应的图形应用程序接口转发名称为本地对象命名时,请注意,如果不支持QRhi::DebugMarkers ,名称将被忽略;如果不设置QRhi::EnableDebugMarkers ,根据后端情况,名称也可能被忽略。
注意: 对于缓冲区、渲染缓冲区和纹理以外的对象,名称可能会被忽略,具体取决于后端。
注: 名称可能会被修改。对于插槽式资源(如由多个本地缓冲区支持的QRhiBuffer ),QRhi 会添加一个后缀,以便底层本地缓冲区之间易于区分。
另请参阅 name().
© 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.