import { Game } from '../core'; import { Entity } from '../entity'; /** * Internal-use utility type representing a Shader Variable Resolution Function which retrieves a value from the Game */ declare type StaticShaderVariableResolver = (game: Game) => Float32Array | number; /** * Internal-use utility type representing a Shader Variable Resolution Function which retrieves a value from an Entity */ declare type EntityShaderVariableResolver = (e: Entity) => Float32Array | number; /** * Utility class for automatically retrieving attribute and uniform shader values from Entities, Components and other Game constructs * * Forms a critical component of the system's rendering approach, where Entities are able to specify their own Shaders. Utilised by the * EntityManager in the construction of Vertex Buffers, and by the WebGLRenderer in the upload of Uniforms * * Works in conjunction with VertexShader + FragmentShader configuration objects, which specify the names, sizes, types, and variation * patterns of their attributes and uniforms * * Mappings of ResolutionFunction> are broken into three categories - Attribute, EntityUniform and StaticUniform: * - Attribute - attributes, varying per vertex, to be retrieved from Entities in the construction of Vertex Buffers by the EntityManager * - example: `attribute vec2 a_Position;` - a vertex position, retrieved from an Entity's Model Component * * - EntityUniform - uniforms, varying per Entity, to be retrieved from Entities and uploaded once per draw call by the WebGLRenderer * - example: `uniform mat3 u_Transform2D;` - an Entity's Transformation Matrix, retrieved from its Transform Component * * - StaticUniform - uniforms, unrelated to Entities, to be retrieved from the Game and uploaded once per render call by the WebGLRenderer * - example: `uniform mat3 u_View2D;` - the 2D View Matrix, retrieved from the Game's World/Camera * * The mappings built into the class represent the supported set of built-in Attribute/Uniform names which, when used in Shaders, will * automatically be retrieved; thereby also setting out the relationship between a variable name and the Entity/engine data it reflects * * Allows for the registration of new mappings at application initialisation, facilitating the extension of the system's built-in Shader and * Component library * * Allows for the overriding of built-in mappings as an explicit choice separate from registration; supporting the augmentation of default * engine functionality but avoiding user error * * Handles errors in the absence of Resulution Functions for given names, preventing invalid WebGL draws * * // TODO the information in this class *could* be used to 'verify' an Entity's makeup - that it can be rendered with its designated Shader * * @see EntityShaderVariableResolver * @see StaticShaderVariableResolver * @see VertexShader * @see FragmentShader * @see EntityManager * @see WebGLRenderer */ export declare class ShaderVariableResolver { /** * Mappings supporting the automatic resolution of Attributes from Entity Components */ private static readonly ENTITY_ATTRIBUTE_MAPPINGS; /** * Mappings supporting the automatic resolution of draw-call Uniforms from Entity Components */ private static readonly ENTITY_UNIFORM_MAPPINGS; /** * Mappings supporting the automatic resolution of render-call Uniforms from Game constructs */ private static readonly STATIC_UNIFORM_MAPPINGS; /** * Resolve an Attribute value, given its name, from an Entity * * @param attributeName the name of the attribute to resolve a value for * @param entity the Entity to retrieve the value from * * @returns the resolved Attribute value */ static resolveAttribute(attributeName: string, entity: Entity): Float32Array | number; /** * Resolve a Uniform value, given its name, from an Entity * * @param uniformName the name of the uniform to resolve a value for * @param entity the Entity to retrieve the value from * * @returns the resolved Uniform value */ static resolveEntityUniform(uniformName: string, entity: Entity): Float32Array | number; /** * Resolve a Uniform value, given its name, from the Game * * @param uniformName the name of the uniform to resolve a value for * @param game the Game instance to retrieve the value from * * @returns the resolved Uniform value */ static resolveStaticUniform(uniformName: string, game: Game): Float32Array | number; /** * Register a new resolution function for a given unknown Shader Attribute name * * @param attributeName the name of the Attribute to register * @param resolve the resolution function to register */ static registerAttributeResolver(attributeName: string, resolve: EntityShaderVariableResolver): void; /** * Register a new resolution function for a given unknown Shader Uniform name, where that Uniform varies per Entity * * @param uniformName the name of the Uniform to register * @param resolve the resolution function to register */ static registerEntityUniformResolver(uniformName: string, resolve: EntityShaderVariableResolver): void; /** * Register a new resolution function for a given unknown Shader Uniform name, where that Uniform is unassocated with any given Entity * * @param uniformName the name of the Uniform to register * @param resolve the resolution function to register */ static registerStaticUniformResolver(uniformName: string, resolve: StaticShaderVariableResolver): void; /** * Override an existing resolution function for a given known Shader Attribute name * * @param attributeName the name of the Attribute to override * @param resolve the replacement resolution function */ static overrideAttributeResolver(attributeName: string, resolve: EntityShaderVariableResolver): void; /** * Override an existing resolution function for a given known Shader Uniform name, where that Uniform varies per Entity * * @param uniformName the name of the Uniform to override * @param resolve the replacement resolution function */ static overrideEntityUniformResolver(uniformName: string, resolve: EntityShaderVariableResolver): void; /** * Override an existing resolution function for a given known Shader Uniform name, where that Uniform is unassocated with any given * Entity * * @param uniformName the name of the Uniform to override * @param resolve the replacement resolution function */ static overrideStaticUniformResolver(uniformName: string, resolve: StaticShaderVariableResolver): void; } export {};