Class: Shader

Shader

Shader

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.
Author:
  • thegoldenmule
Source:
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
Source:

depthUniformPointer :number

This pointer is updated when the shader is compiled and points to the index of the depth uniform.
Type:
  • number
Source:

mainTextureUniformPointer :number

This pointer is updated when the shader is compiled and points to the index of the main texture uniform.
Type:
  • number
Source:

modelMatrixUniformPointer :number

This pointer is updated when the shader is compiled and points to the index of the model matrix uniform.
Type:
  • number
Source:

projectionMatrixUniformPointer :number

This pointer is updated when the shader is compiled and points to the index of the projection matrix uniform.
Type:
  • number
Source:

secTextureUniformPointer :number

This pointer is updated when the shader is compiled and points to the index of the secondary texture uniform.
Type:
  • number
Source:

uvBufferAttributePointer :number

This pointer is updated when the shader is compiled and points to the index of the vertex uv buffer.
Type:
  • number
Source:

vertexBufferAttributePointer :number

This pointer is updated when the shader is compiled and points to the index of the vertex buffer.
Type:
  • number
Source:

vertexColorBufferAttributePointer :number

This pointer is updated when the shader is compiled and points to the index of the vertex color buffer.
Type:
  • number
Source:

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
ctx WebGLContext The context to compile with.
Source:
Returns:
Returns true if successful.
Type
boolean

getShaderProgram() → {GLShaderProgram}

Once compiled, this function returns the shader program that should be uploaded to the GPU.
Source:
Returns:
Type
GLShaderProgram

pushCustomUniforms(ctx)

This method uploads all custom uniforms to the GPU.
Parameters:
Name Type Description
ctx WebGLContext The context to upload through.
Source:

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
vertex String The id of the vertex shader.
fragment String The id of the fragment shader.
Source:

setUniformFloat(name, value) → {Function}

Sets a float value for a specific uniform.
Parameters:
Name Type Description
name String The name of the uniform to set.
value Number The value to upload.
Source:
Returns:
Type
Function

setUniformMat2(name, value) → {Function}

Sets a mat2 value for a specific uniform.
Parameters:
Name Type Description
name String The name of the uniform to set.
value Float32Array The value to upload.
Source:
Returns:
Type
Function

setUniformMat3(name, value) → {Function}

Sets a mat3 value for a specific uniform.
Parameters:
Name Type Description
name String The name of the uniform to set.
value Float32Array The value to upload.
Source:
Returns:
Type
Function

setUniformMat4(name, value) → {Function}

Sets a mat4 value for a specific uniform.
Parameters:
Name Type Description
name String The name of the uniform to set.
value Float32Array The value to upload.
Source:
Returns:
Type
Function

setUniformVec2(name, value) → {Function}

Sets a vec2 value for a specific uniform.
Parameters:
Name Type Description
name String The name of the uniform to set.
value Float32Array The value to upload.
Source:
Returns:
Type
Function

setUniformVec3(name, value) → {Function}

Sets a vec3 value for a specific uniform.
Parameters:
Name Type Description
name String The name of the uniform to set.
value Float32Array The value to upload.
Source:
Returns:
Type
Function

setUniformVec4(name, value) → {Function}

Sets a vec4 value for a specific uniform.
Parameters:
Name Type Description
name String The name of the uniform to set.
value Float32Array The value to upload.
Source:
Returns:
Type
Function