First of all, I do not consider it a general recommendation to use explicit binding through glBindAttribLocation instead of glGetAttribLocation . However, these are the main reasons why I stopped using glGetAttribLocation :
First of all, this can lead to unnecessary overhead. Everything seems nice and enjoyable that you can use readable names instead of numbers. “What the heck is attribute 7 'vs' oh right, attribute texture_coordinate': I will first explain what possible overhead might be, and then why this last part doesn't even make sense.
If you often require attribute locations, the overhead of calling glGetAttribLocation may become negligible, depending on the driver. Therefore, to deal with the general case, you must create a caching system. Great, my simple and straightforward method with names instead of numbers, I just had to write quite a lot of non-trivial shell code. Even worse, you have to take care to destroy the cache when the program becomes invalid, it is likely that you will do it wrong and get errors. So we moved from “good readable names” to “terrible buggy”.
Moreover, the argument "good readable names" is erroneous. You can perfectly do something like the following for places defined in the shader itself:
const GLint vertex_loc_att = 0; const GLint texture_coord_att = 1; ...
Or you can also use an associative container as follows:
attribute_locations["vertex_location"] = 0; attribute_locations["texture_coordinate"] = 1; ...
This one, which you can also combine with glBindAttribLocation , just do this before binding:
foreach name, location in attribute_locations { glBindAttribLocation(program_id, location, name); }
Still very readable, no dynamic cache is required, just some static variables that can even be optimized.
Then you say it yourself: it obviously has advantages when using several programs, I will not repeat it here because Kos explained that one of them is already detailed , I will simply answer one of your arguments:
Attributes that do not need to be shared: this means that there are also attributes that need to be shared, for which it is a great advantage that you use fixed locations. Why should you mix two location management approaches in one application? Keep yourself away from the maintenance headache and stick to one, obviously predefined locations here, because you need them for common attributes.