Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL, is it worth explicitly unbinding after a draw call?

It seems cleaner to me to unbind using glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) and/or glBindBuffer(GL_ARRAY_BUFFER, 0) at the end of a given draw call. I like being sure that nothing is bound that should not be; however, is there much of a performance hit to this?

Would anyone consider doing it the "clean" way to be at all useful? Or should I just go down the fast & sloppy route?

(Yes, I'm aware that the bound buffer object will be replaced by the next buffer object to be bound on that target, anyway -- whether in this or the next render update. And yes, I could do performance tests. But a quick human response would be nice.)

like image 426
Engineer Avatar asked Jul 03 '12 22:07

Engineer


1 Answers

I would unbind for cleanliness while coding and then optimize it all away near release.

The benefits are that you can reorganize your code without worrying about state changes, but still have optimized state changes in the end. And you'll only be spending a fraction of the time on the actual optimization.

In terms of performance hit, if you've got thousands of additional unbind calls there will be some overhead, but it's unlikely that it'll be your bottleneck.

like image 111
Robert Rouhani Avatar answered Sep 29 '22 01:09

Robert Rouhani