/** * a base GL Shader object * @category Rendering */ export default class GLShader { /** * @param {WebGLRenderingContext} gl - the current WebGL rendering context * @param {string} vertex - a string containing the GLSL source code to set * @param {string} fragment - a string containing the GLSL source code to set * @param {string} [precision=auto detected] - float precision ('lowp', 'mediump' or 'highp'). * @see https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/GLSL_Shaders * @example * // create a basic shader * let myShader = new me.GLShader( * // WebGL rendering context * gl, * // vertex shader * [ * "void main() {", * " gl_Position = doMathToMakeClipspaceCoordinates;", * "}" * ].join("\n"), * // fragment shader * [ * "void main() {", * " gl_FragColor = doMathToMakeAColor;", * "}" * ].join("\n") * ) * // use the shader * myShader.bind(); */ constructor(gl: WebGLRenderingContext, vertex: string, fragment: string, precision?: string); /** * the active gl rendering context * @type {WebGLRenderingContext} */ gl: WebGLRenderingContext; /** * `true` once {@link destroy} has been called. After this flag is * `true`, every method on the shader is a silent no-op — callers * holding a stale reference (e.g. a still-registered update loop) * do not crash the frame. * @type {boolean} * @readonly */ readonly destroyed: boolean; /** * `true` while the WebGL context is lost (and until it's * restored). The GL program/attributes/uniforms are released * during the suspended window but the shader source code is * preserved so {@link _onContextRestored} can rebuild the * program against the new context. User code generally doesn't * read this — methods short-circuit internally — but it's * available for diagnostic / debug-plugin tooling. * @type {boolean} * @readonly */ readonly suspended: boolean; _sourceVertex: string; _sourceFragment: string; _precision: string | undefined; _uniformCache: any; program: WebGLProgram; uniforms: object; attributes: number[]; /** * (Re)compile the shader program against `this.gl` from the * preserved source. Called from the constructor and from * {@link _onContextRestored}. Replays any cached uniform values * against the freshly-extracted uniforms proxy. * @private */ private _compile; vertex: any; fragment: any; /** * Handler for {@link ONCONTEXT_LOST}. Tears down the GL program * but preserves the shader source + cached uniform values so the * shader can be transparently rebuilt on context restore. * @private */ private _onContextLost; /** * Handler for {@link ONCONTEXT_RESTORED}. Re-compiles and * re-links the shader against the new GL context, then replays * any cached uniform values via {@link _compile}. * @private */ private _onContextRestored; /** * Installs this shader program as part of current rendering state */ bind(): void; /** * returns the location of an attribute variable in this shader program * @param {string} name - the name of the attribute variable whose location to get. * @returns {GLint} number indicating the location of the variable name if found. Returns -1 otherwise */ getAttribLocation(name: string): GLint; /** * Set the uniform to the given value * @param {string} name - the uniform name * @param {object|Float32Array} value - the value to assign to that uniform * @example * myShader.setUniform("uProjectionMatrix", this.projectionMatrix); */ setUniform(name: string, value: object | Float32Array): void; /** * activate the given vertex attribute for this shader * @param {WebGLRenderingContext} gl - the current WebGL rendering context * @param {object[]} attributes - an array of vertex attributes * @param {number} stride - the size of a single vertex in bytes */ setVertexAttributes(gl: WebGLRenderingContext, attributes: object[], stride: number): void; /** * destroy this shader objects resources (program, attributes, uniforms). * Idempotent — calling destroy twice (or after a context-lost suspend) * is safe. Unsubscribes from the renderer's context lost / restored * events so a destroyed shader is never automatically resurrected. */ destroy(): void; } //# sourceMappingURL=glshader.d.ts.map