# Why do I have additional glBindBuffer() calls?

I have a OpenGL2/OpenGLES2 application and it among others renders a sphere using the following pseudocode:

1. Update vertices data on CPU
2. call glBufferSubData(GL_ARRAY_BUFFER, ...) to update them on GPU size
3. in a loop calls glDrawElements

Now I'm checking it under RenderDoc and see additional calls to glBindBuffer between glDrawElements:

1. glBindBuffer(GL_ARRAY_BUFFER, 0)
2. glBindBuffer(GL_ARRAY_BUFFER, my_vbo_id)
3. glDrawElements

Why I see those additional calls? Why GL driver (or GL library?) inserts them?

• Might be the driver unbinding for update, depending on the arguments of BufferSubData. To avoid such highhandedness, i'd suggest to neatly map, update and unmap the (part of the) buffer with the needed (and none more) hints. Might also be much faster. – user136710 May 19 '20 at 10:41
• glBindBuffer (..., 0) doesn't "unbind"; what it actually does is revert the driver to pre-buffer-objects behaviour, where data is sourced from system memory pointers rather than from buffer objects. This can cause unintended behaviour in your program if you're not aware of it, and drivers should NEVER inject their own bindings of buffer object 0 into a command stream (it's a GL spec violation if they do). – Maximus Minimus May 19 '20 at 11:05
• @Daniel_1985 if I had glBindBuffer(..., 0) i wouldn't ask the question. The source code is here github.com/CelestiaProject/Celestia/blob/master/src/celengine/…, as you can see it's a simple for loop with glDrawElements only. For me it sounds like a bug in intel driver (mesa 19.2). – blackcat May 19 '20 at 15:03
• But vogl doesn't show additional glBindBuffer. – blackcat May 19 '20 at 15:38
• From the documentation of glBindBuffer: "... buffer set to zero effectively unbinds any buffer object previously bound ...". khronos.org/registry/OpenGL-Refpages/gl4. To the problem (if it is one), i don't have enough information for more than guesses. But i won't blame the driver prematurely, could rather be a glitch in RenderDoc, or something misread between a lot of draw calls and buffer bindings. – user136710 May 19 '20 at 20:43