QShaderImage Class

class Qt3DRender::QShaderImage

Provides Image access to shader programs. More...

Header: #include <QShaderImage>
CMake: find_package(Qt6 REQUIRED COMPONENTS 3drender)
target_link_libraries(mytarget PRIVATE Qt6::3drender)
qmake: QT += 3drender
Instantiated By: ShaderImage
Inherits: Qt3DCore::QNode

Public Types

enum Access { ReadOnly, WriteOnly, ReadWrite }
enum ImageFormat { NoFormat, Automatic, R8_UNorm, RG8_UNorm, RGBA8_UNorm, …, RGB10A2U }

Properties

Public Functions

Qt3DRender::QShaderImage::Access access() const
Qt3DRender::QShaderImage::ImageFormat format() const
int layer() const
bool layered() const
int mipLevel() const
Qt3DRender::QAbstractTexture *texture() const

Public Slots

void setAccess(Qt3DRender::QShaderImage::Access access)
void setFormat(Qt3DRender::QShaderImage::ImageFormat format)
void setLayer(int layer)
void setLayered(bool layered)
void setMipLevel(int mipLevel)
void setTexture(Qt3DRender::QAbstractTexture *texture)

Signals

void accessChanged(Qt3DRender::QShaderImage::Access access)
void formatChanged(Qt3DRender::QShaderImage::ImageFormat format)
void layerChanged(int layer)
void layeredChanged(bool layered)
void mipLevelChanged(int mipLevel)
void textureChanged(Qt3DRender::QAbstractTexture *texture)

Detailed Description

To make the content of textures available for read and write operations in a shader, they need to exposed as QShaderImage. Textures can be composed of several mip levels, layers and faces. Additionally declaring a QShaderImage allows specifying which level, layer or face of the texture content we want to access.

QShaderImage has to be assigned as a QParameter's value and reference a valid Qt3DRender::QAbstractTexture to work properly.

If the referenced texture is a one-dimensional array, two-dimensional array, three-dimensional, cube map, cube map array, or two-dimensional multisample array texture, it is possible to bind either the entire texture level or a single layer or face of the texture level. This can be controlled with the layered property.

Support for QShaderImage is only supported with OpenGL 4 and partially with OpenGL ES 3.1 and 3.2.

OpenGL 4 supports the following image types:

GLSL TypeOpenGL Type EnumTexture Type
image1DGL_IMAGE_1DQTexture1D
image2DGL_IMAGE_2DQTexture2D
image3DGL_IMAGE_3DQTexture3D
image2DRectGL_IMAGE_2D_RECTQTextureRectangle
imageCubeGL_IMAGE_CUBEQTextureCubeMap
imageBufferGL_IMAGE_BUFFERQTextureBuffer
image1DArrayGL_IMAGE_1D_ARRAYQTexture1DArray
image2DArrayGL_IMAGE_2D_ARRAYQTexture2DArray
imageCubeArrayGL_IMAGE_CUBE_MAP_ARRAYQTextureCubeMapArray
image2DMSGL_IMAGE_2D_MULTISAMPLEQTexture2DMultisample
image2DMSArrayGL_IMAGE_2D_MULTISAMPLE_ARRAYQTexture2DMultisampleArray
iimage1DGL_INT_IMAGE_1DQTexture1D
iimage2DGL_INT_IMAGE_2DQTexture2D
iimage3DGL_INT_IMAGE_3DQTexture3D
iimage2DRectGL_INT_IMAGE_2D_RECTQTextureRectangle
iimageCubeGL_INT_IMAGE_CUBEQTextureCubeMap
iimageBufferGL_INT_IMAGE_BUFFERQTextureBuffer
iimage1DArrayGL_INT_IMAGE_1D_ARRAYQTexture1DArray
iimage2DArrayGL_INT_IMAGE_2D_ARRAYQTexture2DArray
iimageCubeArrayGL_INT_IMAGE_CUBE_MAP_ARRAYQTextureCubeMapArray
iimage2DMSGL_INT_IMAGE_2D_MULTISAMPLEQTexture2DMultisample
iimage2DMSArrayGL_INT_IMAGE_2D_MULTISAMPLE_ARRAYQTexture2DMultisampleArray
uimage1DGL_UNSIGNED_INT_IMAGE_1DQTexture1D
uimage2DGL_UNSIGNED_INT_IMAGE_2DQTexture2D
uimage3DGL_UNSIGNED_INT_IMAGE_3DQTexture3D
uimage2DRectGL_UNSIGNED_INT_IMAGE_2D_RECTQTextureRectangle
uimageCubeGL_UNSIGNED_INT_IMAGE_CUBEQTextureCubeMap
uimageBufferGL_UNSIGNED_INT_IMAGE_BUFFERQTextureBuffer
uimage1DArrayGL_UNSIGNED_INT_IMAGE_1D_ARRAYQTexture1DArray
uimage2DArrayGL_UNSIGNED_INT_IMAGE_2D_ARRAYQTexture2DArray
uimageCubeArrayGL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAYQTextureCubeMapArray
uimage2DMSGL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLEQTexture2DMultisample
uimage2DMSArrayGL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAYQTexture2DMultisampleArray

