import { Bindable } from './bindable'; import { AbstractObject } from './object'; import { Shader } from './shader'; /** * WebGL Program wrapper encapsulating program creation, shader attachment, linking, binding, as well as attribute and * uniform location retrieval. A program is intended to be used as follows: * * ``` * const vert = new Shader(this._context, gl.VERTEX_SHADER, 'ndcvertices.vert (blit)'); * vert.initialize(require('./shaders/ndcvertices.vert')); * const frag = new Shader(this._context, gl.FRAGMENT_SHADER, 'blit.frag'); * frag.initialize(require('./shaders/blit.frag')); * * this._program = new Program(this._context, 'BlitProgram'); * this._program.initialize([vert, frag]); * * this.aVertex = this._program.attribute('a_vertex'); * const uTexture = this._program.uniform('u_texture'); * * this._program.bind(); * gl.uniform1i(uTexture, 0); * // ... draw * this._program.unbind(); * ``` */ export declare class Program extends AbstractObject implements Bindable { /** * Default program, e.g., used for unbind. */ static readonly DEFAULT_PROGRAM: undefined; /** @see {@link shaders} */ protected _shaders: Shader[]; /** @see {@link linked} */ protected _linked: boolean; /** * Creates a WebGLProgram object and attaches, and references all shaders to it. The program is then linked. All * shaders have to be initialized in order to be attached and at least on vertex and one fragment shader has to be * present. Note that the shaders are not detached by default. If neither the shader objects nor recompilation is * required all shaders should be detached manually after initialization/creation. * @param shaders - Vertex and fragment shaders that are to be attached to the program. * @param link - Whether or not to immediately link the program iff provided shader(s) are attached successfully. * @returns - Either a new program or undefined if linking failed or one of the shaders is invalid/not compiled. */ protected create(shaders?: Array, link?: boolean): WebGLProgram | undefined; /** * Delete the program object on the GPU. This should have the reverse effect of `create`. */ protected delete(): void; /** * Attaches and references all given shaders. Attach is expected to be called once within creation of a Program. * Shaders that are not initialized will be skipped/not attached. * @param shaders - All shaders to be attached to the program for linking. * @param link - Whether or not to link the program again after attaching the shader(s). * @returns - True if attaching all shaders and linking succeeded, false otherwise. */ attach(shaders: Shader | Array, link?: boolean): boolean; /** * Detaches one or multiple shaders from the program. Note that relinking is not invoked automatically. * @param shaders - Shaders that are to be deleted. */ detach(shaders: Shader | Array): void; /** * Links the program with all its already attached shaders. If linking fails, a developer log with additional * information is provided. * @returns - True if linking the program succeeded, false otherwise. */ link(): boolean; /** * Activates this program for use. */ bind(): void; /** * Deactivates this/any program for use. */ unbind(): void; /** * Requests the location of a uniform of the program. * @param uniform - Uniform identifier to request location of. */ uniform(uniform: string): WebGLUniformLocation; /** * Requests the location of an attribute of the program. * @param attribute - Attribute identifier to request location of. * @param location - Attribute location (if WebGL2 location is used) * @returns - Location of the attribute (or location parameter if provided). */ attribute(attribute: string, location?: GLuint): GLint; /** * Provides access (leaky abstraction) to all shaders attached to this program. */ get shaders(): Array; /** * Read access the the program's link status. True if last linking was successful. */ get linked(): boolean; }