1

Is it OK to make (per-draw-call) uniform and (per-vertex) attribute to share same channel (location = X) explicitly?

Vertex Shader :-

layout(location = 2) in vec3 perVertex_pos;      
layout(location = 2) uniform vec3 perInstance_color;
//^ same "location = 2" ... valid?

I am trying to keep location to a low figure as much as possible to fix an error C5102: input semantic attribute "ATTR" has too big of a numeric index.

References :
https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)
https://www.khronos.org/opengl/wiki/Uniform_(GLSL)/Explicit_Uniform_Location
They explain each type (uniform & attribute) individually, but do not tell whether I can share the index.

Edit: A similar-but-perpendicular question : Are OpenGL indices and locations the same thing for uniforms and vertex attributes?

javaLover
  • 6,347
  • 2
  • 22
  • 67
  • 1
    [OpenGL 4.6 API Core Profile Specification - 7.3.1 Program Interfaces, page 108](https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.core.pdf#page=124&zoom=100,0,173): *"Each entry in the active resource list **for an interface** is assigned **a unique unsigned integer index** in the range zero to N − 1, where N is the number of entries in the active resource list.*" - Uniforms and attributes are different types of interfaces. – Rabbid76 Aug 25 '19 at 10:47

1 Answers1

4

Yes, they can share indices. Attribute locations and uniform locations are unrelated.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • May you provide some reference to make me rest in peace, please? – javaLover Aug 25 '19 at 09:18
  • @javaLover I don't have a reference at hand, but you might be able to verify it by not specifying `location`, and checking the automatically assigned locations with `glGetAttribLocation` and `glGetUniformLocation`. – HolyBlackCat Aug 25 '19 at 09:19