QRhiResource Class

Base class for classes encapsulating native resource objects. 更多...

头: #include <QRhiResource>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
Since: Qt 6.6
继承者:
11 types

QRhiBuffer , QRhiCommandBuffer , QRhiComputePipeline , QRhiGraphicsPipeline , QRhiRenderBuffer , QRhiRenderPassDescriptor , QRhiRenderTarget , QRhiSampler , QRhiShaderResourceBindings , QRhiSwapChain ,和 QRhiTexture

公共类型

enum Type { Buffer, Texture, Sampler, RenderBuffer, RenderPassDescriptor, …, CommandBuffer }

公共函数

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 )

详细描述

注意: This is a RHI API with limited compatibility guarantees, see QRhi 了解细节。

成员类型文档编制

enum QRhiResource:: Type

Specifies type of the resource.

常量
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

成员函数文档编制

[virtual noexcept] QRhiResource:: ~QRhiResource ()

析构函数。

Releases (or requests deferred releasing of) the underlying native graphics resources, if there are any.

注意: Resources referenced by commands for the current frame should not be released until the frame is submitted by QRhi::endFrame ().

另请参阅 destroy ().

void QRhiResource:: deleteLater ()

When called without a frame being recorded, this function is equivalent to deleting the object. Between a QRhi::beginFrame () 和 QRhi::endFrame () however the behavior is different: the QRhiResource will not be destroyed until the frame is submitted via QRhi::endFrame (), thus satisfying the QRhi requirement of not altering QRhiResource objects that are referenced by the frame being recorded.

QRhi that created this object is already destroyed, the object is deleted immediately.

Using deleteLater() can be a useful convenience in many cases, and it complements the low-level guarantee (that the underlying native graphics objects are never destroyed until it is safe to do so and it is known for sure that they are not used by the GPU in an still in-flight frame), by offering a way to make sure the C++ object instances (of QRhiBuffer , QRhiTexture , etc.) themselves also stay valid until the end of the current frame.

The following example shows a convenient way of creating a throwaway buffer that is only used in one frame and gets automatically released in endFrame(). (when it comes to the underlying native buffer(s), the usual guarantee applies: the QRhi backend defers the releasing of those until it is guaranteed that the frame in which the buffer is accessed by the GPU has completed)

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 ()

Releases (or requests deferred releasing of) the underlying native graphics resources. Safe to call multiple times, subsequent invocations will be a no-op then.

Once destroy() is called, the QRhiResource instance can be reused, by calling create() again. That will then result in creating new native graphics resources underneath.

注意: Resources referenced by commands for the current frame should not be released until the frame is submitted by QRhi::endFrame ().

The QRhiResource destructor also performs the same task, so calling this function is not necessary before deleting a QRhiResource .

另请参阅 deleteLater ().

quint64 QRhiResource:: globalResourceId () const

Returns the global, unique identifier of this QRhiResource .

User code rarely needs to deal with the value directly. It is used internally for tracking and bookkeeping purposes.

QByteArray QRhiResource:: name () const

Returns the currently set object name. By default the name is empty.

另请参阅 setName ().

[pure virtual] QRhiResource::Type QRhiResource:: resourceType () const

Returns the type of the resource.

QRhi *QRhiResource:: rhi () const

返回 QRhi that created this resource.

QRhi that created this object is already destroyed, the result is nullptr .

void QRhiResource:: setName (const QByteArray & name )

设置 name for the object.

This allows getting descriptive names for the native graphics resources visible in graphics debugging tools, such as RenderDoc and XCode .

When it comes to naming native objects by relaying the name via the appropriate graphics API, note that the name is ignored when QRhi::DebugMarkers are not supported, and may, depending on the backend, also be ignored when QRhi::EnableDebugMarkers is not set.

注意: The name may be ignored for objects other than buffers, renderbuffers, and textures, depending on the backend.

注意: The name may be modified. For slotted resources, such as a QRhiBuffer backed by multiple native buffers, QRhi will append a suffix to make the underlying native buffers easily distinguishable from each other.

另请参阅 name ().