@luma.gl/shadertools
Version:
Shader module system for luma.gl
91 lines • 3.8 kB
TypeScript
import type { ShaderModule } from "./shader-module.js";
/**
* Shader stages supported by shader-module uniform-layout validation helpers.
*/
export type ShaderModuleUniformLayoutStage = 'vertex' | 'fragment' | 'wgsl';
/**
* Describes the result of comparing declared `uniformTypes` with the fields
* found in a shader uniform block.
*/
export type ShaderModuleUniformLayoutValidationResult = {
/** Name of the shader module being validated. */
moduleName: string;
/** Expected block name derived from the shader module name. */
uniformBlockName: string;
/** Shader stage that was inspected. */
stage: ShaderModuleUniformLayoutStage;
/** Field names declared by the module metadata. */
expectedUniformNames: string[];
/** Field names parsed from the shader source. */
actualUniformNames: string[];
/** Whether the declared and parsed field lists match exactly. */
matches: boolean;
};
/**
* Parsed information about one GLSL uniform block declaration.
*/
export type GLSLUniformBlockInfo = {
/** Declared block type name. */
blockName: string;
/** Optional instance name that follows the block declaration. */
instanceName: string | null;
/** Raw layout qualifier text, if present. */
layoutQualifier: string | null;
/** Whether any explicit layout qualifier was present. */
hasLayoutQualifier: boolean;
/** Whether the block explicitly declares `layout(std140)`. */
isStd140: boolean;
/** Raw source text inside the block braces. */
body: string;
};
/**
* Logging surface used by validation and warning helpers.
*/
type Logger = {
/** Error logger compatible with luma's deferred log API. */
error?: (...args: unknown[]) => () => unknown;
/** Warning logger compatible with luma's deferred log API. */
warn?: (...args: unknown[]) => () => unknown;
};
/**
* Returns the uniform block type name expected for the supplied shader module.
*/
export declare function getShaderModuleUniformBlockName(module: ShaderModule): string;
/**
* Returns the ordered field names parsed from a shader module's uniform block.
*
* @returns `null` when the stage has no source or the expected block is absent.
*/
export declare function getShaderModuleUniformBlockFields(module: ShaderModule, stage: ShaderModuleUniformLayoutStage): string[] | null;
/**
* Computes the validation result for a shader module's declared and parsed
* uniform-block field lists.
*
* @returns `null` when the module has no declared uniform types or no matching block.
*/
export declare function getShaderModuleUniformLayoutValidationResult(module: ShaderModule, stage: ShaderModuleUniformLayoutStage): ShaderModuleUniformLayoutValidationResult | null;
/**
* Validates that a shader module's parsed uniform block matches `uniformTypes`.
*
* When a mismatch is detected, the helper logs a formatted error and optionally
* throws via {@link assert}.
*/
export declare function validateShaderModuleUniformLayout(module: ShaderModule, stage: ShaderModuleUniformLayoutStage, options?: {
log?: Logger;
throwOnError?: boolean;
}): ShaderModuleUniformLayoutValidationResult | null;
/**
* Parses all GLSL uniform blocks in a shader source string.
*/
export declare function getGLSLUniformBlocks(shaderSource: string): GLSLUniformBlockInfo[];
/**
* Emits warnings for GLSL uniform blocks that do not explicitly declare
* `layout(std140)`.
*
* @returns The list of parsed blocks that were considered non-compliant.
*/
export declare function warnIfGLSLUniformBlocksAreNotStd140(shaderSource: string, stage: Exclude<ShaderModuleUniformLayoutStage, 'wgsl'>, log?: Logger, context?: {
label?: string;
}): GLSLUniformBlockInfo[];
export {};
//# sourceMappingURL=shader-module-uniform-layout.d.ts.map