xeolabs / scenejs

An extensible WebGL-based 3D engine. This is an archived project.
https://xeolabs.github.io/scenejs/
Other
649 stars 165 forks source link

Prevent uniform cache from referencing outside array #475

Closed tsherif closed 8 years ago

tsherif commented 8 years ago

This update prevents the uniform cache from storing a reference to argument arrays directly. The problem can be seen in the following example:

var array = [1, 2, 3];
uniform.setValue(array);   // Uniform caches a direct reference to array!
array[0] = 5;
uniform.setValue(array);   // Uniform not updated because the new value is already in the cache!

The update creates a separate array to cache the value, and manually copies values over to prevent this.

I also changed the reference to SCENEJS_uLightAttenuation in the FS to use the more common x, y, z accessors, rather than array notation. I think it's more clear, but let me know if you think otherwise.

tsherif commented 8 years ago

@xeolabs, this is what prevented the attenuation in point and spot lights from working properly.