PDA

View Full Version : Unbinding things after you use them



redphi
06-17-2012, 11:59 AM
Right, now I unbind targets with glBindBuffer(GL_ARRAY_BUFFER, 0); after I finish using each VBO. Similarly, I reset the "active program" using glUseProgram(0); after I finish using them. Is there any benefits or drawbacks to this?

menzel
06-17-2012, 01:58 PM
More GL calls can eat some performance and there is no direct advantage of:


glUseProgram( foo );
glUseProgram( 0 );
glUseProgram( bar );
glUseProgram( 0 );
// next frame
glUseProgram( foo );
...


over just:



glUseProgram( foo );
glUseProgram( bar );
// next frame
glUseProgram( foo );
...


You only might catch errors in your program more easily if for example you draw something without setting the correct VAOs or shaderprograms if you also unset all of them, so you will try to draw with program 0 and VAO 0 instead of the one that just happens to be active (and might work for a while making the bug even harder to find later on). But apart from that 'cleaning up' might not help you much if you do that each frame.

redphi
06-17-2012, 05:59 PM
Thanks, noted!