Chrome uniform3fv

I’ve just noticed that the Windows dev channel for Chrome now supports WebGL, which is great news!

Less good news is that its support for uniform3fv differs from that in Firefox, and it’s not obvious which is correct. It appears to only accept proper WebGL buffer objects, not JavaScript lists (which is fair enough) but it also takes an extra size parameter.

In more detail: in Firefox I was doing something like:

gl.uniform3fv(gl.getUniformLocation(shaderProgram, "uAmbientColor"), [0.5, 0.5, 0.5]);

Now, changing it to

gl.uniform3fv(gl.getUniformLocation(shaderProgram, "uAmbientColor"), new WebGLFloatArray([0.5, 0.5, 0.5]));

…is probably an improvement anyway, so I’ll update my code accordingly. However, the above still won’t work on Chrome; to get it to work I need to do this:

gl.uniform3fv(gl.getUniformLocation(shaderProgram, "uAmbientColor"), new WebGLFloatArray([0.5, 0.5, 0.5]), 3);

…the last parameter being a size (as per uniform3fv chrome - Google Search). That last line works in Chrome, but unfortunately doesn’t work in Firefox.

Does anyone know which one is correct according to the latest version of the spec?

Cheers,

Giles

Thinking about it, the function’s name already includes the number of items it expects in the array passed to it: uniform3fv means “set a uniform from this array of 3 floats”. So I suspect Chrome’s wrong. It’d be nice to know for sure, though…

As you already wrote, there is no size parameter. At least the parameter it is redundant, especially because the array does know its length. I’m sure that’s a bug in Chrome.

However, you might want to use

gl.uniform3f(index, x, y, z)

instead. That should be faster, in cases where you don’t an array yet.

Good point that the non-v version is going to be faster. It’s not quite so simple in the actual code, but only one case will be made significantly messier by changing to uniform3f – so that’s what I’ll do.