emitGlslFragment()
Function in Emit
Emit a module as a GLSL ES 3.00 fragment for a host that owns the program: the declarations and helper functions, without #version, without the precision lines and, by default, without the stage entry point.
import { emitGlslFragment } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function emitGlslFragment( m: ModuleDecl, stage?: 'vertex' | 'fragment', opts?: GlslEmitOptions & { entryPoints?: boolean },): EmitFragmentParameters
mModuleDeclthe module to emit.
stageoptional'vertex' | 'fragment'which stage’s scope to emit; omit for the whole module.
optsoptionalGlslEmitOptions & { entryPoints?: boolean }the
GlslEmitOptions, plusentryPointsto keep the entries.
Return value
the fragment: its source, preamble, declares and requires.
Exceptions
Errorthe same errors as
emitGlslModule.
Description
The host splices the returned source into
a program it assembles itself.
What the header would have carried comes back as data in EmitFragment.preamble:
the #version line, any #extension … : require a declared capability needs, and the
precision lines, including the ones for the integer and array sampler types derived from
the module’s texture bindings. A host merges and de-duplicates those across the
fragments it assembles.
Entry points are omitted unless opts.entryPoints is true. They are listed in
declares.entryPoints either way, and they still decide the stage scope, so the
fragment carries exactly the helpers, structs and bindings the stage’s entry reaches.
Examples
Example
import { emitGlslFragment } from 'typeshade'
const frag = emitGlslFragment(MODULE, 'fragment')// frag.preamble: ['#version 300 es', 'precision highp float;', 'precision highp int;']// frag.source: the declarations and helpers, ready to splice into a host programTargets
| Target | Support | Notes |
|---|---|---|
| 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 2508, at commit 26de7be8