ShaderProgram
Methods
attachShader
Attach a compiled shader to the program.
| Argument | Type | Required | Description |
|---|---|---|---|
shader | Yes | The shader to attach. |
bind
Make this program the current one, linking it first if needed.
Returns
| Type | Description |
|---|---|
| boolean | True when the program is bound. |
cleanup
Release the program and detach and delete its shaders.
compileShader
Compile the vertex and fragment shaders, attach them and link the program.
Returns
| Type | Description |
|---|---|
| number | 1 on success, 0 on failure. |
detachShader
Detach a shader from the program.
| Argument | Type | Required | Description |
|---|---|---|---|
shader | Yes | The shader to detach. |
findUniform
Get the cached location of a uniform, or -1 when it is not used.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. |
getBound
Whether the program is currently bound.
getCompiled
Whether the program has been compiled.
getError
Get the last error message.
getFragmentShader
Get the fragment shader.
getGeometryShader
Get the geometry shader. WebGL has no geometry stage; it is kept for source substitution only.
getHandle
Get the underlying GL program object, or 0 when it has not been created.
getLastCameraMTime
Get the MTime of the camera the camera uniforms were last set from.
getLinked
Whether the program has been linked.
getMd5Hash
Get the hash of the shader sources this program was built from.
getVertexShader
Get the vertex shader.
isAttributeUsed
Whether the given attribute exists in the linked program.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The attribute name. |
isBound
Whether this program is the current one.
isUniformUsed
Whether the given uniform exists in the linked program.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. |
link
Link the program.
Returns
| Type | Description |
|---|---|
| boolean | True when the program is linked. |
release
Unbind this program.
replace
Whether the substitution changed the source.
result
The resulting source.
setBound
Set the bound flag.
| Argument | Type | Required | Description |
|---|---|---|---|
bound | Yes | The bound flag. |
setCompiled
Set the compiled flag.
| Argument | Type | Required | Description |
|---|---|---|---|
compiled | Yes | The compiled flag. |
setContext
Set the WebGL context of the program and of its shaders.
| Argument | Type | Required | Description |
|---|---|---|---|
context | Yes | The WebGL context. |
setError
Set the error message.
| Argument | Type | Required | Description |
|---|---|---|---|
error | Yes | The error message. |
setFragmentShader
Set the fragment shader.
| Argument | Type | Required | Description |
|---|---|---|---|
fragmentShader | Yes | The fragment shader. |
setGeometryShader
Set the geometry shader.
| Argument | Type | Required | Description |
|---|---|---|---|
geometryShader | Yes | The geometry shader. |
setHandle
Set the underlying GL program object.
| Argument | Type | Required | Description |
|---|---|---|---|
handle | Yes | The GL program object. |
setLastCameraMTime
Set the MTime of the camera the camera uniforms were last set from.
| Argument | Type | Required | Description |
|---|---|---|---|
mtime | Yes | The camera MTime. |
setLinked
Set the linked flag.
| Argument | Type | Required | Description |
|---|---|---|---|
linked | Yes | The linked flag. |
setMd5Hash
Set the hash of the shader sources this program was built from.
| Argument | Type | Required | Description |
|---|---|---|---|
md5Hash | Yes | The hash. |
setUniform2f
Set a vec2 uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v1 | Yes | The first component. | |
v2 | Yes | The second component. |
setUniform2fv
Set a vec2 array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setUniform2i
Set an ivec2 uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v1 | Yes | The first component. | |
v2 | Yes | The second component. |
setUniform2iv
Set an ivec2 array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setUniform3f
Set a vec3 uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
a1 | Yes | The first component. | |
a2 | Yes | The second component. | |
a3 | Yes | The third component. |
setUniform3fArray
Set a vec3 uniform from an array of exactly three values.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
a | Yes | The three components. |
setUniform3fv
Set a vec3 array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setUniform3i
Set an ivec3 uniform, either as three arguments or as a single array of three values.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
args | Yes | The three components. |
setUniform3iv
Set an ivec3 array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setUniform4f
Set a vec4 uniform, either as four arguments or as a single array of four values.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
args | Yes | The four components. |
setUniform4fv
Set a vec4 array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setUniform4i
Set an ivec4 uniform, either as four arguments or as a single array of four values.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
args | Yes | The four components. |
setUniform4iv
Set an ivec4 array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setUniformMatrix
Set a mat4 uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The 16 matrix values. |
setUniformMatrix3x3
Set a mat3 uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The 9 matrix values. |
setUniformf
Set a float uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The value. |
setUniformfv
Set a float array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setUniformi
Set an int uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The value. |
setUniformiv
Set an int array uniform.
| Argument | Type | Required | Description |
|---|---|---|---|
name | Yes | The uniform name. | |
v | Yes | The values. |
setVertexShader
Set the vertex shader.
| Argument | Type | Required | Description |
|---|---|---|---|
vertexShader | Yes | The vertex shader. |
substitute
Perform string substitutions on shader source, used to build up shader strings from templates.
| Argument | Type | Required | Description |
|---|---|---|---|
source | Yes | The source to substitute into. | |
search | Yes | The string or pattern to replace. | |
replace | Yes | The replacement, joined with newlines when an array. | |
all | Boolean | No | (default: true) When false, only the first occurrence is replaced. |