Exhibit #4: Getting Info about Uniforms
Uniforms
What We Did
- You can get the number of uniforms that are used in a program with
gl.getProgramParameter(<program>, gl.ACTIVE_UNIFORMS)
.
- You can then get information about the uniform with the given index with
gl.getActiveUniform(<program>, <uniform-index>);
.
- Like the vertex attribute cause, the index goes from 0 to
gl.getProgramParameter(<program>, gl.ACTIVE_UNIFORMS)-1
.
- You get an object that tells you the name, size, and the type of the uniform.
The size is not 1 if it is a uniform array.
- For a uniform array, you get the name of the first entry.
- You can get the location of a uniform with
gl.getUniformLocation(<program>, <uniform-name>)
- Unlike the vertex attribute case, this does not simply return an integer because uniforms can be arrays.
- Instead, you get an object which represents the location.
- This object does not change during the lifetime of the program, so you can get all locations once and use them repeatedly afterwards.
- Hint: Use these functions to build better abstractions around uniforms.