emitGlslModule
이 페이지에서

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

매개변수

m ModuleDecl

the module to emit.

stage선택 사항 'vertex' | 'fragment'

which stage to emit, or omitted for the whole module.

opts선택 사항 GlslEmitOptions

the GLSL options and the shared emit options.

반환값

string

the GLSL ES 3.00 source, #version 300 es first.

예외

@link ValidationError

when the module fails a core rule, and UnsupportedFeatureError (SD0030) when this target cannot spell something the module needs: a @compute entry that is not declared portable, a multisampled texture load, f16, subgroups, a read_write storage binding, a storage element type outside the list above, a vertex entry returning a bare non-struct output, a raw statement with no glsl text, or a stage with more than one entry, which has one main() to give them (name it with emitGlslStages’s vertexEntry or fragmentEntry).

설명

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 기준

이 페이지 편집 문제 보고