textureLoad
Function
Reads one texel at the integer coord and mip level without filtering, by a vec2i on a texture_2d, a vec3i on a texture_3d and one integer on a texture_1d; a cube texture has no texel fetch on either target.
The signature and the sentence under each name are the compiler's own text at commit 26de7be8.
Syntax
declare function textureLoad<E extends TextureElem = f32>( tex: texture_2d<E>, coord: TexelCoord2, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_2d_array<E>, coord: TexelCoord2, layer: number, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_3d<E>, coord: TexelCoord3, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_1d<E>, coord: number, level: number,): Vec4OfElem<E>declare function textureLoad<E extends TextureElem = f32>( tex: texture_multisampled_2d<E>, coord: TexelCoord2, sampleIndex: number,): Vec4OfElem<E>declare function textureLoad(tex: texture_depth_multisampled_2d, coord: TexelCoord2, sampleIndex: number): f32declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>( tex: texture_storage_2d<F, A>, coord: TexelCoord2,): StorageTexel<F>declare function textureLoad<F extends StorageFormat, A extends 'read' | 'read_write'>( tex: texture_storage_2d_array<F, A>, coord: TexelCoord2, layer: number,): StorageTexel<F>A number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.
type f32 = number & { readonly [f32Tag]?: true }
A declaration you write still needs a width, and a bare number on a field or a parameter is refused; the TypeScript constructs page carries that row with the compiler's own message.
A signature may name a type the ambient file declares for its own use. These are those declarations.
TextureElemtype TextureElem = f32 | i32 | u32TexelCoord2type TexelCoord2 = vec2i | vec2uTexelCoord3type TexelCoord3 = vec3i | vec3uStorageFormattype StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'StorageTexeltype StorageTexel<F extends StorageFormat> = F extends `${string}uint` ? vec4u : F extends `${string}sint` ? vec4i : vec4
Parameters
-
textexture_2d<E>texture_2d_array<E>texture_3d<E>texture_1d<E>texture_multisampled_2d<E>texture_depth_multisampled_2dtexture_storage_2d<F, A>texture_storage_2d_array<F, A> -
coordTexelCoord2TexelCoord3number -
leveloptionalnumber -
layeroptionalnumber -
sampleIndexoptionalnumber
Return value
Vec4OfElem<E>f32StorageTexel<F>
Description
On a texture_2d_array the layer comes before the level, and on a texture_multisampled_2d or texture_depth_multisampled_2d the third argument is the sample index instead of a level. Compiles to textureLoad on WGSL and texelFetch on GLSL, which has no multisampled form, so a module loading one emits WGSL alone.
Targets
- WGSL
-
textureLoad(a, b, c) - GLSL ES 3.00
-
texelFetch(a, b, int(c))