QRhiTextureRenderTarget Class

Texture render target resource. More...

Header: #include <QRhiTextureRenderTarget>
qmake: QT += rhi
Inherits: QRhiRenderTarget

Public Types

enum Flag { PreserveColorContents, PreserveDepthStencilContents }
flags Flags

Public Functions

virtual bool build() = 0
QRhiTextureRenderTargetDescription description() const
QRhiTextureRenderTarget::Flags flags() const
virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0
void setDescription(const QRhiTextureRenderTargetDescription &desc)
void setFlags(QRhiTextureRenderTarget::Flags f)

Reimplemented Public Functions

virtual QRhiResource::Type resourceType() const override

Protected Variables

QRhiTextureRenderTargetDescription m_desc
QRhiTextureRenderTarget::Flags m_flags

Additional Inherited Members

Detailed Description

Texture render target resource.

A texture render target allows rendering into one or more textures, optionally with a depth texture or depth/stencil renderbuffer.

Note: Textures used in combination with QRhiTextureRenderTarget must be created with the QRhiTexture::RenderTarget flag.

The simplest example of creating a render target with a texture as its single color attachment:


  texture = rhi->newTexture(QRhiTexture::RGBA8, size, 1, QRhiTexture::RenderTarget);
  texture->build();
  rt = rhi->newTextureRenderTarget({ texture });
  rp = rt->newCompatibleRenderPassDescriptor();
  rt->setRenderPassDescriptor(rt);
  rt->build();
  // rt can now be used with beginPass()

Member Type Documentation

enum QRhiTextureRenderTarget::Flag
flags QRhiTextureRenderTarget::Flags

Flag values describing the load/store behavior for the render target. The load/store behavior may be baked into native resources under the hood, depending on the backend, and therefore it needs to be known upfront and cannot be changed without rebuilding (and so releasing and creating new native resources).

ConstantValueDescription
QRhiTextureRenderTarget::PreserveColorContents1 << 0Indicates that the contents of the color attachments is to be loaded when starting a render pass, instead of clearing. This is potentially more expensive, especially on mobile (tiled) GPUs, but allows preserving the existing contents between passes.
QRhiTextureRenderTarget::PreserveDepthStencilContents1 << 1Indicates that the contents of the depth texture is to be loaded when starting a render pass, instead clearing. Only applicable when a texture is used as the depth buffer (QRhiTextureRenderTargetDescription::depthTexture() is set) because depth/stencil renderbuffers may not have any physical backing and data may not be written out in the first place.

The Flags type is a typedef for QFlags<Flag>. It stores an OR combination of Flag values.

Property Documentation

Member Function Documentation

[pure virtual] bool QRhiTextureRenderTarget::build()

Creates the corresponding native graphics resources. If there are already resources present due to an earlier build() with no corresponding release(), then release() is called implicitly first.

Note: renderPassDescriptor() must be set before calling build(). To obtain a QRhiRenderPassDescriptor compatible with the render target, call newCompatibleRenderPassDescriptor() before build() but after setting all other parameters, such as description() and flags(). To save resources, reuse the same QRhiRenderPassDescriptor with multiple QRhiTextureRenderTarget instances, whenever possible. Sharing the same render pass descriptor is only possible when the render targets have the same number and type of attachments (the actual textures can differ) and the same flags.

Note: resources, such as QRhiTexture instances, referenced in description() must already be built

Returns true when successful, false when a graphics operation failed. Regardless of the return value, calling release() is always safe.

QRhiTextureRenderTargetDescription QRhiTextureRenderTarget::description() const

See also setDescription().

QRhiTextureRenderTarget::Flags QRhiTextureRenderTarget::flags() const

See also setFlags().

[pure virtual] QRhiRenderPassDescriptor *QRhiTextureRenderTarget::newCompatibleRenderPassDescriptor()

Returns a new QRhiRenderPassDescriptor that is compatible with this render target.

The returned value is used in two ways: it can be passed to setRenderPassDescriptor() and QRhiGraphicsPipeline::setRenderPassDescriptor(). A render pass descriptor describes the attachments (color, depth/stencil) and the load/store behavior that can be affected by flags(). A QRhiGraphicsPipeline can only be used in combination with a render target that has the same QRhiRenderPassDescriptor set.

Two QRhiTextureRenderTarget instances can share the same render pass descriptor as long as they have the same number and type of attachments. The associated QRhiTexture or QRhiRenderBuffer instances are not part of the render pass descriptor so those can differ in the two QRhiTextureRenderTarget intances.

Note: resources, such as QRhiTexture instances, referenced in description() must already be built

See also build().

[override virtual] QRhiResource::Type QRhiTextureRenderTarget::resourceType() const

Reimplemented from QRhiRenderTarget::resourceType().

Returns the resource type.

void QRhiTextureRenderTarget::setDescription(const QRhiTextureRenderTargetDescription &desc)

See also description().

void QRhiTextureRenderTarget::setFlags(QRhiTextureRenderTarget::Flags f)

See also flags().

Member Variable Documentation

Related Non-Members

Macro Documentation