Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.