emitGlslStages
On this page

emitGlslStages()

Function in Emit

Emit both stages of one module, lowering and optimizing it once.

import { emitGlslStages } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

function emitGlslStages(
m: ModuleDecl,
opts?: GlslEmitOptions & { vertexEntry?: string; fragmentEntry?: string },
): { vertex: string; fragment: string }

Parameters

m ModuleDecl

the module to emit.

optsoptional GlslEmitOptions & { vertexEntry?: string; fragmentEntry?: string }

the GlslEmitOptions, plus vertexEntry and fragmentEntry.

Return value

{ vertex: string; fragment: string }

the vertex and fragment sources, each #version 300 es first.

Exceptions

Error

the same errors as emitGlslModule.

UnsupportedFeatureError

GLSL allows one main() per stage, so a module with two fragment entries needs fragmentEntry to say which one becomes main(); the other entries are left out of that stage’s source, and with none named such a stage throws UnsupportedFeatureError (SD0030).

SD0030

GLSL allows one main() per stage, so a module with two fragment entries needs fragmentEntry to say which one becomes main(); the other entries are left out of that stage’s source, and with none named such a stage throws UnsupportedFeatureError (SD0030).

Description

The result is identical to calling emitGlslModule(m, 'vertex') and emitGlslModule(m, 'fragment'), at about half the cost, since the optimizer runs once for both stages. Use it from a host that creates a pipeline, which always needs both.

opts.vertexEntry and opts.fragmentEntry name the entry to emit for each stage, for a module that declares several entries of one stage. GLSL allows one main() per stage, so a module with two fragment entries needs fragmentEntry to say which one becomes main(); the other entries are left out of that stage’s source, and with none named such a stage throws UnsupportedFeatureError (SD0030). The output does not depend on which other entries the module carries, because every optimizer pass works on one function at a time.

Examples

Example

import { emitGlslStages } from 'typeshade'
const { vertex, fragment } = emitGlslStages(MODULE, { fragmentEntry: 'fs_pattern' })

Targets

TargetSupportNotes
WGSL (WebGPU) Does not apply
GLSL ES 3.00 (WebGL2) Supported

Writes GLSL ES 3.00 for WebGL2.

CPU oracle Does not apply

In the guide

See also

Source

src/core/backends/glsl.ts, line 2558, at commit 26de7be8

Edit this page Report a problem