textureLoad()
Function in Builtins
Load one texel from a 2D texture at integer coordinates, returning vec4<f32>, vec4<u32> or vec4<i32> to match the texture's element.
import { textureLoad } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function textureLoad<K extends TextureLoad2dKey>( tex: ReadonlyNode<K>, coord: NodeLike, level: NodeLike,): Node<TexelKey<K>>;function textureLoad<K extends TextureLoadArrayKey>( tex: ReadonlyNode<K>, coord: NodeLike, layer: ReadonlyNode<'i32' | 'u32'> | number, level: NodeLike,): Node<TexelKey<K>>;Parameters
texReadonlyNode<K>coordNodeLikelevelNodeLike
Return value
Exceptions
SD0015A JS number level lifts to a u32 literal, so 0 emits a valid integer level on both targets, and a fractional level throws SD0015.
Description
WGSL requires the mip level
argument; pass 0 for the base level. A JS number level lifts to a u32 literal, so 0
emits a valid integer level on both targets, and a fractional level throws SD0015. The
coordinate is usually a vec2<i32>; any vector or scalar node is accepted here and the
GPU compiler checks it. The CPU evaluation returns a placeholder under its gpuStubs
option.
For an integer texture this is the read to use: integer texels cannot be filtered, so
textureSample and textureSampleLevel reject those keys at tsc.
Targets
| Target | Support | Notes |
|---|---|---|
| WGSL (WebGPU) | Supported |
|
| GLSL ES 3.00 (WebGL2) | Supported |
|
| CPU oracle | Stub | The oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with |
In the guide
See also
Source
src/core/ir/node.ts, line 2146, at commit 26de7be8