uniformStruct()
Function in Layout
Declare a uniform-buffer struct together with its binding, from one field map.
import { uniformStruct } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function uniformStruct<F extends Record<string, UniformFieldSpec>>( typeName: string, at: { group: number; binding: number; as: string }, fields: F,): UniformStruct<F>Parameters
typeNamestringthe emitted struct name.
at{ group: number; binding: number; as: string }the
groupandbindingslot, andas, the emitted variable name every field read is spelled through.fieldsF extends Record<string, UniformFieldSpec>the field map: a shader type, or an
arrayOfarray field.
Return value
the UniformStruct handle described above.
Description
The struct, the binding and every field read then come from the same declaration, so a slot or a field type cannot drift between them.
The returned handle carries:
.struct(also spelled.decl) formodule({ structs })and.bindingformodule({ bindings }). Passing the handle inusescontributes both..field.<name>for typed field access, which chains straight into the value surface:U.field.raster_params.x,U.field.mvp.mul(v). A field declared witharrayOfexposes.at(i)instead. Uniforms are read-only, soU.field.opacity.assign(...)is a tsc error..nodefor the raw binding access node, which is what a hand-builtmember(...)read needs and is rarely wanted otherwise..typefor the struct’s shader type.
Byte offsets are std140 and come from reflect(m).uniforms, so a host never counts them by
hand.
Examples
Example
import { uniformStruct, mat4x4fT, vec4fT } from 'typeshade'
const U = uniformStruct('Uniforms', { group: 0, binding: 0, as: 'u' }, { mvp: mat4x4fT, raster_params: vec4fT,})
const opacity = U.field.raster_params.xconst m = module({ uses: [U], funcs: [vs, fs] })In the guide
See also
Source
src/core/sot.ts, line 749, at commit 26de7be8