compile
On this page

compile()

Function in Authoring

Compile TypeShade TypeScript source into the module and generated shader outputs.

import { compile } from 'typeshade'

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

Syntax

function compile(source: string, options: CompileOptions = {}): CompileResult

Parameters

source string
optionsoptional CompileOptions

Return value

CompileResult

Description

The source must carry the "use typeshade" directive (compileTsSource’s requireDirective default): without it the result has one MISSING_DIRECTIVE error and nothing else. When the front end reports an error the backends are not run at all, so wgsl and glsl are undefined and eval throws; a partial module is never packed into shader text. When the front end reports no error, a WGSL emitter that throws anyway (a literal the target cannot spell, an IR the emitter rejects) is reported as one BACKEND error diagnostic rather than an exception, and wgsl and glsl are again undefined. GLSL is attempted for every module whose WGSL exists; when the GLSL emitter throws on a module with a render entry (a binding whose GLSL lowering is not supported yet, Rule 10.5) the module has still compiled: wgsl stays, glsl is undefined, and the throw is one BACKEND diagnostic with category warning. A compute entry beside a render entry runs on WebGL2 as its pass program (change 0054, Rule 10.3), so glsl holds what the render entries reach, and a compute entry with no pass program is one more BACKEND warning. A compute-only module gets glsl: undefined with no diagnostic, since it has no vertex or fragment program to miss. See CompileResult for each field.

options.fileName names the source; see CompileOptions.fileName for when the default placeholder is not good enough.

In the guide

See also

Source

src/compiler/ts/compile.ts, line 185, at commit af54ddad5

Edit this page Report a problem