QRhiTexture Class

Texture resource. More...

Header: #include <QRhiTexture>
qmake: QT += rhi
Inherits: QRhiResource

Public Types

enum Flag { RenderTarget, CubeMap, MipMapped, sRGB, ..., UsedWithLoadStore }
flags Flags
enum Format { UnknownFormat, RGBA8, BGRA8, R8, ..., ASTC_12x12 }

Public Functions

virtual bool build() = 0
virtual bool buildFrom(const QRhiNativeHandles *src)
QRhiTexture::Flags flags() const
QRhiTexture::Format format() const
virtual const QRhiNativeHandles *nativeHandles()
QSize pixelSize() const
int sampleCount() const
void setFlags(QRhiTexture::Flags f)
void setFormat(QRhiTexture::Format fmt)
void setPixelSize(const QSize &sz)
void setSampleCount(int s)

Reimplemented Public Functions

virtual QRhiResource::Type resourceType() const override

Protected Variables

QRhiTexture::Flags m_flags
QRhiTexture::Format m_format
QSize m_pixelSize
int m_sampleCount

Additional Inherited Members

Detailed Description

Texture resource.

Member Type Documentation

enum QRhiTexture::Flag
flags QRhiTexture::Flags

Flag values to specify how the texture is going to be used. Not honoring the flags set before build() and attempting to use the texture in ways that was not declared upfront can lead to unspecified behavior or decreased performance depending on the backend and the underlying graphics API.

ConstantValueDescription
QRhiTexture::RenderTarget1 << 0The texture going to be used in combination with QRhiTextureRenderTarget.
QRhiTexture::CubeMap1 << 2The texture is a cubemap. Such textures have 6 layers, one for each face in the order of +X, -X, +Y, -Y, +Z, -Z. Cubemap textures cannot be multisample.
QRhiTexture::MipMapped1 << 3The texture has mipmaps. The appropriate mip count is calculated automatically and can also be retrieved via QRhi::mipLevelsForSize(). The images for the mip levels have to be provided in the texture uploaded or generated via QRhiResourceUpdateBatch::generateMips(). Multisample textures cannot have mipmaps.
QRhiTexture::sRGB1 << 4Use an sRGB format.
QRhiTexture::UsedAsTransferSource1 << 5The texture is used as the source of a texture copy or readback, meaning the texture is given as the source in QRhiResourceUpdateBatch::copyTexture() or QRhiResourceUpdateBatch::readBackTexture().
QRhiTexture::UsedWithGenerateMips1 << 6The texture is going to be used with QRhiResourceUpdateBatch::generateMips().
QRhiTexture::UsedWithLoadStore1 << 7The texture is going to be used with image load/store operations, for example, in a compute shader.

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

enum QRhiTexture::Format

Specifies the texture format. See also QRhi::isTextureFormatSupported() and note that flags() can modify the format when QRhiTexture::sRGB is set.

ConstantValueDescription
QRhiTexture::UnknownFormat0Not a valid format. This cannot be passed to setFormat().
QRhiTexture::RGBA81Four component, unsigned normalized 8 bit per component. Always supported.
QRhiTexture::BGRA82Four component, unsigned normalized 8 bit per component.
QRhiTexture::R83One component, unsigned normalized 8 bit.
QRhiTexture::R164One component, unsigned normalized 16 bit.
QRhiTexture::RED_OR_ALPHA85Either same as R8, or is a similar format with the component swizzled to alpha, depending on RedOrAlpha8IsRed.
QRhiTexture::RGBA16F6Four components, 16-bit float per component.
QRhiTexture::RGBA32F7Four components, 32-bit float per component.
QRhiTexture::D16816-bit depth (normalized unsigned integer)
QRhiTexture::D32F932-bit depth (32-bit float)
QRhiTexture::BC110 
QRhiTexture::BC211 
QRhiTexture::BC312 
QRhiTexture::BC413 
QRhiTexture::BC514 
QRhiTexture::BC6H15 
QRhiTexture::BC716 
QRhiTexture::ETC2_RGB817 
QRhiTexture::ETC2_RGB8A118 
QRhiTexture::ETC2_RGBA819 
QRhiTexture::ASTC_4x420 
QRhiTexture::ASTC_5x421 
QRhiTexture::ASTC_5x522 
QRhiTexture::ASTC_6x523 
QRhiTexture::ASTC_6x624 
QRhiTexture::ASTC_8x525 
QRhiTexture::ASTC_8x626 
QRhiTexture::ASTC_8x827 
QRhiTexture::ASTC_10x528 
QRhiTexture::ASTC_10x629 
QRhiTexture::ASTC_10x830 
QRhiTexture::ASTC_10x1031 
QRhiTexture::ASTC_12x1032 
QRhiTexture::ASTC_12x1233 

Property Documentation

Member Function Documentation

[pure virtual] bool QRhiTexture::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.

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

[virtual] bool QRhiTexture::buildFrom(const QRhiNativeHandles *src)

Similar to build() except that no new native textures are created. Instead, the texture from src is used.

This allows importing an existing native texture object (which must belong to the same device or sharing context, depending on the graphics API) from an external graphics engine.

Note: format(), pixelSize(), sampleCount(), and flags() must still be set correctly. Passing incorrect sizes and other values to QRhi::newTexture() and then following it with a buildFrom() expecting that the native texture object alone is sufficient to deduce such values is wrong and will lead to problems.

Note: QRhiTexture does not take ownership of the texture object. release() does not free the object or any associated memory.

The opposite of this operation, exposing a QRhiTexture-created native texture object to a foreign engine, is possible via nativeHandles().

See also QRhiVulkanTextureNativeHandles, QRhiD3D11TextureNativeHandles, QRhiMetalTextureNativeHandles, and QRhiGles2TextureNativeHandles.

QRhiTexture::Flags QRhiTexture::flags() const

See also setFlags().

QRhiTexture::Format QRhiTexture::format() const

See also setFormat().

[virtual] const QRhiNativeHandles *QRhiTexture::nativeHandles()

Returns a pointer to a backend-specific QRhiNativeHandles subclass, such as QRhiVulkanTextureNativeHandles. The returned value is null when exposing the underlying native resources is not supported by the backend.

See also QRhiVulkanTextureNativeHandles, QRhiD3D11TextureNativeHandles, QRhiMetalTextureNativeHandles, and QRhiGles2TextureNativeHandles.

QSize QRhiTexture::pixelSize() const

See also setPixelSize().

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

Reimplemented from QRhiResource::resourceType().

Returns the resource type.

int QRhiTexture::sampleCount() const

See also setSampleCount().

void QRhiTexture::setFlags(QRhiTexture::Flags f)

See also flags().

void QRhiTexture::setFormat(QRhiTexture::Format fmt)

See also format().

void QRhiTexture::setPixelSize(const QSize &sz)

See also pixelSize().

void QRhiTexture::setSampleCount(int s)

See also sampleCount().

Member Variable Documentation

Related Non-Members

Macro Documentation