Talk:Uniform (GLSL)

From OpenGL.org
(Redirected from Talk:GLSL Uniform)
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.

In general, when you see small errors like this, you should just edit the page and fix it. It'd probably have taken less time for you to correct than it took to write this. That's why anyone can edit Wiki pages, after all. Alfonse (talk) 05:44, 29 August 2012 (PDT)



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

The description given is only true for uniforms that have been given an explicit location. When OpenGL manually assigns a location, it's up to the implementation. And if you're seeing this sorting behavior with explicit assignment, then contact NVIDIA (because they're the only ones thus far who have implemented it) and tell them it's a bug. The best place to do that is in the Drivers sub-forum of the OpenGL forums. Alfonse (talk) 05:44, 29 August 2012 (PDT)