nanogl
nanogl copied to clipboard
Safe setter for uniforms
Thanks for releasing NanoGL - I've really enjoyed experimenting with it recently! I love the convenient uniform setters on programs, but occasionally I'll use something like gl_FragColor = vec4(1.0, 0, 0, 1); in my shaders to debug something, but that throws an error with program.u_whatever is not a function.
To get around this, I'll often wrap my programs in their own class with a method:
uniforms(uniforms) {
this.program.use();
for(let name in uniforms) {
let setter = this.program[name];
if(setter === undefined) continue;
setter(uniforms[name]);
}
return this;
}
Useful addition to NanoGL's Program module?