class |
---|
ProgramWrapper |
ProgramLoader |
This class wraps a WebGLProgram and stores its attributes and uniforms
method | description |
---|---|
constructor(glContext, name) |
Create a webgl program from the given webgl context and sets a name |
get glContext() |
Get the webgl context associated with the program |
get glProgram() |
Get the WebGLProgram instance referenced by this object |
get name() |
Get the name of this program |
use() |
Use this program for rendering |
getAttributeLocation(name) |
Return the location for the requested attribute name |
getUniformLocation(name) |
Return the location for the requested uniform name |
getUniformBlockIndex(name) |
Return the index for the requested uniform block name |
uniformBlockBinding(name, index) |
Call gl.uniformBlockBinding to bind uniform block to given index |
queryAttributes() |
Query the GPU for all the attributes of the current program and stores the data |
queryUniforms() |
Query the GPU for all the uniforms of the current program and stores the data |
queryUniformBlocks() |
Query the GPU for all the uniform blocks of the current program and stores the data |
This class loads the shaders and creates the programs
method | description |
---|---|
constructor(app) | Create an instance that references the given app |
loadShader(url, type, name=url) | Create and compile a shader loading the source code from url Fails if the shader name is already taken |
addShaderSource(src, type, name) | Create and compile a shader with the given source code Fails if the shader name is already taken |
addProgram(name, shaderNames) | Create a program in the app object, attach the shaders with the given names, link the program and detach the sahders. Fails if the specified name is already taken in the app object or if a shader needed is not present |
async loadFromJSON(url) | Load a json from url and uses it to load shaders and programs. calling loadFromObject method |
async loadFromObject(obj) |
Load shaders and programs from an object with the following structure:
{
path : "path/to/shaders",
shaders : [ { type : "VERTEX_SHADER", file : "vertex.glsl" }, ... ],
programs : [ { name : "myProg", shaders : ["vertex.glsl", "fragment.glsl"] }, ... ]
} Fails if a shader can't be loaded |
async deleteShaders() | Call deleteShader for every shader previously loaded |
async checkShaders() | Check all shaders for compile errors Log the shader info log in the console. Return the number of compile errors. Useful only for debug |
async checkPrograms() | Check all programs of this loader for link errors Log the program info log in the console. Return the number of link errors. Useful only for debug |
async validatePrograms() | Validate all programs of this loader and check for errors Log the program info log in the console. Return the number of errors. Useful only for debug |