Should the quantifier layout (location) be different between uniform / input / output?

Now I am setting up the layout quantifier (location) for my GLSL shaders. And this question strikes me as to whether these quantifier IDs need each other.

Should there be:

layout (location = 0) uniform vec3 v1;
layout (location = 1) in vec3 v2;
layout (location = 2) uniform vec3 v3;
layout (location = 3) in vec3 v4;

      

Or it could be (since location could be specified as uniform or entrances):

layout (location = 0) uniform vec3 v1;
layout (location = 0) in vec3 v2;
layout (location = 1) uniform vec3 v3;
layout (location = 1) in vec3 v4;

      

Thank.

+3


source to share


1 answer


Whereas for vertex shader attributes, the layout location is the index of the attribute, the layout location for homogeneous variables is the uniform location. These are two different things.

If you haven't set explicit layout locations and read them after linking the shader program, you can see that they can be in the same range. This can be done with glGetAttribLocation and glGetUniformLocation

Both of your options are correct and possible. Attribute locations must be unique, and uniform locations must be unique. But they don't have to be unambiguous, other than the type of location index.

For more information on the layout classifier, I recommend the OGL and GLSL documentation of the Khronos group: Layout Qualifier (GLSL)



Accordingly, see OpenGL API Core Profile 4.6 - 7.3.1 Programming Interfaces .

Each entry in the list of active resources for the interface is assigned a unique unsigned integer index in the range from zero to N - 1, where N is the number of entries in the list of active resources.

While the interface type for homogeneous variables is UNIFORM

, the type for attributes is PROGRAM_INPUT

. The location of the various program resources can be obtained using the instructions glGetProgramResourceLocation

for the type and name of the program interface.

+3


source







All Articles