Define tightly packed interface block array

Greetings,

I want to define an uniform interface block that consists of a 100 element array of floats with std140. Problem: It seems that every element in the array is padded to the size of a vec4 (which for me is 16 bytes). Is there a way to define a float uniform array so that every element only uses 4 bytes?

Regards.

The only thing you can do is create a vec4 array and use math to access it as if it were a flat array. Basically, you do this arr[index / 4][index % 4] to access the element from arr at the index index.

Accessing a matrix via a single index is not possible, is it?

If you’re talking about one of GLSL’s mat* types, the no, you have to access each column/row individually. But that’s just a matter of simple math.

2 Likes

Aside from Alfonse’ solution, another option is to use a SSBO with the std430 layout or a buffer texture instead of a UBO.

1 Like