VariantFamily
인터페이스, 배리언트 분류
A built family.
import type { VariantFamily } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface VariantFamily<A extends Record<string, readonly unknown[]>> { readonly variants: readonly Variant<A>[]; readonly keys: readonly string[]; get(key: string): Variant<A> | undefined; emit(target: 'wgsl', opts?: EmitOptions): ReadonlyMap<string, string>; emit( target: 'glsl-es300', opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }, ): ReadonlyMap<string, string>; emitGuarded( defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }, ): string; emitGuardedFragment( defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }, ): EmitFragment;}인스턴스 속성
variants읽기 전용readonly Variant<A>[]keys읽기 전용readonly string[]Every key, in
variantsorder: the id set a pipeline cache keys its programs by.
인스턴스 메서드
get(key: string): Variant<A> | undefinedLook one variant up by key;
undefinedwhen the key names no variant.emit(target: 'wgsl', opts?: EmitOptions): ReadonlyMap<string, string>One preprocessor-free source per key. The only shape WGSL can take, and the one a pipeline cache should prefer on GLSL too.
emit(target: 'glsl-es300', opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }): ReadonlyMap<string, string>emitGuarded(defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }): stringOne GLSL source whose arms are selected by preprocessor defines the host owns.
Opt in to this when the host already sets the define per draw and cannot pick a source per variant; otherwise prefer
VariantFamily.emit. GLSL only, because the arms are selected by the GLSL preprocessor. Every arm is byte-identical to the correspondingemit()source, so a program selected through the ladder is the same program as the standalone variant.emitGuardedFragment(defines: GuardDefines<A>, opts?: GlslEmitOptions & { stage?: 'vertex' | 'fragment' }): EmitFragmentThe same generated ladder as
VariantFamily.emitGuarded, returned as a header-less fragment for a host that owns the program and composes these declarations into it.emitGuardedreturns a whole stage, preamble included. A ladder pasted into a host program through an#includecannot carry a second#version, so here the preamble comes back as data, exactly asemitGlslFragmentreturns it, and[...preamble, '', source].join('\n')reproducesemitGuarded’s output byte for byte.declaresandrequiresare the union across the arms, since the host’s preprocessor picks the arm and the composer cannot know which: every name any arm declares is one the host’s prelude must not collide with, and every symbol any arm needs is one the host must provide. Throws for a preamble mismatch exactly asemitGuardeddoes.
함께 보기
소스
src/core/variant-family.ts, 79행, 커밋 c66579bf 기준