PDA

View Full Version : Multiple shaders: how to deal with attributes?



smani
02-13-2011, 08:39 AM
Hello,
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:
init:
- create and populate index buffer, vertex buffer, normal buffer, ...
- compile and link glsl program

draw:
- 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?
Thanks!
smani

mobeen
02-13-2011, 08:49 AM
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.

smani
02-13-2011, 08:57 AM
Mh indeed, makes sense. Thanks!