Talk:Uniform (GLSL)

From OpenGL Wiki
Revision as of 15:24, 28 August 2012 by MarkTheFox (talk | contribs)
Jump to: navigation, search

Regarding the explanation of the layout on uniform variables created from a structure it seems there is a small mistake on the layout value for the second example, shouldn't it be 7 instead of 2 for manyStructs[0].thirdField ? (0*3 [array] + 2 [struct offset] + 5 [base location]) Here is the corresponding part of the page :

struct MyStruct
{
  vec2 firstField;
  vec4 secondField;
  mat2 thirdField;
};

layout(location = 5) uniform MyStruct manyStructs[3];

"manyStructs[0].firstField" will have the location 5. "manyStructs[0].thirdField will have the location 2. "manyStructs[2].secondField" will have the location (2*3 [array] + 1 [struct offset] + 5 [base location]), or 12. And so forth.



Moreover, I've tried to identify the uniform ID from a layout I've created and it seems the members are sorted alphabetically while creating the ID for binding ... what about this ? Should we sort the data in our struct in order to use the previous formula : index*(number of members in struct) + offset + baseLocation