// luma.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors import {UniformFormat} from '../../types'; import {PropType} from '../filters/prop-types'; import type {UniformTypes, UniformValue} from '../utils/uniform-types'; // To avoid dependency on core module, do not import `Binding` type. // The ShaderModule is not concerned with the type of `Binding`, // it is the repsonsibility of `splitUniformsAndBindings` in // ShaderInputs to type the result of `getUniforms()` type Binding = unknown; // import type {Binding} from '@luma.gl/core'; export type UniformInfo = { format?: UniformFormat; } & PropType; // Helper types type BindingKeys = {[K in keyof T]: T[K] extends UniformValue ? never : K}[keyof T]; type UniformKeys = {[K in keyof T]: T[K] extends UniformValue ? K : never}[keyof T]; export type PickBindings = {[K in BindingKeys>]: T[K]}; export type PickUniforms = {[K in UniformKeys>]: T[K]}; /** * A shader module definition object * @note `UniformsT` & `BindingsT` are deduced from `PropsT` by default. If * a custom type for `UniformsT` is used, `BindingsT` should be also be provided. */ export type ShaderModule< PropsT extends Record = Record, UniformsT extends Record = PickUniforms, BindingsT extends Record = PickBindings > = { /** Used for type inference not for values */ props?: Required; /** Used for type inference, not currently used for values */ uniforms?: UniformsT; /** Used for type inference, not currently used for values */ bindings?: BindingsT; name: string; fs?: string; vs?: string; /** Uniform shader types @note: Both order and types MUST match uniform block declarations in shader */ uniformTypes?: Required>; // Record; /** Uniform JS prop types */ uniformPropTypes?: Record; /** Default uniform values */ defaultUniforms?: Required; // Record; /** Function that maps props to uniforms & bindings */ getUniforms?: ( props?: Partial, prevUniforms?: UniformsT ) => Partial; defines?: Record; /** Injections */ inject?: Record; dependencies?: ShaderModule[]; /** Information on deprecated properties */ deprecations?: ShaderModuleDeprecation[]; /** Internal */ normalized?: boolean; }; /** Use to generate deprecations when shader module is used */ export type ShaderModuleDeprecation = { type: string; regex?: RegExp; new: string; old: string; deprecated?: boolean; };