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 26de7be8.

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 compute entry beside the render pair, a binding the GLSL emulation cannot spell) the module has still compiled: wgsl stays, glsl is undefined, and the throw is one BACKEND diagnostic with category warning. A compute-only module gets glsl: undefined with no diagnostic, since GLSL ES 3.00 has no compute stage 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 176, at commit 26de7be8

Edit this page Report a problem