A glitch?

I am currently using GLSL 4

When a declare a uniform array:

uniform vec3 scale[9];

its fine.

When I do

uniform vec3 hey[10]; or hey[25]; or hey[30];


But when I do hey[128];

its FINE…

These are my variable initializations

layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 color;
layout(location = 2) in mat4 transformation;

uniform vec3 scale[32];

out vec3 out_color;

queried my GL_MAX_VERTEX_UNIFORM_VECTOR and its near 1024 or something…
I am guessing it has something to do with it location relative to the varying data in the shader?

Uniforms and attributes are entirely separate.

Are you using the correct strides and sizes when uploading the data? Unless you use the std140 layout, array strides, sizes and alignment are implementation-dependent.

WOW. That worked. Can you explain layout(std140) a little bit more?

std140 is a defined layout. The precise details are given in section of the OpenGL 4.5 specification. The idea is that you can deduce the layout from the definition of the block, so you can e.g. define a C structure and use that to access the data for a uniform block, with structure fields corresponding to uniform variables.

The main disadvantage is that it uses more memory than the other layouts because unused variables cannot be discarded and alignments are based upon the worst case, resulting in more padding (e.g. the alignment of an array is rounded up to a multiple of that for a vec4, as is that for a vec3).

The other layouts (apart from std430) are implementation-dependent, meaning that they’re whatever is convenient for the hardware. Padding will only be added if the hardware requires it. Variables may be re-ordered to minimise the size of the block or to produce more efficient code.

The “shared” layout at least guarantees that identical uniform block definitions will have the same layout, so that you can use the same UBO with multiple shaders. The “packed” layout doesn’t even guarantee that; variables which aren’t used by a particular shader may be omitted, possibly having a knock-on effect upon the overall layout.

With either layout, you have to explicitly query the offset for each variable. For arrays and matrices, you need to query the offset for the array itself as well as the stride (the offset between consecutive elements). With the “packed” layout, you have to perform the queries separately for each each shader, even if the uniform block definitions are identical.

The std430 layout is similar to std140 but with looser alignment restrictions, but it can only be used for shader storage blocks, not for uniform blocks.