ShaderImage QML Type
为着色器程序提供对图像的访问。更多...
| Import Statement: | import Qt3D.Render 2.12 |
| In C++: | QShaderImage |
| Status: | Deprecated |
此类型已弃用。我们强烈建议不要在新代码中使用它。
属性
详细说明
为了使着色器中能够对纹理内容进行读写操作,需要将纹理作为 ShaderImage 进行暴露。纹理可以由多个 Mip 级别、图层和面组成。此外,声明一个 ShaderImage 还可以指定我们要访问的纹理内容的具体级别、图层或面。
ShaderImage 必须作为参数的值进行赋值,并引用一个有效的 Qt3D.Render.AbstractTexture ,才能正常工作。
如果引用的纹理是一维数组、二维数组、三维数组、立方体贴图、立方体贴图数组或二维多采样数组纹理,则可以绑定整个纹理级别,也可以绑定该纹理级别的单个层或面。这可以通过layered 属性进行控制。
ShaderImage 仅在 OpenGL 4 中受支持,在 OpenGL ES 3.1 和 3.2 中仅部分支持。
OpenGL 4 支持以下图像类型:
| GLSL 类型 | OpenGL 类型枚举 | 纹理类型 |
|---|---|---|
| image1D | GL_IMAGE_1D | Texture1D |
| image2D | GL_IMAGE_2D | Texture2D |
| image3D | GL_IMAGE_3D | Texture3D |
| image2DRect | GL_IMAGE_2D_RECT | TextureRectangle |
| imageCube | GL_IMAGE_CUBE | TextureCubeMap |
| imageBuffer | GL_IMAGE_BUFFER | TextureBuffer |
| image1DArray | GL_IMAGE_1D_ARRAY | Texture1DArray |
| image2DArray | GL_IMAGE_2D_ARRAY | Texture2DArray |
| imageCubeArray | GL_IMAGE_CUBE_MAP_ARRAY | TextureCubeMapArray |
| image2DMS | GL_IMAGE_2D_MULTISAMPLE | Texture2DMultisample |
| image2DMSArray | GL_IMAGE_2D_MULTISAMPLE_ARRAY | Texture2DMultisampleArray |
| iimage1D | GL_INT_IMAGE_1D | Texture1D |
| iimage2D | GL_INT_IMAGE_2D | Texture2D |
| iimage3D | GL_INT_IMAGE_3D | Texture3D |
| iimage2DRect | GL_INT_IMAGE_2D_RECT | TextureRectangle |
| iimageCube | GL_INT_IMAGE_CUBE | TextureCubeMap |
| iimageBuffer | GL_INT_IMAGE_BUFFER | TextureBuffer |
| iimage1DArray | GL_INT_IMAGE_1D_ARRAY | Texture1DArray |
| iimage2DArray | GL_INT_IMAGE_2D_ARRAY | Texture2DArray |
| iimageCubeArray | GL_INT_IMAGE_CUBE_MAP_ARRAY | TextureCubeMapArray |
| iimage2DMS | GL_INT_IMAGE_2D_MULTISAMPLE | Texture2DMultisample |
| iimage2DMSArray | GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY | Texture2DMultisampleArray |
| uimage1D | GL_UNSIGNED_INT_IMAGE_1D | Texture1D |
| uimage2D | GL_UNSIGNED_INT_IMAGE_2D | Texture2D |
| uimage3D | GL_UNSIGNED_INT_IMAGE_3D | Texture3D |
| uimage2DRect | GL_UNSIGNED_INT_IMAGE_2D_RECT | TextureRectangle |
| uimageCube | GL_UNSIGNED_INT_IMAGE_CUBE | TextureCubeMap |
| uimageBuffer | GL_UNSIGNED_INT_IMAGE_BUFFER | TextureBuffer |
| uimage1DArray | GL_UNSIGNED_INT_IMAGE_1D_ARRAY | Texture1DArray |
| uimage2DArray | GL_UNSIGNED_INT_IMAGE_2D_ARRAY | Texture2DArray |
| uimageCubeArray | GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY | TextureCubeMapArray |
| uimage2DMS | GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE | Texture2DMultisample |
| uimage2DMSArray | GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY | Texture2DMultisampleArray |
OpenGL ES 3.1 支持以下图像类型:
| GLSL 类型 | OpenGL 类型枚举 | 纹理类型 |
|---|---|---|
| image2D | GL_IMAGE_2D | Texture2D |
| image3D | GL_IMAGE_3D | Texture3D |
| imageCube | GL_IMAGE_CUBE | TextureCubeMap |
| image2DArray | GL_IMAGE_2D_ARRAY | Texture2DArray |
| iimage2D | GL_INT_IMAGE_2D | Texture2D |
| iimage3D | GL_INT_IMAGE_3D | Texture3D |
| iimageCube | GL_INT_IMAGE_CUBE | TextureCubeMap |
| iimage2DArray | GL_INT_IMAGE_2D_ARRAY | Texture2DArray |
| uimage2D | GL_UNSIGNED_INT_IMAGE_2D | Texture2D |
| uimage3D | GL_UNSIGNED_INT_IMAGE_3D | Texture3D |
| uimageCube | GL_UNSIGNED_INT_IMAGE_CUBE | TextureCubeMap |
| uimage2DArray | GL_UNSIGNED_INT_IMAGE_2D_ARRAY | Texture2DArray |
OpenGL ES 3.2 支持所有 OpenGL ES 3.1 的图像类型,以及以下类型:
| GLSL 类型 | OpenGL 类型枚举 | 纹理类型 |
|---|---|---|
| imageBuffer | GL_IMAGE_BUFFER | TextureBuffer |
| imageCubeArray | GL_IMAGE_CUBE_MAP_ARRAY | TextureCubeMapArray |
| iimageBuffer | GL_IMAGE_BUFFER | TextureBuffer |
| iimageCubeArray | GL_INT_IMAGE_CUBE_MAP_ARRAY | TextureCubeMapArray |
| uimageBuffer | GL_UNSIGNED_INT_IMAGE_BUFFER | TextureBuffer |
| uimageCubeArray | GL_UNSIGNED_INT_IMAGE_CUBE_MAP_ARRAY | TextureCubeMapArray |
预期用法如下:
import Qt3D.Render 2.14
Entity {
...
Texture2D {
id: tex2D
...
}
Material {
parameters: Parameter {
name: "imageUniformName"
value: ShaderImage {
texture: tex2D
}
}
...
}
...
}属性文档
access : enumeration
指定我们希望允许着色器实例对图像进行何种访问。如果着色器试图对访问权限不兼容的图像进行写入或读取操作,其行为将未定义。
| 常量 | 描述 |
|---|---|
ShaderImage.ReadOnly | 只读访问。 |
ShaderImage.WriteOnly | 仅写入访问。 |
ShaderImage.ReadWrite | 读写访问。 |
默认值为ShaderImage.ReadWrite。
format : enumeration
指定图像格式,这在从着色器向ShaderImage 存储值时至关重要。
该格式不必与被引用的纹理格式完全一致,但必须兼容(尺寸需匹配,但类类型不作硬性要求)。 例如,格式为 R32F(大小为 32 位,类为 1x32)的纹理可以与格式为 RGBA8I(大小为 32 位,类为 4x8)的图像一起使用。OpenGL 规范中的表 8.27 列出了所有受支持的图像格式的大小和类。
默认情况下,Qt3D 会尝试将图像格式设置为与被引用的纹理格式一致。
默认值为ShaderImage.Automatic。
layer : int
指定应使用引用纹理中的哪一层作为ShaderImage 。如果layered 设置为true,或者引用纹理的类型与图层不兼容,则此属性不产生任何效果。
注意:当 引用纹理的类型为立方体贴图或立方体贴图数组,且ĺayered 设置为false时,面和层的获取方式如下:
cubeMapLayer = layer / 6
cubeMapFace = layer - (cubeMapLayer * 6)默认值为 0。
layered : bool
*
如果设置为 true,且引用的纹理是一维数组、二维数组、三维数组、立方体贴图、立方体贴图数组或二维多采样数组纹理,则整个纹理将绑定到所有层。如果设置为 false,则仅绑定由layer 属性指定的单个层。
默认值为false 。
mipLevel : int
指定应从引用的纹理中使用哪个mipLevel作为ShaderImage 。
默认值为 0。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.