View Full Version : Should I avoid rebinding the same texture/shader?

06-11-2011, 06:17 AM
In my current scenegraph I'm naievely binding my textures, shaders, vbos and whatnot for every object I draw. Frequently I am rebiniding the same information for subsequent objects. The way I understand it, binding takes up a good chunk of rendering time. Is OpenGL smart enough to catch this, or should I be tracking these repeated bindings and skipping them?

Also, does glEnable()/glDisable() have a lot of overhead?

06-11-2011, 06:27 AM
There are 2 solutions to this.
1. Track state changes in your renderer and avoid redundent calls.
2. Sort objects to avoid redundent calls. Sorting can be complex since you might want to sort for multiple reasons (blending, texture, shader, texture 1, texture 2)

06-11-2011, 07:26 AM
All right. So you're saying doing this is definitely worth while.

Alfonse Reinheart
06-11-2011, 01:49 PM
So you're saying doing this is definitely worth while.

No, he said what it would take to have fewer changes. Whether it is worthwhile is something that can only be determined by profiling.