OpenGL ES 3.1 supports the following image types:

GLSL TypeOpenGL Type EnumTexture Type
image2DGL_IMAGE_2DQTexture2D
image3DGL_IMAGE_3DQTexture3D
imageCubeGL_IMAGE_CUBEQTextureCubeMap
image2DArrayGL_IMAGE_2D_ARRAYQTexture2DArray
iimage2DGL_INT_IMAGE_2DQTexture2D
iimage3DGL_INT_IMAGE_3DQTexture3D
iimageCubeGL_INT_IMAGE_CUBEQTextureCubeMap
iimage2DArrayGL_INT_IMAGE_2D_ARRAYQTexture2DArray
uimage2DGL_UNSIGNED_INT_IMAGE_2DQTexture2D
uimage3DGL_UNSIGNED_INT_IMAGE_3DQTexture3D
uimageCubeGL_UNSIGNED_INT_IMAGE_CUBEQTextureCubeMap
uimage2DArrayGL_UNSIGNED_INT_IMAGE_2D_ARRAYQTexture2DArray

OpenGL ES 3.2 supports all of the OpenGL ES 3.1 image types as well as the following:

GLSL TypeOpenGL Type EnumTexture Type
imageBufferGL_IMAGE_BUFFERQTextureBuffer
imageCubeArrayGL_IMAGE_CUBE_MAP_ARRAYQTextureCubeMapArray
iimageBufferGL_IMAGE_BUFFERQTextureBuffer
iimageCubeArrayGL_INT_IMAGE_CUBE_MAP_ARRAYQTextureCubeMapArray
uimageBufferGL_UNSIGNED_INT_IMAGE_BUFFERQTextureBuffer
uimageCubeArrayGL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAYQTextureCubeMapArray

Expected use would look like:

 Qt3DRender::QTexture2D *tex2D = new Qt3DRender::QTexture2D();
 ...
 Qt3DRender::QMaterial *material = new Qt3DRender::QMaterial();
 ...
 Qt3DRender::QParameter *imageParameter = new Qt3DRender::QParameter();
 Qt3DRender::QShaderImage *shaderImage = new Qt3DRender::QShaderImage();

 shaderImage->setTexture(tex2D);

 imageParameter->setName("imageUniformName");
 imageParameter->setValue(QVariant::fromValue(shaderImage));

 material->addParameter(imageParamenter);

Member Type Documentation

enum QShaderImage::Access

ConstantValueDescription
Qt3DRender::QShaderImage::ReadOnly0Image will only be read from in shaders
Qt3DRender::QShaderImage::WriteOnly1Image will only be written into from shaders
Qt3DRender::QShaderImage::ReadWrite2Image will only be read and written into from shaders

enum QShaderImage::ImageFormat

This list describes all possible image formats

