Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While in the rendering loop, is it OK to call glUseProgram? Does it have a big overhead? I'm planing to use a program for each different material in the scene. I'm a real beginner with OpenGL and I'm afraid that changing the program several times for each frame it's not the best practice (although I can't think of something else).

share|improve this question
up vote 2 down vote accepted

In the order of slow things, changing programs is more or less around the level of changing textures. It's something you have to do in order to render what you need, but for performance sake, it might be a good idea to minimize the number of changes where reasonable. This could be changing the order in which things are drawn (objects using the same shader are rendered sequentially), texture atlasing, etc.

share|improve this answer
That's what I've though too, group the objects that use the same shader to be drawn one after the other. I just needed a confirmation that things are usually done this way. – Valentin Radu Dec 22 '11 at 0:12

It's more clear if you do it the way you described. For me, clarity always wins over performance. It will be easier to trace bugs if you enclose only the code that absolutely needs the shaders with glUseProgram(...).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.