Multiple shaders: how to deal with attributes?

I was wondering which are the best practices (resulting in best performance) when using multiple shaders. The approach I would use at the moment is:

  • create and populate index buffer, vertex buffer, normal buffer, …
  • compile and link glsl program


  • use the glsl program
  • query attribute locations for vertex, normal, …
  • bind buffers, set and enable the attributes
  • query all uniform locations and set corresponding data
  • glDrawElements

Is there a better approach than re-querying all locations at each draw iteration?

Rather than querying locations at each render, you can store the locations for all the attributes/uniforms at the initialization then during render just use the stored locations of attrib./uniforms.

Mh indeed, makes sense. Thanks!