/** * GLSL Compiler -- `BoundaryDef` to uniform declarations + `bindUniforms()` helper. * * Generates GLSL preamble code with: * - `#define` statements for state indices (`STATE_MOBILE 0`, etc.) * - `uniform` declarations for each value key * - A JS helper function string for binding uniform values to WebGL * * @module */ import type { Boundary, StateUnion } from '@czap/core'; /** GLSL scalar, vector, matrix, or sampler type used in a uniform declaration. */ export type GLSLType = 'float' | 'int' | 'uint' | 'bool' | 'vec2' | 'vec3' | 'vec4' | 'ivec2' | 'ivec3' | 'ivec4' | 'mat2' | 'mat3' | 'mat4' | 'sampler2D' | 'samplerCube'; /** A single GLSL uniform declaration produced by {@link GLSLCompiler.compile}. */ export interface GLSLUniform { /** Uniform name (prefixed `u_`, snake-case). */ readonly name: string; /** Inferred GLSL type; float when any state value is non-integer or negative. */ readonly type: GLSLType; /** Optional inline comment emitted alongside the declaration. */ readonly comment?: string; } /** A single GLSL `#define` produced by {@link GLSLCompiler.compile}. */ export interface GLSLDefine { /** Macro name (`STATE_*` or `STATE_COUNT`). */ readonly name: string; /** Macro value (always numeric, serialized as a string). */ readonly value: string; /** Optional inline comment emitted alongside the `#define`. */ readonly comment?: string; } /** * Output of {@link GLSLCompiler.compile}. * * `declarations` is the complete preamble block ready to prepend to a * shader; `bindUniforms` is a `function bindUniforms(gl, program, values)` * stringified helper that routes the values map into `uniform*` calls. */ export interface GLSLCompileResult { /** State-index `#define`s. */ readonly defines: readonly GLSLDefine[]; /** Uniform declarations, including the `u_state` index uniform. */ readonly uniforms: readonly GLSLUniform[]; /** Default uniform values keyed by uniform name (from the last state's values). */ readonly uniformValues: Record; /** * Per-state uniform values keyed by state name then `u_*` uniform name. Unlike * the flat {@link uniformValues} default (last-state-wins), this preserves * every state's authored values so the live runtime can resolve * `stateUniforms[currentState]` and update uniforms on each boundary crossing * — the GLSL analog of `ARIACompileResult.stateAttributes`. */ readonly stateUniforms: Record>; /** Pre-serialized `#define` + `uniform` declarations block. */ readonly declarations: string; /** Stringified `bindUniforms(gl, program, values)` helper. */ readonly bindUniforms: string; } /** * Compile a boundary definition and per-state numeric value maps into * GLSL `#define` statements, `uniform` declarations, and a `bindUniforms` * helper function string. * * @example * ```ts * import { Boundary } from '@czap/core'; * import { GLSLCompiler } from '@czap/compiler'; * * const boundary = Boundary.make({ * input: 'width', * at: [[0, 'mobile'], [768, 'desktop']], * }); * const result = GLSLCompiler.compile(boundary, { * mobile: { blur: 0.5, brightness: 1.0 }, * desktop: { blur: 0.0, brightness: 1.2 }, * }); * console.log(result.declarations); * // #define STATE_MOBILE 0 * // #define STATE_DESKTOP 1 * // uniform int u_state; * // uniform float u_blur; * // uniform float u_brightness; * ``` * * @param boundary - The boundary definition with states * @param states - Per-state numeric value maps * @returns A {@link GLSLCompileResult} with defines, uniforms, and helper code */ declare function compile(boundary: B, states: { [S in StateUnion & string]: Record; }): GLSLCompileResult; /** * Serialize a {@link GLSLCompileResult} into a full GLSL preamble string * including declarations and the `bindUniforms` helper. * * @example * ```ts * import { GLSLCompiler } from '@czap/compiler'; * * const result = GLSLCompiler.compile(boundary, states); * const glsl = GLSLCompiler.serialize(result); * // Prepend to your fragment shader source * const shaderSource = glsl + '\n' + mainShaderCode; * ``` * * @param result - The compile result to serialize * @returns A GLSL preamble string */ declare function serialize(result: GLSLCompileResult): string; /** * GLSL compiler namespace. * * Compiles boundary definitions into GLSL shader preambles containing * `#define` state constants, `uniform` declarations, and a JavaScript * `bindUniforms()` helper for setting uniform values via WebGL. * * @example * ```ts * import { Boundary } from '@czap/core'; * import { GLSLCompiler } from '@czap/compiler'; * * const boundary = Boundary.make({ * input: 'width', * at: [[0, 'sm'], [768, 'lg']], * }); * const result = GLSLCompiler.compile(boundary, { * sm: { intensity: 0.5 }, lg: { intensity: 1.0 }, * }); * const preamble = GLSLCompiler.serialize(result); * ``` */ export declare const GLSLCompiler: { readonly compile: typeof compile; readonly serialize: typeof serialize; }; export {}; //# sourceMappingURL=glsl.d.ts.map