linkVariants
On this page

linkVariants()

Function in Variants

Emit, compile and link every variant of a family on a real WebGL2 context.

import { linkVariants } from 'typeshade'

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

Syntax

function linkVariants<A extends Record<string, readonly unknown[]>>(
gl: GlLinker,
family: VariantFamily<A>,
opts?: EmitOptions,
): readonly VariantLinkResult[]

Parameters

gl GlLinker

a WebGL2 context, or anything satisfying GlLinker.

family VariantFamily<A>

the family to enumerate; every key in family.keys is attempted.

optsoptional EmitOptions

emit options, applied to every variant equally. To check the production output, pass the same plugins the production emit uses, for example { plugins: obfuscate() }.

Return value

readonly VariantLinkResult[]

one result per key, in family.keys order.

Description

A module type-checks as a whole, but the combination of axis values a host actually selects is only proven when a driver compiles and links it. This function enumerates the family, emits GLSL ES 3.00 for each variant, compiles the vertex and fragment shaders and links them into a program, and reports the outcome per key.

const gl = canvas.getContext('webgl2')!
const failed = linkVariants(gl, family).filter((r) => !r.ok)
expect(failed, failed.map((r) => `${r.key}: ${r.failedAt} ${r.log}`).join('\n')).toEqual([])

Every variant is attempted even after one fails, so the result lists every broken combination in one run.

GL objects are deleted as it goes: a family is a cartesian product, and a matrix with a few axes would otherwise leak hundreds of programs on a context that is usually shared with a live page.

See also

Source

src/core/variant-link.ts, line 98, at commit 26de7be8

Edit this page Report a problem