ShaderImage QML Type

提供对着色器程序的图像访问。更多

Import Statement: import Qt3D.Render 2.9
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 类型枚举纹理类型
图像 1DGL_IMAGE_1DTexture1D
图像2DGL_IMAGE_2DTexture2D
图像 3DGL_IMAGE_3DTexture3D
image2DRectgl_image_2d_rectTextureRectangle
图像立方体图像立方体TextureCubeMap
图像缓冲区gl_image_bufferTextureBuffer
image1DArraygl_image_1d_arrayTexture1DArray
图像 2DArraygl_image_2d_arrayTexture2DArray
图像立方数组gl_image_cube_map_arrayTextureCubeMapArray
图像2DMSgl_image_2d_multisampleTexture2DMultisample
图像 2DMSArraygl_image_2d_multisample_arrayTexture2DMultisampleArray
iimage1Dgl_int_image_1dTexture1D
iimage2Dgl_int_image_2dTexture2D
iimage3Dgl_int_image_3dTexture3D
iimage2DRectgl_int_image_2d_rectTextureRectangle
iimageCubegl_int_image_cubeTextureCubeMap
iimageBuffergl_int_image_bufferTextureBuffer
iimage1DArraygl_int_image_1d_arrayTexture1DArray
iimage2DArraygl_int_image_2d_arrayTexture2DArray
iimageCubeArraygl_int_image_cube_map_arrayTextureCubeMapArray
iimage2DMSgl_int_image_2d_multisampleTexture2DMultisample
iimage2DMSArraygl_int_image_2d_multisample_arrayTexture2DMultisampleArray
uimage1Dgl_unsigned_int_image_1dTexture1D
uimage2Dgl_unsigned_int_image_2dTexture2D
uimage3Dgl_unsigned_int_image_3dTexture3D
uimage2DRectgl_unsigned_int_image_2d_rectTextureRectangle
uimageCubegl_unsigned_int_image_cubeTextureCubeMap
uimageBuffergl_unsigned_int_image_bufferTextureBuffer
uimage1DArraygl_unsigned_int_image_1d_arrayTexture1DArray
uimage2DArraygl_unsigned_int_image_2d_arrayTexture2DArray
uimageCubeArraygl_unsigned_int_image_cube_map_arrayTextureCubeMapArray
uimage2DMSgl_unsigned_int_image_2d_multisampleTexture2DMultisample
uimage2DMSArraygl_unsigned_int_image_2d_multisample_arrayTexture2DMultisampleArray

OpenGL ES 3.1 支持以下图像类型:

GLSL 类型OpenGL 类型枚举纹理类型
图像 2DGL_IMAGE_2DTexture2D
图像 3DGL_IMAGE_3DTexture3D
图像立方体图像立方体TextureCubeMap
image2DArraygl_image_2d_arrayTexture2DArray
iimage2Dgl_int_image_2dTexture2D
iimage3Dgl_int_image_3dTexture3D
图像立方体gl_int_image_cubeTextureCubeMap
iimage2DArraygl_int_image_2d_arrayTexture2DArray
uimage2Dgl_unsigned_int_image_2dTexture2D
uimage3Dgl_unsigned_int_image_3dTexture3D
uimageCubegl_unsigned_int_image_cubeTextureCubeMap
uimage2DArraygl_unsigned_int_image_2d_arrayTexture2DArray

OpenGL ES 3.2 支持所有 OpenGL ES 3.1 图像类型以及以下类型:

GLSL 类型OpenGL 类型枚举纹理类型
图像缓冲区gl_image_bufferTextureBuffer
图像立方数组图像立方图数组TextureCubeMapArray
iimageBuffergl_image_bufferTextureBuffer
图像立方数组gl_int_image_cube_map_arrayTextureCubeMapArray
uimageBuffergl_unsigned_int_image_bufferTextureBuffer
uimageCubeArraygl_unsigned_int_image_cube_map_arrayTextureCubeMapArray

预期用途如下

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(mipLevel 属性):表示ShaderImage 应使用引用纹理中的哪个 mipLevel。

默认值为 0。


© 2025 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.