emitGlslModule()
함수, 출력 분류
Emit a module as GLSL ES 3.00 source.
import { emitGlslModule } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function emitGlslModule( m: ModuleDecl, stage?: 'vertex' | 'fragment', opts?: GlslEmitOptions,): string매개변수
mModuleDeclthe module to emit.
stage선택 사항'vertex' | 'fragment'which stage to emit, or omitted for the whole module.
opts선택 사항GlslEmitOptionsthe GLSL options and the shared emit options.
반환값
string
the GLSL ES 3.00 source, #version 300 es first.
예외
@link ValidationErrorwhen the module fails a core rule, and
UnsupportedFeatureError(SD0030) when this target cannot spell something the module needs: a@computeentry that is not declaredportable, a multisampled texture load,f16, subgroups, aread_writestorage binding, a storage element type outside the list above, a vertex entry returning a bare non-struct output, a raw statement with noglsltext, or astagewith more than one entry, which has onemain()to give them (name it withemitGlslStages’svertexEntryorfragmentEntry).
설명
Pass 'vertex' or 'fragment' to get one
compilable stage, the string gl.shaderSource takes: that stage’s entry becomes
void main(), and only the structs, bindings and helper functions the entry reaches are
declared. Omit the stage for a whole-module string; a module with entries for both
stages then contains two main() functions, which no GLSL compiler accepts, so the
whole-module form is for modules without entries and for inspecting output.
The source is assembled in this order: #version 300 es, any #extension directive a
declared capability needs, the precision lines, a #define per override, plain structs,
consts and module variables, layout(std140) uniform blocks and sampler uniforms, helper functions, then the
entry: its in/out varyings, a <name>_impl function where the body cannot be
inlined into main(), and main() itself. A uniform struct binding becomes a std140
block whose byte offsets are the ones wgslLayout reports, so a host packs one
buffer for both backends. A storage binding, which WebGL2 cannot express, is read from
a data texture instead: array<f32>, array<u32>, array<i32>, array<vecN<f32>> and
arrays of structs with f32, u32 and vecN<f32> fields are supported, and data[i]
becomes a texelFetch at (i % width, i / width) in a sampler2D (R32F),
usampler2D (R32UI) or isampler2D (R32I) of the same name. A compute entry
declared portable: true is emitted as a fragment pass; see
lowerComputeToFragment.
opts.floatPrecision sets the precision <p> float; line; see
GlslEmitOptions.floatPrecision for when 'mediump' is safe.
opts.overrideValues pins specialization constants as #defines, since GLSL ES 3.00
has no pipeline-time equivalent. The shared EmitOptions apply too: parens,
plugins and fp64Flavor.
예제
예제
import { emitGlslModule } from 'typeshade'
const vs = emitGlslModule(MODULE, 'vertex')const fs = emitGlslModule(MODULE, 'fragment', { floatPrecision: 'mediump' })대상별 지원
| 대상 | 지원 | 비고 |
|---|---|---|
| WGSL (WebGPU) | 해당 없음 | |
| GLSL ES 3.00 (WebGL2) | 지원 | Writes GLSL ES 3.00 for WebGL2. |
| CPU 오라클 | 해당 없음 |
관련 가이드
함께 보기
소스
src/core/backends/glsl.ts, 2461행, 커밋 c66579bf 기준