Constructor
new Program()
OpenGL shader program class
Example
// 1- Create a new shader program termed 'cel-shading' from the current graphics context
var shaderProgram = new Program(renderer.getContext(),'cel-shading');
// 2- Load vertex source file from DOM and compile
shaderProgram.loadDOM("vertex" ,"cel-shading-vs");
// 3- Load fragment source file from DOM and compile
shaderProgram.loadDOM("fragment","cel-shading-fs");
// 4- Link the program
shaderProgram.link();
// 5 Get uniformLocation
shaderProgram.setUniformLocation("uPMatrix");
shaderProgram.setUniformLocation("uVMatrix");
shaderProgram.setUniformLocation("uMMatrix");
Methods
_compile()
Private method for compiling shader
_createAttributesAndUniforms()
Private method to automatically detect in the shader source files the attribute(s) and uniform(s). TODO - Must be improved to remove commented lines containing attributes and/or uniforms
getID()
Get OpenGL ID of this shader program
load(type:, name:)
Load vertex or fragment source files for compilation and link
Parameters:
Name | Type | Description |
---|---|---|
type: |
string | Source file types - 'vertex' or 'fragment' |
name: |
string | Source filename |
loadDOM(type:, name:)
Load vertex or fragment source files for compilation and link from the DOM. From Learning WEBGL.
Parameters:
Name | Type | Description |
---|---|---|
type: |
string | Source file types - 'vertex' or 'fragment' |
name: |
string | ID of the html div |
loadHTTP(type:, name:)
Load vertex or fragment source files for compilation and link via http
Parameters:
Name | Type | Description |
---|---|---|
type: |
string | Source file types - 'vertex' or 'fragment' |
name: |
string | Source filename |
setUniformLocation()
Get uniform location and set up the correspondig array. The method's name is not really appropriate (set/getUniform[...])
updateUniforms()
Update all the uniforms. This function is called by the ShapeGL.render().
use()
Activate this shader program for rendering