import { Context } from './context'; import { AbstractObject } from './object'; /** * WebGL shader wrapper encapsulating shader creation, compilation, and deletion. A shader can be attached to multiple * Programs for linking, and can be deleted if detached from all (linked) programs. The expected default behavior is to * create a shader, attach it to programs, and discard is immediately after all programs are created (linked). If, * however, the source of a shader needs to be changed, e.g., for replacements or other modifications, the shader * object should be kept and, on change, all programs that have the shader attached have to be invalidated/relinked * manually. * * ``` * var frag = new gloperate.Shader(context, context.gl.FRAGMENT_SHADER, 'EmptyFragmentShader'); * var vert = new gloperate.Shader(context, context.gl.VERTEX_SHADER, 'EmptyVertexShader'); * vert.initialize('void main() { }'); * frag.initialize('void main() { }'); * * var prog = new gloperate.Program(context, 'EmptyProgram'); * prog.initialize([frag, vert]); * ``` */ export declare class Shader extends AbstractObject { /** @see {@link type} */ protected _type: GLenum; /** @see {@link source} */ protected _source: string; /** @see {@link compiled} */ protected _compiled: boolean; /** * Map of replacement strings and the value to replace them with. */ protected _replacements: undefined | Map; /** * Object constructor, requires a context and a valid identifier. * @param context - Valid context to create the object for. * @param type - Either GL_VERTEX_SHADER or GL_FRAGMENT_SHADER. * @param identifier - Meaningful name for identification of this instance. */ constructor(context: Context, type: GLenum, identifier?: string); /** * Creates a shader, sets the shader source, and compiles the shader. If the shader source cannot be compiled, the * identifier and an info log are logged to console and the shader object is deleted. Note that a '#version 300 es' * is added in case the shader source is compiled in a WebGL2 context. * @param source - Shader source. * @param compile - Whether or not to compile the shader immediately if a source is provided. * @returns - Either a new shader or undefined if compilation failed. */ protected create(source?: string, compile?: boolean): WebGLShader | undefined; /** * Delete the shader object. This should have the reverse effect of `create`. */ protected delete(): void; /** * Triggers recompilation of a shader. This is usually used internally automatically, but exposed here for leaky * abstraction. It should not be required to invoke this manually in most cases. The shader object is marked as * compiled iff the source compiled successfully. Note that invalidation of all programs this shader is attached * to needs to be done manually. */ compile(): void; /** * Adds a search-replacement-pair that is processed every time the shaders is recompiled. Note that recompilation * has to be triggered manually. Internally, all replacements are stored as a Map of search and replacement values. * Thus, specifying a replacement value overrides an existing search value. * @param searchValue - String that is to be searched (all occurrences) and replaced by replace value. * @param replaceValue - The value to be used as replacement for all search value occurrences. */ replace(searchValue: string, replaceValue: string): void; /** * Either VERTEX_SHADER or FRAGMENT_SHADER. */ get type(): GLenum; /** * Allows to change the shader's source. Note that this will not recompile the shader. */ set source(source: string); /** * Read access to the shader's source (without replacements applied). */ get source(): string; /** * Processes all search values and replaces them with the replace value on the source. * @returns The source with all replacements applied. */ get sourceWithReplacements(): string; /** * Read access the the shader's compile status. True if last compilation was successful. */ get compiled(): boolean; }