uniformStruct
On this page

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

typeName string

the emitted struct name.

at { group: number; binding: number; as: string }

the group and binding slot, and as, the emitted variable name every field read is spelled through.

fields F extends Record<string, UniformFieldSpec>

the field map: a shader type, or an arrayOf array field.

Return value

UniformStruct<F>

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) for module({ structs }) and .binding for module({ bindings }). Passing the handle in uses contributes 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 with arrayOf exposes .at(i) instead. Uniforms are read-only, so U.field.opacity.assign(...) is a tsc error.
  • .node for the raw binding access node, which is what a hand-built member(...) read needs and is rarely wanted otherwise.
  • .type for 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.x
const m = module({ uses: [U], funcs: [vs, fs] })

In the guide

See also

Source

src/core/sot.ts, line 749, at commit 26de7be8

Edit this page Report a problem