Consider something like the following for webgl (untested but should work):
const lookup = new Map();
const isEqual3fv = (v1, v2) => {
return v1[0] === v2[0] && v1[1] === v2[1] && v1[2] === v2[2];
}
const setUniform3fv = (location, value) => {
if(!lookup.has(location) || !isEqual3fv(lookup.get(location), value)) {
gl.uniform3fv(location, value);
lookup.set(location, value);
}
}
Would this be an optimization in most cases? Is caching the values and comparing for equality before setting the uniform generally a worthwhile optimization - or is the difference pretty negligible?
glUniform
silently abort on -1. ;-) – Christian Rau Mar 12 '18 at 15:07