PDA

View Full Version : Passing arrays to VS



Achilles4689
07-07-2011, 03:59 PM
Hey all,

I need to pass an array of uniform mat4 to the VS in order for skin-and-bone animation. In other animation demos I've seen, they just make as many single uniform mat4 as they need. Is there not a way to pass an array of mat4?

Such as
uniform mat4 Bones[10];

The webgl spec says

void uniformMatrix4fv(WebGLUniformLocation location, GLboolean transpose,
Float32Array value);

void uniformMatrix4fv(WebGLUniformLocation location, GLboolean transpose,
float[] value);

I can't seem to get it to work without DOM errors.

gardin
07-16-2011, 11:41 AM
Yes, you can pass a matrix array to a shader program they way you describe.

GLSL requires (I'm not a WebGL-developer, but OpenGL should be the same in this case) that the length of the array can be determined during compiling or linkage. Which means that you can define it as: const int length = 10; uniform mat4 Bones[length]; You cannot however have the length defined as a uniform and try to load it later on..

On to your problem: The array provided in GL is a single array of some type (in this case float), i'm guessing you're trying to provide a multidimensional array perhaps? The array has to be in column major order if transpose is not set to true.

//Johan