3
\$\begingroup\$

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).

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Valentin Radu Dec 22 '11 at 0:12
0
\$\begingroup\$

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(...).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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