Constructor
new Shader(vertexFunc, fragmentFunc, shaderInitFunc)
(DO NOT USE) Internal use by Hummingbird only.
| Name | Type | Description |
|---|---|---|
vertexFunc | function | Optional function that returns the vertex shader source, defaults. |
fragmentFunc | function | Optional function that returns the fragment shader source, defaults. |
shaderInitFunc | function | 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.
| Name | Type | Description |
|---|---|---|
type | number | The type of shader, see MDN. |
source | string | Shader source to use. |
- Type:
- WebGLShader
createProgram(vertexShaderSource, fragmentShaderSource) → {WebGLProgram}
(DO NOT USE) Actual method for creating the shader program with compiled shaders.
| Name | Type | Description |
|---|---|---|
vertexShaderSource | string | Argument for vertex shader to use. |
fragmentShaderSource | string | Argument for fragment shader to use. |
- 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.
| Name | Type | Description |
|---|---|---|
name | string | Name of the attribute. |
ID of attribute inside shader.
- Type:
- number
getUniformLocation(name) → {WebGLUniformLocation}
(DO NOT USE) Method for getting the location of uniforms inside shaders.
| Name | Type | Description |
|---|---|---|
name | string | Name of the uniform. |
Location of uniform inside shader.
- Type:
- WebGLUniformLocation
setUniform(type, name, values)
(DO NOT USE) Method for setting a uniform inside shaders.
| Name | Type | Description |
|---|---|---|
type | string | Type of value, "f" for floats and "i" for integers, see MDN. |
name | string | Name of the uniform. |
values | Array | Array with values, length 1-4, see MDN. |
setUniformArray(type, name, array, elementAmount)
(DO NOT USE) Method for setting array uniforms inside shaders.
| Name | Type | Default | Description |
|---|---|---|---|
type | string | Type of value, "f" for floats and "i" for integers, see MDN. | |
name | string | Name of the uniform. | |
array | Array | Array with values, see MDN. | |
elementAmount | number | 1 | 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.
| Name | Type | Description |
|---|---|---|
type | string | Type of value, "f" for floats only, see MDN. |
name | string | Name of the uniform. |
matrix | glMatrix. | 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.