adding mat4 arrays to GLSL shader

I am trying to allow my GLSL shader to accept a mat4 array. The problem I am having is in glShaderContext_src.cxx there is a function call:

gsg->_glGetActiveUniform(_glsl_program, i, param_maxlength, NULL, &param_size, &param_type, param_name);

This is supposed to set the param_size and param_type. It gets the param_size right, which is the length of the array, but the param_type is 0 which is wrong. It does work for other array types, such as an array of vec4. As far as I could tell this call just gets passed to the platform-specific GL code and does not have much to do with Panda.
Is there something I missed here?

Odd. Have you tried updating your video drivers? Perhaps there’s a bug there.

What is really odd is now that I’ve updated to the latest drivers, the param_name of any array is getting [0] appended onto the end. So whereas before a param was called diffuse it is now called diffuse[0]. I confirmed on a second machine that the drivers were the cause.
I’ll investigate more but this is quite unusual.

Well I can add [0] to the end of my setShaderInput name calls and it works as before. Still no param_type for mat4 array though.

This sounds important:
Uniform variables that are declared as structures or arrays of structures will not be returned directly by this function. Instead, each of these uniform variables will be reduced to its fundamental components containing the “.” and “[]” operators such that each of the names is valid as an argument to glGetUniformLocation. Each of these reduced uniform variables is counted as one active uniform variable and is assigned an index. A valid name cannot be a structure, an array of structures, or a subcomponent of a vector or matrix.

In the end I decided to just pack all my values into one long vec4 array rather than sort through GL code. :slight_smile:

GLSL mat4 arrays are now supported in CVS. I suppose this is a bit late now, but better late than never, I suppose.

Some GPUs do indeed add [0], some don’t. Both are valid ways to refer to the first element of an array (or a range of elements if param_size > 1), so Panda checks for the presence of [0] and removes it. (It doesn’t bother to parse it for cases of [1] or other values, since that doesn’t seem to happen in my tests.)