ioStruct
이 페이지에서

ioStruct()

함수, 레이아웃 분류

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'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

function ioStruct<F extends Record<string, FieldSpec>, N extends string>(
name: N,
fields: F,
): IoStruct<F, N>

매개변수

name N extends string

the emitted struct name.

fields F extends Record<string, FieldSpec>

the field map, each value a builtin(...) or location(...) spec.

반환값

IoStruct<F, N>

the IoStruct handle described above.

설명

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:

  • .type is the struct’s ShaderType. Use it as a parameter type, { vo: VsOut.type }, or pass the handle itself in an fn param record and the body receives the typed field proxy.
  • .decl is the StructDecl for module({ structs }), or pass the handle in uses.
  • .of(node) reads fields off a value of this struct: VsOut.of(p.vo).uv is 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 a var of 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.

예제

예제

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 reads
return VsOut.construct({ pos: clip, uv, vis })

관련 가이드

함께 보기

소스

src/core/sot.ts, 413행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고