23.9 C
New York
Monday, April 28, 2025

C++: when ought to linking and draining happen in OpenGL?


Unbinding in OpenGL is mostly by no means essential, and try to be suspicious of tutorials that use unbinding, as it could display a lack of awareness of how the API is designed to work.

Typically, the intention of unbinding is now not to make use of the beforehand connected object for rendering and different operations. Nevertheless, in observe, disassembly typically has different unintended effects that you could be not intend, might not need, and should not even take into account.

By “unbind” right here, after all, I imply “Binding Object 0”, and this all comes with the caveat that in fashionable OpenGL and/or core profiles, the habits of doing this can be invalid. Nevertheless, it may nonetheless lead you to errors in case you are not conscious of what you’re really doing.

For texture objects, 0 is definitely a legitimate texture object, and binding texture 0 will revert to OpenGL 1.0 (with out the feel objects extension). You may bind texture 0, you possibly can GLTEXIMAGE, you possibly can draw with it.

For buffer objects, hyperlink 0 buffer 0 will revert to the habits of client-side vertex arrays, the place the varied GL* pointer calls carry a pointer to a piece of system reminiscence, not an offset in a buffer. Chances are you’ll be vulnerable to deferencing a null pointer.

For shaders, Binding Shader 0 will return you to the fastened operate pipeline.

For VAOs, binding VAO 0 will return you to the OpenGL habits earlier than VAO is launched.


For sturdy code, the strategy I choose is to bind every part you want earlier than every draw name (or group of draw calls utilizing the identical state), and by no means put on out until the undraw habits is what you explicitly intend. This sample displays that they use extra fashionable APIs and is extra more likely to match what the {hardware} and driver count on to see internally.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles