new Shader() → {Shader}
Defines an object that represents a glsl shader. This object
provides an interface through which uniforms may be uploaded and shader
definitions may be compiled.
Returns:
- Type
- Shader
Members
-
colorUniformPointer :number
-
This pointer is updated when the shader is compiled and points to the index of the color uniform.
Type:
- number
-
depthUniformPointer :number
-
This pointer is updated when the shader is compiled and points to the index of the depth uniform.
Type:
- number
-
mainTextureUniformPointer :number
-
This pointer is updated when the shader is compiled and points to the index of the main texture uniform.
Type:
- number
-
modelMatrixUniformPointer :number
-
This pointer is updated when the shader is compiled and points to the index of the model matrix uniform.
Type:
- number
-
projectionMatrixUniformPointer :number
-
This pointer is updated when the shader is compiled and points to the index of the projection matrix uniform.
Type:
- number
-
secTextureUniformPointer :number
-
This pointer is updated when the shader is compiled and points to the index of the secondary texture uniform.
Type:
- number
-
uvBufferAttributePointer :number
-
This pointer is updated when the shader is compiled and points to the index of the vertex uv buffer.
Type:
- number
-
vertexBufferAttributePointer :number
-
This pointer is updated when the shader is compiled and points to the index of the vertex buffer.
Type:
- number
-
vertexColorBufferAttributePointer :number
-
This pointer is updated when the shader is compiled and points to the index of the vertex color buffer.
Type:
- number
Methods
-
compile(ctx) → {boolean}
-
Compiles a shader, given a WebGLContext. This is necessary if the context is lost or the shader ids have been changed.
Parameters:
Name Type Description ctxWebGLContext The context to compile with. Returns:
Returns true if successful.- Type
- boolean
-
getShaderProgram() → {GLShaderProgram}
-
Once compiled, this function returns the shader program that should be uploaded to the GPU.
Returns:
- Type
- GLShaderProgram
-
pushCustomUniforms(ctx)
-
This method uploads all custom uniforms to the GPU.
Parameters:
Name Type Description ctxWebGLContext The context to upload through. -
setShaderProgramIds(vertex, fragment)
-
This method sets the ids of the vertex and fragment shaders. Once these are changed, the shader needs to be recompiled.
Parameters:
Name Type Description vertexString The id of the vertex shader. fragmentString The id of the fragment shader. -
setUniformFloat(name, value) → {Function}
-
Sets a float value for a specific uniform.
Parameters:
Name Type Description nameString The name of the uniform to set. valueNumber The value to upload. Returns:
- Type
- Function
-
setUniformMat2(name, value) → {Function}
-
Sets a mat2 value for a specific uniform.
Parameters:
Name Type Description nameString The name of the uniform to set. valueFloat32Array The value to upload. Returns:
- Type
- Function
-
setUniformMat3(name, value) → {Function}
-
Sets a mat3 value for a specific uniform.
Parameters:
Name Type Description nameString The name of the uniform to set. valueFloat32Array The value to upload. Returns:
- Type
- Function
-
setUniformMat4(name, value) → {Function}
-
Sets a mat4 value for a specific uniform.
Parameters:
Name Type Description nameString The name of the uniform to set. valueFloat32Array The value to upload. Returns:
- Type
- Function
-
setUniformVec2(name, value) → {Function}
-
Sets a vec2 value for a specific uniform.
Parameters:
Name Type Description nameString The name of the uniform to set. valueFloat32Array The value to upload. Returns:
- Type
- Function
-
setUniformVec3(name, value) → {Function}
-
Sets a vec3 value for a specific uniform.
Parameters:
Name Type Description nameString The name of the uniform to set. valueFloat32Array The value to upload. Returns:
- Type
- Function
-
setUniformVec4(name, value) → {Function}
-
Sets a vec4 value for a specific uniform.
Parameters:
Name Type Description nameString The name of the uniform to set. valueFloat32Array The value to upload. Returns:
- Type
- Function