Constructor
new ShaderProgram(webglRenderingContext, vertexSource, fragmentSource)
Parameters:
| Name | Type | Description |
|---|---|---|
webglRenderingContext |
WebGL2RenderingContext | WebGL2 rendering context used to create shaders and the program. |
vertexSource |
string | GLSL source code of the vertex shader. |
fragmentSource |
string | GLSL source code of the fragment shader. |
- Source:
Classes
Members
program
Returns the underlying WebGL program object.
- Source:
Methods
dispose()
Releases the underlying WebGL program. After calling dispose, this instance must not be used.
- Source:
getAttribLocation(name) → {number}
Returns the attribute location for the given attribute name.
This is useful for manual `vertexAttribPointer` setups.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Attribute name in the linked shader program. |
- Source:
Returns:
- Attribute location (0+).
- Type
- number
getUniformLocation(name) → {WebGLUniformLocation}
Returns a cached uniform location.
This can be used for manual `gl.uniform*` calls.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Uniform name in the linked shader program. |
- Source:
Returns:
- Type
- WebGLUniformLocation
setFloat(name, value)
Sets a float uniform.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Name of the uniform variable. |
value |
number | Float value to upload. |
- Source:
setInt(name, value)
Sets an integer uniform.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Name of the uniform variable. |
value |
number | Integer value to upload. |
- Source:
setMatrix4(name, matrix)
Sets a 4x4 matrix uniform.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Name of the uniform variable in the GLSL program. |
matrix |
Float32Array | 4x4 matrix in column-major order to upload to the uniform. |
- Source:
setTexture2D(name, texture, textureUnitIndexopt)
Sets a `sampler2D` uniform and binds a `Texture2D` to the specified texture unit.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
name |
string | Name of the uniform variable. | ||
texture |
Texture2D | `Texture2D` instance to bind. | ||
textureUnitIndex |
number |
<optional> |
0 | Texture unit index (0 => N). |
- Source:
setVector2(name, value)
Sets a vec2 uniform.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Name of the uniform variable. |
value |
Float32Array | Array.<number> | Two numeric components. |
- Source:
setVector3(name, value)
Sets a vec3 uniform.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Name of the uniform variable. |
value |
Float32Array | Array.<number> | Three numeric components. |
- Source:
setVector4(name, value)
Sets a `vec4` uniform.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Name of the uniform variable. |
value |
Float32Array | Array.<number> | Four numeric components. |
- Source:
use()
Makes this program active for subsequent draw calls.
- Source: