ioStruct()
Function in Layout
Declare a struct that crosses a stage boundary, a vertex output, a fragment input, a compute IO record, from one field map.
import { ioStruct } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function ioStruct<F extends Record<string, FieldSpec>, N extends string>( name: N, fields: F,): IoStruct<F, N>Parameters
nameN extends stringthe emitted struct name.
fieldsF extends Record<string, FieldSpec>the field map, each value a
builtin(...)orlocation(...)spec.
Return value
IoStruct<F, N>
the IoStruct handle described above.
Description
Every field is a builtin or location
spec, so the attributes live with the field they belong to and the struct is declared once.
The returned handle carries everything the rest of the module needs:
.typeis the struct’sShaderType. Use it as a parameter type,{ vo: VsOut.type }, or pass the handle itself in anfnparam record and the body receives the typed field proxy..declis theStructDeclformodule({ structs }), or pass the handle inuses..of(node)reads fields off a value of this struct:VsOut.of(p.vo).uvis typed, and a misspelled field is a tsc error. The view follows its base, so a read-only base yields read-only fields..var(name)declares avarof the struct and returns assignable fields:o.pos.assign(...). The proxy reads as the raw node in value positions, and.$is that raw struct value where an explicit one is wanted..construct({ ... })builds the value in one expression, keyed by field name, with a missing or extra field a tsc error. It is the form to prefer when nothing needs mutating.
Examples
Example
import { ioStruct, builtin, location, vec4fT, vec2fT, f32T } from 'typeshade'
const VsOut = ioStruct('VsOut', { pos: builtin('position', vec4fT), uv: location(0, vec2fT), vis: location(1, f32T),})
const pin = VsOut.of(p.vo) // pin.uv, pin.vis are typed readsreturn VsOut.construct({ pos: clip, uv, vis })In the guide
See also
Source
src/core/sot.ts, line 413, at commit 26de7be8