The WebGLPipeline to which this Shader belongs.
The name of this Shader.
The vertex shader source code as a single string.
The fragment shader source code as a single string.
An array of attributes.
Array of objects that describe the vertex attributes.
The fragment shader source code.
A reference to the WebGL Rendering Context the WebGL Renderer is using.
The name of this shader.
A reference to the WebGLPipeline that owns this Shader.
A Shader class can only belong to a single pipeline.
The WebGLProgram created from the vertex and fragment shaders.
A reference to the WebGLRenderer instance.
The active uniforms that this shader has.
This is an object that maps the uniform names to their WebGL location and cached values.
It is populated automatically via the createUniforms method.
The amount of vertex attribute components of 32 bit length.
ReadonlyvertexThe size, in bytes, of a single vertex.
This is derived by adding together all of the vertex attributes.
For example, the Multi Pipeline has the following attributes:
inPosition - (size 2 x gl.FLOAT) = 8 inTexCoord - (size 2 x gl.FLOAT) = 8 inTexId - (size 1 x gl.FLOAT) = 4 inTintEffect - (size 1 x gl.FLOAT) = 4 inTint - (size 4 x gl.UNSIGNED_BYTE) = 4
The total, in this case, is 8 + 8 + 4 + 4 + 4 = 28.
This is calculated automatically during the createAttributes method.
The vertex shader source code.
Sets the program this shader uses as being the active shader in the WebGL Renderer.
This method is called every time the parent pipeline is made the current active pipeline.
OptionalsetAttributes: booleanShould the vertex attribute pointers be set? Default false.
Optionalflush: booleanFlush the pipeline before binding this shader? Default false.
Takes the vertex attributes config and parses it, creating the resulting array that is stored
in this shaders attributes property, calculating the offset, normalization and location
in the process.
Calling this method resets WebGLShader.attributes, WebGLShader.vertexSize and
WebGLShader.vertexComponentCount.
It is called automatically when this class is created, but can be called manually if required.
An array of attributes configs.
This method will create the Shader Program on the current GL context.
If a program already exists, it will be destroyed and the new one will take its place.
After the program is created the uniforms will be reset and this shader will be rebound.
This is a very expensive process and if your shader is referenced elsewhere in your game those references may then be lost, so be sure to use this carefully.
However, if you need to update say the fragment shader source, then you can pass
the new source into this method and it'll rebuild the program using it. If you
don't want to change the vertex shader src, pass undefined as the parameter.
OptionalvertSrc: stringThe source code of the vertex shader. If not given, uses the source already defined in this Shader.
OptionalfragSrc: stringThe source code of the fragment shader. If not given, uses the source already defined in this Shader.
Sets up the WebGLShader.uniforms object, populating it with the names
and locations of the shader uniforms this shader requires.
It works by first calling gl.getProgramParameter(program.webGLProgram, gl.ACTIVE_UNIFORMS) to
find out how many active uniforms this shader has. It then iterates through them,
calling gl.getActiveUniform to get the WebGL Active Info from each one. Finally,
the name and location are stored in the local array.
This method is called automatically when this class is created.
Removes all external references from this class and deletes the WebGL program from the WebGL context.
Does not remove this shader from the parent pipeline.
Checks to see if the given uniform name exists and is active in this shader.
The name of the uniform to check for.
Sets the program this shader uses as being the active shader in the WebGL Renderer.
Then resets all of the attribute pointers.
Resets the cached values of the given uniform.
The name of the uniform to reset.
Sets a 1f uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value of the float uniform.
Sets a 1fv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets a 1i uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value of the int uniform.
Sets a 1iv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets a 2f uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new X component of the vec2 uniform.
The new Y component of the vec2 uniform.
Sets a 2fv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets a 2i uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new X component of the ivec2 uniform.
The new Y component of the ivec2 uniform.
Sets a 2iv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets a 3f uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new X component of the vec3 uniform.
The new Y component of the vec3 uniform.
The new Z component of the vec3 uniform.
Sets a 3fv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets a 3i uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new X component of the ivec3 uniform.
The new Y component of the ivec3 uniform.
The new Z component of the ivec3 uniform.
Sets a 3iv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets a 4f uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
X component of the uniform
Y component of the uniform
Z component of the uniform
W component of the uniform
Sets a 4fv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets a 4i uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
X component of the uniform
Y component of the uniform
Z component of the uniform
W component of the uniform
Sets a 4iv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value to be used for the uniform variable.
Sets the vertex attribute pointers.
This should only be called after the vertex buffer has been bound.
It is called automatically during the bind method.
Optionalreset: booleanReset the vertex attribute locations? Default false.
Sets a boolean uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
The new value of the boolean uniform.
Sets a matrix 2fv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
Whether to transpose the matrix. Should be false.
The new values for the mat2 uniform.
Sets a matrix 3fv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
Whether to transpose the matrix. Should be false.
The new values for the mat3 uniform.
Sets a matrix 4fv uniform value based on the given name on this shader.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The name of the uniform to set.
Should the matrix be transpose
Matrix data
Sets the given uniform value/s based on the name and GL function.
This method is called internally by other methods such as set1f and set3iv.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The GL function to call.
The name of the uniform to set.
The new value of the uniform.
OptionalskipCheck: booleanSkip the value comparison? Default false.
Sets the given uniform value/s based on the name and GL function.
This method is called internally by other methods such as set1f and set3iv.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The GL function to call.
The name of the uniform to set.
The new value of the uniform.
The new value of the uniform.
OptionalskipCheck: booleanSkip the value comparison? Default false.
Sets the given uniform value/s based on the name and GL function.
This method is called internally by other methods such as set1f and set3iv.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The GL function to call.
The name of the uniform to set.
The new value of the uniform.
The new value of the uniform.
The new value of the uniform.
OptionalskipCheck: booleanSkip the value comparison? Default false.
Sets the given uniform value/s based on the name and GL function.
This method is called internally by other methods such as set1f and set3iv.
The uniform is only set if the value/s given are different to those previously set.
This method works by first setting this shader as being the current shader within the WebGL Renderer, if it isn't already. It also sets this shader as being the current one within the pipeline it belongs to.
The GL function to call.
The name of the uniform to set.
The new value of the uniform.
The new value of the uniform.
The new value of the uniform.
The new value of the uniform.
OptionalskipCheck: booleanSkip the value comparison? Default false.
Repopulate uniforms on the GPU.
This is called automatically by the pipeline when the context is lost and then recovered. By the time this method is called, the WebGL resources are already recreated, so we just need to re-populate them.
Instances of the WebGLShader class belong to the WebGL Pipeline classes. When the pipeline is created it will create an instance of this class for each one of its shaders, as defined in the pipeline configuration.
This class encapsulates everything needed to manage a shader in a pipeline, including the shader attributes and uniforms, as well as lots of handy methods such as
set2f, for setting uniform values on this shader.Typically, you do not create an instance of this class directly, as it works in unison with the pipeline to which it belongs. You can gain access to this class via a pipeline's
shadersarray, post-creation.