uniformStruct
이 페이지에서

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>

매개변수

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.

반환값

UniformStruct<F>

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) 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.

예제

예제

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] })

관련 가이드

함께 보기

소스

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

이 페이지 편집 문제 보고