uniformStruct()
함수, 레이아웃 분류
Declare a uniform-buffer struct together with its binding, from one field map.
import { uniformStruct } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function uniformStruct<F extends Record<string, UniformFieldSpec>>( typeName: string, at: { group: number; binding: number; as: string }, fields: F,): UniformStruct<F>매개변수
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.
반환값
the UniformStruct handle described above.
설명
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.
예제
예제
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] })관련 가이드
함께 보기
소스
src/core/sot.ts, 749행, 커밋 c66579bf 기준