the glVertexAttrib family of functions allows to add generic attributes to each vertex. You can set a index that the data will be associated with. However, you can't choose the index arbitrarily, since I discovered that using indices lower than 4 will break standard (Normal/TexCoord) attributes, plus 0 is the vertex position. How can I find out, which will be the first real free index to use for custom attributes?
3 Answers
I found a website which lists the predefined indices on nvidia hardware:
http://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php
Unfortunately there are certain limitations when using this on NVidia Hardware. According to NVidia: "GLSL attempts to eliminate aliasing of vertex attributes but this is integral to NVIDIA’s hardware approach and necessary for maintaining compatibility with existing OpenGL applications that NVIDIA customers rely on. NVIDIA’s GLSL implementation therefore does not allow built-in vertex attributes to collide with a generic vertex attributes that is assigned to a particular vertex attribute index with glBindAttribLocation. For example, you should not use gl_Normal (a built-in vertex attribute) and also use glBindAttribLocation to bind a generic vertex attribute named "whatever" to vertex attribute index 2 because gl_Normal aliases to index 2."
In other words, NVidia hardware indices are reserved for built-in attributes:
- gl_Vertex 0
- gl_Normal 2
- gl_Color 3
- gl_SecondaryColor 4
- gl_FogCoord 5
- gl_MultiTexCoord0 8
- gl_MultiTexCoord1 9
- gl_MultiTexCoord2 10
- gl_MultiTexCoord3 11
- gl_MultiTexCoord4 12
- gl_MultiTexCoord5 13
- gl_MultiTexCoord6 14
- gl_MultiTexCoord7 15

- 4,736
- 2
- 21
- 24
-
For further reference, note that these are the same indices indicated in the ARB_vertex_program specification. The missing indices in your list are (1:) blend weights 0-3, (6:) point size, and (7:) blend indices. 6 is used for point sprites and 1 and 7 are used for hardware skinning. – rdb May 24 '15 at 12:41
You shouldn't be choosing your own indices. GL can provide free ones for you through the glGetAttribLocation function by using the attribute name in code (if you do this after linking the program).
I never encountered this problem... but unfortunately I don't have my own shader wrapper code to hand (at work atm) to be able to explain why.

- 3,043
- 1
- 21
- 28
-
1This is not true, the OpenGL specification allows to arbitrarily choose indexes. There is however an issue with NVidia, see heeen's answer. – Julien Guertault Feb 28 '13 at 15:04
-
By the way, see this answer for a very good reason to choose your own indices: http://stackoverflow.com/a/4638906/253883 – Julien Guertault Mar 01 '13 at 08:50
You can actually use vertex attribute arrays exclusively and thus skip glVertexPointer()
and co entirely. This will avoid any double ups and is also nicely unified. You should still use glGetAttribLocation()
though, because AFAIK you can't know ahead of time what index each attribute will be mapped to at runtime.
As always, the extension spec has all the gory details.

- 957
- 16
- 31