externVar
이 페이지에서

externVar()

함수, 작성 분류

Declare a host-provided global: the variable counterpart of externFn.

import { externVar } from 'typeshade'

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

구문

function externVar<T extends ShaderType>(
name: string,
type: T,
opts?: { spelling?: { wgsl?: string; glsl?: string }; stage?: ExternVarDecl['stage'] },
): ExternVarHandle<KeyOf<T>>

매개변수

name string

the logical symbol name, and the default spelling on both targets.

type T extends ShaderType

its shader type, for checking every read.

opts선택 사항 { spelling?: { wgsl?: string; glsl?: string }; stage?: ExternVarDecl['stage'] }

per-target spelling, and an advisory stage.

반환값

ExternVarHandle<KeyOf<T>>

an ExternVarHandle: .node reads the value, .decl goes into module({ externs }).

설명

A host prelude may hand a shader values such as a view matrix or a frame time as loose globals the module does not declare. externVar declares such a value abstractly. It emits nothing on either backend; what it provides is everything around the reference: type checking at each use site, a name that survives mangle, and an entry in reflect().requires (and in a fragment’s requires) so a host can check the module’s expectations against what its prelude provides.

spelling maps the logical name onto each target. When another host exposes the same value differently, as a WGSL struct member or a bound uniform in place of a GLSL prelude global, the change is confined to the spelling map.

예제

예제

import { externVar, mat4fT } from 'typeshade'
const uMatrix = externVar('u_matrix', mat4fT, { stage: 'vertex' })
const clip = uMatrix.node.mul(worldPos) // type-checked; emits `u_matrix * …`

관련 가이드

함께 보기

소스

src/core/ir/builder.ts, 1547행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고