VariantFamily
이 페이지에서

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 variants order: the id set a pipeline cache keys its programs by.

인스턴스 메서드

get (key: string): Variant<A> | undefined

Look one variant up by key; undefined when 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' }): string

One 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 corresponding emit() 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' }): EmitFragment

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

emitGuarded returns a whole stage, preamble included. A ladder pasted into a host program through an #include cannot carry a second #version, so here the preamble comes back as data, exactly as emitGlslFragment returns it, and [...preamble, '', source].join('\n') reproduces emitGuarded’s output byte for byte.

declares and requires are 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 as emitGuarded does.

함께 보기

소스

src/core/variant-family.ts, 79행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고