ConstantValueDescription
Qt3DRender::QShaderImage::NoFormat0GL_NONE
Qt3DRender::QShaderImage::Automatic1Qt 3D will try to determine the format automatically based on the referenced texture.
Qt3DRender::QShaderImage::R8_UNorm0x8229GL_R8 (GLSL type r8, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG8_UNorm0x822BGL_RG8 (GLSL type rg8, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA8_UNorm0x8058GL_RGBA8 (GLSL type rgba8, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R16_UNorm0x822AGL_R16 (GLSL type r16, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG16_UNorm0x822CGL_RG16 (GLSL type rg16, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA16_UNorm0x805BGL_RGBA16 (GLSL type rgba16, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::R8_SNorm0x8F94GL_R8_SNORM (GLSL type r8_snorm, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG8_SNorm0x8F95GL_RG8_SNORM (GLSL type rg8_snorm, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA8_SNorm0x8F97GL_RGBA8_SNORM (GLSL type rgba8_snorm, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R16_SNorm0x8F98GL_R16_SNORM (GLSL type r16_snorm, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG16_SNorm0x8F99GL_RG16_SNORM (GLSL type rg16_snorm, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA16_SNorm0x8F9BGL_RGBA16_SNORM (GLSL type rgba16_snorm, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::R8U0x8232GL_R8UI (GLSL type r8ui, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG8U0x8238GL_RG8UI (GLSL type rg8ui, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA8U0x8D7CGL_RGBA8UI (GLSL type rgba8ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R16U0x8234GL_R16UI (GLSL type r16ui, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG16U0x823AGL_RG16UI (GLSL type rg16ui, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA16U0x8D76GL_RGBA16UI (GLSL type rgba16ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R32U0x8236GL_R32UI (GLSL type r32ui, supported by OpenGL 4.2+, OpenGL ES 3.1)
Qt3DRender::QShaderImage::RG32U0x823CGL_RG32UI (GLSL type rg32ui, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA32U0x8D70GL_RGBA32UI (GLSL type rgba32ui, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R8I0x8231GL_R8I (GLSL type r8i, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG8I0x8237GL_RG8I (GLSL type rg8i, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA8I0x8D8EGL_RGBA8I (GLSL type rgba8i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R16I0x8233GL_R16I (GLSL type r16i, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG16I0x8239GL_RG16I (GLSL type rg16i, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA16I0x8D88GL_RGBA16I (GLSL type rgba16i, supported by OpenGL 4.2+, OpenGL ES 3.1)
Qt3DRender::QShaderImage::R32I0x8235GL_R32I (GLSL type r32i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::RG32I0x823BGL_RG32I (GLSL type rg32i, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA32I0x8D82GL_RGBA32I (GLSL type rgba32i, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R16F0x822DGL_R16F (GLSL type r16f, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RG16F0x822FGL_RG16F (GLSL type rg16f, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA16F0x881AGL_RGBA16F (GLSL type rgba16f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::R32F0x822EGL_R32F (GLSL type r32f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::RG32F0x8230GL_RG32F (GLSL type rg32f, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGBA32F0x8814GL_RGBA32F (GLSL type rgba32f, supported by OpenGL 4.2+, OpenGL ES 3.1+)
Qt3DRender::QShaderImage::RG11B10F0x8C3AGL_R11F_G11F_B10F (GLSL type r11f_g11f_b10f, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGB10A20x8059GL_RGB10_A2 (GLSL type rgb10_a2, supported by OpenGL 4.2+)
Qt3DRender::QShaderImage::RGB10A2U0x906FGL_RGB10_A2UI (GLSL type rgb10_a2ui, supported by OpenGL 4.2+)

Property Documentation

access : Access

Specifies the type of access we want to allow from our shader instances to the image. If a shader tries to write or read from an image that has incompatible access, the behavior is undefined.

The default value is QShaderImage::ReadWrite.

Access functions:

Qt3DRender::QShaderImage::Access access() const
void setAccess(Qt3DRender::QShaderImage::Access access)

Notifier signal:

void accessChanged(Qt3DRender::QShaderImage::Access access)

format : ImageFormat

Specifies the image format, which is essentially important when storing values in the Image from a shader.

The format doesn't have to be the same as the referenced texture's format. It however has to be compatible (matching in size but not necessarily by class type). For instance a texture of format R32F (size 32bits, class 1x32) could be used with an image of format RGBA8I (size 32bits, class 4x8). Table 8.27 of the OpenGL specifications shows the size and class for all supported Image formats.

By default Qt3D will try to set the image format to match that of the referenced texture.

The default value is QShaderImage::Automatic.

Access functions:

Qt3DRender::QShaderImage::ImageFormat format() const
void setFormat(Qt3DRender::QShaderImage::ImageFormat format)

Notifier signal:

void formatChanged(Qt3DRender::QShaderImage::ImageFormat format)

layer : int

Holds which layer out of the referenced texture should be used for the QShaderImage. This property does nothing if layered is set to true or if the reference texture's type isn't compatible with layers.

Note: When the referenced texture is of type cube map or cube map array and ĺayered is set to false, the face and layer are retrieved in the following manner:

 cubeMapLayer = layer / 6
 cubeMapFace = layer - (cubeMapLayer * 6)

The default value is 0.

Access functions:

int layer() const
void setLayer(int layer)

Notifier signal:

void layerChanged(int layer)

layered : bool

*

If set to true, if the referenced texture is a one-dimensional array, two-dimensional array, three-dimensional, cube map, cube map array, or two-dimensional multisample array texture, the entire level will be bound for all layers. If set to false, only the single layer specified by the layer property will be bound.

The default value is false.

Access functions:

bool layered() const
void setLayered(bool layered)

Notifier signal:

void layeredChanged(bool layered)

mipLevel : int

Holds which mipLevel out of the referenced texture should be used for the QShaderImage.

The default value is 0.

Access functions:

int mipLevel() const
void setMipLevel(int mipLevel)

Notifier signal:

void mipLevelChanged(int mipLevel)