Shader

(DO NOT USE) Class with all of the shader initialization and handling.

Constructor

new Shader(vertexFunc, fragmentFunc, shaderInitFunc)

(DO NOT USE) Internal use by Hummingbird only.

Parameters:
NameTypeDescription
vertexFuncfunction

Optional function that returns the vertex shader source, defaults.

fragmentFuncfunction

Optional function that returns the fragment shader source, defaults.

shaderInitFuncfunction

Optional function to (for example) initialize uniforms in the shader, defaults.

Members

(readonly) attribLocationCache

(DO NOT USE) Internal variable for caching shader attributes, to minimize API calls.

(readonly) fragmentSource

(DO NOT USE) Internal variable to keep track of the fragment source for compilation.

(readonly) id

(DO NOT USE) Internal variable in which the shader is stored.

(readonly) initFunc

(DO NOT USE) Internal variable for initilization of parts of the shaders (like uniforms).

(readonly) uniformLocationCache

(DO NOT USE) Internal variable for caching shader uniforms, to minimize API calls.

(readonly) vertexSource

(DO NOT USE) Internal variable to keep track of the vertex source for compilation.

Methods

bind()

(DO NOT USE) Method to bind this shader program (set it as active).

compileShader(type, source) → {WebGLShader}

(DO NOT USE) Method for compiling shaders.

Parameters:
NameTypeDescription
typenumber

The type of shader, see MDN.

sourcestring

Shader source to use.

Returns:
Type: 
WebGLShader

createProgram(vertexShaderSource, fragmentShaderSource) → {WebGLProgram}

(DO NOT USE) Actual method for creating the shader program with compiled shaders.

Parameters:
NameTypeDescription
vertexShaderSourcestring

Argument for vertex shader to use.

fragmentShaderSourcestring

Argument for fragment shader to use.

Returns:
Type: 
WebGLProgram

delete()

(DO NOT USE) Method to unbind and then delete this shader program, is called from HB.Renderer#delete.

getAttribLocation(name) → {number}

(DO NOT USE) Method for getting the location of attributes inside shaders.

Parameters:
NameTypeDescription
namestring

Name of the attribute.

Returns:

ID of attribute inside shader.

Type: 
number

getUniformLocation(name) → {WebGLUniformLocation}

(DO NOT USE) Method for getting the location of uniforms inside shaders.

Parameters:
NameTypeDescription
namestring

Name of the uniform.

Returns:

Location of uniform inside shader.

Type: 
WebGLUniformLocation

setUniform(type, name, values)

(DO NOT USE) Method for setting a uniform inside shaders.

Parameters:
NameTypeDescription
typestring

Type of value, "f" for floats and "i" for integers, see MDN.

namestring

Name of the uniform.

valuesArray

Array with values, length 1-4, see MDN.

setUniformArray(type, name, array, elementAmount)

(DO NOT USE) Method for setting array uniforms inside shaders.

Parameters:
NameTypeDefaultDescription
typestring

Type of value, "f" for floats and "i" for integers, see MDN.

namestring

Name of the uniform.

arrayArray

Array with values, see MDN.

elementAmountnumber1

Amount of elements in each element of the array, i.e. 2 for vec2, see docs.gl and MDN.

setUniformMatrix(type, name, matrix)

(DO NOT USE) Method for setting matrix uniforms inside shaders.

Parameters:
NameTypeDescription
typestring

Type of value, "f" for floats only, see MDN.

namestring

Name of the uniform.

matrixglMatrix.mat4

Matrix.

unbind()

(DO NOT USE) Method to bind an empty shader program (set this one as inactive).

(static) init()

(DO NOT USE) Internal method for creating the HB.shader instance.