UNPKG

blaze-2d

Version:

A fast and simple WebGL 2 2D game engine written in TypeScript

60 lines (59 loc) 2.6 kB
import { TextureUnit } from "../texture/texture"; import Color from "./color"; /** * Stores information about a {@link WebGLProgram}, such as it's attribute and uniform locations. */ export interface ShaderProgramInfo { program: WebGLProgram; attribLocations: { [index: string]: number; }; uniformLocations: { [index: string]: WebGLUniformLocation; zIndex: WebGLUniformLocation; texture?: WebGLUniformLocation; numOfTiles?: WebGLUniformLocation; }; } /** * Creates and compiles a shader from its source. * * @param gl The webgl context to use when creating the shader * @param type The type of shader to create (either `gl.VERTEX_SHADER` or `gl.FRAGMENT_SHADER`) * @param source The shader source as a string * @returns The compiled shader or undefined if there was an error when creating the shader */ export declare function createShader(gl: WebGL2RenderingContext, type: number, source: string): WebGLShader; /** * Creates a {@link WebGLProgram} instance with a vertex and fragment shader. * * @param gl The webgl context to use when creating the program * @param vertexShader The vertex shader of the program * @param fragmentShader The fragment shader of the program * @returns The created program or undefined if there was an error when creating the program */ export declare function createProgram(gl: WebGL2RenderingContext, vertexShader: WebGLShader, fragmentShader: WebGLShader): WebGLProgram; /** * Creates each webgl shader and links them together in a {@link WebGLProgram} * * @param gl The webgl context to use when creating the shaders * @param vsSource The source of the vertex shader as a string * @param fsSource The source of the fragment shader as a string * @returns The created {@link WebGLProgram} instance */ export declare function createShaderProgram(gl: WebGL2RenderingContext, vsSource: string, fsSource: string): WebGLProgram; /** * Clears the color and depth buffer of the webgl context. * * @param gl The webgl context to clear * @param color The color to use as the clear color */ export declare function clear(gl: WebGL2RenderingContext, color?: Color): void; /** * Creates a {@link WebGLTexture} and loads an image onto it. * * @param gl The {@link WebGL2RenderingContext} to use to load the texture * @param textureUnit The texture unit to to take the {@link Texture} from and to bind the {@link WebGLTexture} to * @returns The WebGL texture that was created */ export declare function loadTexture(gl: WebGL2RenderingContext, textureUnit: TextureUnit): WebGLTexture;