You have seen similar code before, but we used glMatrix
to store the uniform variables on the JavaScript side.
var catData = {
// ... geometry data ...
lineColor: [0.2, 0.2, 0.2],
fillColor: [1.0, 0.9, 0.7]
};
// ...
function createShape(gl, data) {
var shape = {};
// ... store geometry data in shape ...
shape.lineColor = vec3.clone(data.lineColor);
shape.fillColor = vec3.clone(data.fillColor);
return shape;
}
// ...
gl.uniform3fv(gl.getUniformLocation(program, "color"), shape.fillColor);
// ... draw the triangles ...
gl.uniform3fv(gl.getUniformLocation(program, "color"), shape.lineColor);
// ... draw the lines ...