textureDimensions
Function
Texture dimensions describe the extent of an image, not its colour.
Related names in other languages
These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.
- GLSL:
textureSize
Compare examples
Each component of the returned vector gives the texel count along one axis. A cube's face count is not part of that size vector.
Example 1texture_2d: 8 × 4
- Result
vec2u(8, 4)
Example 2texture_3d: 8 × 4 × 2
- Result
vec3u(8, 4, 2)
Example 3texture_cube: 4 × 4 × 6
- Result
vec2u(4, 4)
The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use them to turn texel offsets into normalized coordinate offsets.
Inputs and limits
Array layer counts and sample counts are separate queries. A cube query returns the size of one face.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
- WGSL
textureDimensions(a)- GLSL ES 3.00
uvec2(textureSize(a, 0))
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Returns the size of the texture's base mip level: width and height as a vec2u, width, height and depth as a vec3u on a texture_3d, or the width alone as a u32 on a texture_1d.
Syntax
declare function textureDimensions<E extends TextureElem = f32>( tex: texture_2d<E> | texture_2d_array<E>, level?: number,): vec2udeclare function textureDimensions<E extends TextureElem = f32>( tex: texture_cube<E> | texture_cube_array<E>, level?: number,): vec2udeclare function textureDimensions<E extends TextureElem = f32>( tex: texture_3d<E>, level?: number,): vec3udeclare function textureDimensions<E extends TextureElem = f32>(tex: texture_1d<E>, level?: number): u32declare function textureDimensions<E extends TextureElem = f32>(tex: texture_multisampled_2d<E>): vec2udeclare function textureDimensions( tex: | texture_depth_2d | texture_depth_2d_array | texture_depth_cube | texture_depth_cube_array | texture_depth_multisampled_2d, level?: number,): vec2udeclare function textureDimensions<F extends StorageFormat, A extends StorageAccess>( tex: texture_storage_2d<F, A> | texture_storage_2d_array<F, A>,): vec2uA 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 number you write as a type is inferred from its uses, and f32, i32 and u32 fix a width; the TypeScript constructs page carries that row with the compiler's emit.
A signature may name a type the ambient file declares for its own use. These are those declarations.
TextureElemtype TextureElem = f32 | i32 | u32StorageFormattype StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'StorageAccesstype StorageAccess = 'write' | 'read' | 'read_write'
Parameters
-
textexture_2d<E> | texture_2d_array<E>texture_cube<E> | texture_cube_array<E>texture_3d<E>texture_1d<E>texture_multisampled_2d<E>| texture_depth_2d | texture_depth_2d_array | texture_depth_cube | texture_depth_cube_array | texture_depth_multisampled_2dtexture_storage_2d<F, A> | texture_storage_2d_array<F, A> -
leveloptionalnumber
Return value
Description
On a cube texture it is the size of one face.
Targets
- WGSL
-
textureDimensions(a) - GLSL ES 3.00
-
uvec2(textureSize(a, 0))