function draw() {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.uniformMatrix4fv(u_view, false, view);
gl.uniformMatrix4fv(u_projection, false, projection);
gl.uniform1f(u_ambient, controls.ambient == "on");
gl.uniform1f(u_diffuse, controls.diffuse == "on");
gl.uniform1f(u_specular, controls.specular == "on");
gl.uniform3fv(u_specular_color, hexToRGB(controls.specular_color));
gl.uniform1f(u_specular_exp, controls.specular_exp);
gl.uniform3fv(u_light_color, hexToRGB(controls.light_color));
for (const group in geometry.indices) {
gl.uniform3fv(u_color, geometry.materials[group].albedo);
const [start, end] = geometry.indices[group];
gl.drawElements(
gl.TRIANGLES,
end - start,
gl.UNSIGNED_SHORT,
INDEX_SIZE * start
);
}
}