import { AttribProps, DrawMode, UniformProps } from '@df0/types'; import { AttribManager } from './AttribManager'; import { WebGLManager } from './WebGLManager'; export declare type UniformData = { [key: string]: UniformProps; }; export declare type AttribData = { [key: string]: AttribProps; }; /** * An object that describes all of the necessary data to create and manage * this program within the renderer. */ export interface EngineProgramDefinition { uniforms: UniformData; attribs: AttribData; vertexShader: string; fragmentShader: string; } export declare type UniformSetter = (el: any) => void; export declare type UniformSetters = { [k in keyof T['uniforms']]: UniformSetter; }; export declare type UniformLocs = { [k in keyof T['uniforms']]: WebGLUniformLocation; }; export declare type AttribManagers = { [k in keyof T['attribs']]: AttribManager; }; /** * Create a setter which writes the given uniform specified by `props` to `loc`. * Note that this function does not call gl.useProgram(). * * @param gl The WebGL rendering context this uniform is in. * @param loc The uniform location to write to. * @param props UniformProps for this uniform. */ export declare function getUniformSetter(gl: WebGL2RenderingContext, loc: WebGLUniformLocation, props: UniformProps): UniformSetter; /** * Takes in a gl context, program sources (frag and vert shader), * and data about attribs / uniforms and provides: * - attrib managers * - uniform setters * - skeleton code for rendering in our engine via `flush()` */ export declare class GenericRenderer { /** The program corresponding to this renderer. */ program: WebGLProgram; /** A dictionary of uniform setters, keyed by uniform name. */ uniformSetters: UniformSetters; /** A dictionary of attrib managers, keyed by attrib name. */ attribManagers: AttribManagers; /** * Uniform data for this program. Typically not used after construction. * Kept for use in inherited classes. */ uniformData: UniformData; /** * Uniform data for this program. Typically not used after construction. * Kept for use in inherited classes. */ attribData: AttribData; /** * Uniform locs for this program. Typically not referenced directly, * but rather through generated uniformSetters. Kept for use in inherited classes. */ uniformLocs: UniformLocs; /** GameGLManager corresponding to this program. */ manager: U; /** The number of queued vertices so far. Used for batch rendering. */ verts: number; /** * Create a renderer from a GameGLManager and program data. * @param glManager GameGLManager which holds context for rendering this program. * @param programData ProgramData describing this program. */ constructor(glManager: U, programData: T); /** * Run by flush(). Override this in child classes. Programs with uniformss * should always override this. */ setUniforms(): void; /** * Draw all buffered vertices to the screen. * @param drawMode The drawing mode for the buffered vertices. Default: Triangles. */ flush(drawMode?: DrawMode): void; }