Skip to content

arrayOf

const arrayOf: TgpuComptime<WgslArrayConstructor>

Defined in: packages/typegpu/src/data/array.ts:57

Creates an array schema that can be used to construct gpu buffers. Describes arrays with fixed-size length, storing elements of the same type.

The only decoration allowed on element types is d.location. Decorators like d.align and d.size cannot be applied directly — wrap them in a struct instead, e.g. d.arrayOf(d.struct({ value: d.align(16, d.u32) }), n).

const LENGTH = 3;
const array = d.arrayOf(d.u32, LENGTH);
If `elementCount` is not specified, a partially applied function is returned.
const array = d.arrayOf(d.vec3f);
// ^? (n: number) => WgslArray<d.Vec3f>

The type of elements in the array.

The number of elements in the array.

If elementType is decorated with anything other than d.location.