QShaderImage Class

class Qt3DRender::QShaderImage

Provides Image access to shader programs. More...

Header: #include <QShaderImage>
qmake: QT += 3drender
Since: Qt 5.14
Instantiated By: ShaderImage
Inherits: Qt3DCore::QNode

This class was introduced in Qt 5.14.

Public Types

enum Access { ReadOnly, WriteOnly, ReadWrite }

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