import { GameBase } from '../core/game.base'; import { Color } from '../math/color'; import { ShaderProgram } from '../shader/program/shaderProgram'; import { TextureAtlas } from '../texture/textureAtlas'; import { RendererConfig } from './renderer.config'; /** * Core WebGL Renderer; utilised by the EntityManager to defer the rendering of Entities to the Canvas * * Handles every aspect of WebGL API interaction; including the construction and maintenance of Shaders and VBOs, and the rendering of game * objects by way of a per-render-call configuration object * * Designed to operate entirely on outside configuration, so as to enable the EntityManager to implement abstracted optimisations for things * like vertex management, buffering and shader switching */ export declare class Renderer { /** The WebGLRenderingContext retrieved from the Canvas */ private readonly gl; /** Game background Color, in its GL-friendly Float32Array form */ private readonly backgroundColor; /** A maintained list of shader program specifications; mapped by their name for simple management and usage */ private readonly shaderPrograms; /** Active shader program specification; used for frame-to-frame optimisation of shader switching */ private activeShaderProgram; /** A maintained list of VBO handles; mapped by their name for simple managment and usage */ private readonly vbos; /** Active VBO name; used for frame-to-frame optimisation of VBO switching and vertexAttribPointer() calls */ private activeVBOName; /** A maintained list of texture specifications; mapped by their name for simple management and usage */ private readonly textures; /** Active texture specification; used for render-to-render optimisation of texture switching */ private activeTexture; /** Current rendering mode; used for differentiating some rendering functionality between 2D and 3D Games */ private mode; /** Reference to the Game the Renderer belongs to */ private game; /** * Constructor. Take the Game the Renderer belongs to, then perform one-time setup of the Canvas context * * @param game the Game the Renderer belongs to * @param clearColor the Game's background color, to be set once as the gl clearColor */ constructor(game: GameBase, clearColor: Color); /** * Retrieve the active texture unit, used for configuring Sampler2Ds in shaders */ get activeTextureUnit(): number; /** * Clear the drawing buffer with the appropriate bitmask, accounting for depth buffer if we're rendering in 3D */ clearScreen(): void; /** * Create and store a VBO with a given name to be used as a buffering target and vertex source later on * * @param name the name of the VBO */ createVBO(name: string): void; /** * Delete a VBO with a given name to release memory no longer required by the application * * @param name the name of the VBO */ deleteVBO(name: string): void; /** * Initialise and store a shader program and perform one-time setup of its attribute and uniform locations * * @param shader the ShaderProgram specification */ createShaderProgram(shader: ShaderProgram): void; /** * Create a texture from an image with a given source * * @param textureAtlas the TextureAtlas representing the texture to load */ createTexture(textureAtlas: TextureAtlas): void; /** * Extra WebGL state configuation for specific 2D and 3D related state */ setRenderingMode(mode: '2D' | '3D'): void; /** * Generic rendering method; using the information in a given RendererConfig, render some Entities * * @param config the RendererConfig specifying what and how to render */ render(config: RendererConfig): void; /** * Unlink the Renderer's Game reference, allowing for garbage collection on Game destroy * * // TODO incomplete, part of the first-working-version of the destroy() solution */ destroy(): void; /** * One-time WebGL global state configuration, where configurations apply to both 2D and 3D rendering modes */ private init; /** * Compile an individual FragmentShader or VertexShader * * @param name the name of the shader * @param type the type of the shader - vertex or fragment * @param src the shader source * * @returns the compiled WebGLShader */ private compileShader; /** * Perform one-time setup of a ShaderProgram's attribute and uniform locations, storing the information in the ShaderProgramSpec map * * @param program the WebGLProgram to initialise * @param spec the ShaderProgramSpec that was used to create the program */ private initializeShaderProgram; /** * Switch to the named Shader Program * * @param name the name of the Shader Program to switch to */ private useShaderProgram; /** * Switch to the VBO with the given VBOConfig, configuring attribute points. * * Rebuffers the VBO's vertex array if it has been marked as changed between renders * * @param vbo the VBOConfig specifying the VBO to switch to */ private useVBO; /** * Switch to the named Texture * * @param name the name of the Texture to switch to */ private useTexture; /** * Upload a uniform of a given type and value to the given uniform location as previously retrieved for a ShaderProgram * * @param location the loction of the uniform to upload * @param type the UniformType of the uniform to upload * @param value the value of the uniform to upload */ private loadUniform; /** * Check whether or not a given image is sourced from the same origin as that which Aura is running on; used in supporting crossorign * textures * * @param url the source URL of the image * @returns */ private imageIsSameOrigin; }