new Program(gl, displayName, vertexShaderSource, fragmentShaderSource, attributeNames, uniformNames)
WebGL program object. Designed to support async compilation/linking. When creating many programs first call vr.Program#beginLinking on all of them followed by a vr.Program#endLinking on all of them.
Parameters:
Name | Type | Description |
---|---|---|
gl |
WebGLRenderingContext | WebGL context. |
displayName |
string | Debug name. |
vertexShaderSource |
string | Vertex shader source. |
fragmentShaderSource |
string | Fragment shader source. |
attributeNames |
!Array.<string> | A list of attribute names. |
uniformNames |
!Array.<string> | A list of uniform names. |
- Source:
- vr.js, line 1325
Examples
var program = new vr.Program(gl, 'MyShader',
'vertex shader source', 'fragment shader source',
['attribute1', 'attribute2'],
['uniform1', 'uniform2']);
program.beginLinking();
program.endLinking();
function render() {
program.use();
gl.enableVertexAttribArray(program.attributes['attribute1']);
gl.enableVertexAttribArray(program.attributes['attribute2']);
gl.uniform1f(program.uniforms['uniform1'], 1);
gl.uniform1f(program.uniforms['uniform2'], 2);
// Draw/etc.
};
Asynchronous compilation/linking.
// Create all programs. This is cheap.
var programs = [new vr.Program(...), new vr.Program(...), ...];
// Begin compilation/linking.
for (var n = 0; n < programs.length; n++) {
programs[n].beginLinking();
}
// Perform other loading/uploads/etc.
// TODO: your loading code.
// End compilation/linking and generate any errors.
for (var n = 0; n < programs.length; n++) {
try {
programs[n].endLinking();
} catch (e) {
// Handle any compilation/link errors here.
}
}
Members
-
<readonly> attributes :!Object.<number>
-
Attribute names to locations.
Type:
- !Object.<number>
- Source:
- vr.js, line 1340
-
<readonly> uniforms :!Object.<!WebGLUniformLocation>
-
Uniform names to locations.
Type:
- !Object.<!WebGLUniformLocation>
- Source:
- vr.js, line 1350
Methods
-
beginLinking()
-
Compiles the shaders and begins linking. This must be followed by a call to vr.Program#endLinking. Shader/program errors will not be queried until then.
- Source:
- vr.js, line 1390
-
dispose()
-
Disposes the object.
- Source:
- vr.js, line 1379
-
endLinking()
-
Links the program and throws on any compile/link errors.
- Source:
- vr.js, line 1403
-
use()
-
Uses the program on the current GL context.
- Source:
- vr.js, line 1452