0
\$\begingroup\$

I'm reading through the OpenGL documentation for version 3.3 core. I'm having issues understanding proper buffer deletion.

At the moment I have an object that loads itself into OpenGL memory in the constructor and only exposes a VAO with the attribute pointers and a bound element array ready for rendering. When it stops existing it deletes all the buffers and sets pointers to NULL.

How do I properly delete OpenGL data? I'm going to assume that the object doesn't stop existing while it's being rendered. Do I have to do something more than just delete the VAO and then delete the buffer objects? Does that leave anything out? Should I bind the VAO disable the attributes, unbind it and then delete it?

\$\endgroup\$
2
\$\begingroup\$

In general, deleting an object in OpenGL involves nothing more than calling one of the glDelete* functions, where * is the type of object. OpenGL is smart enough to not break or otherwise implode when told to delete an object that may still be used by the renderer.

If you delete an object that is still attached to another object (a buffer object in a VAO or a texture attached to an FBO), then the actual deletion is deferred until all attachments are broken or the objects attached to them are themselves deleted. So if you delete a buffer object that a VAO uses, that VAO will still work, preserving the lifetime of the buffer object until it's no longer using it.

So ultimately, you don't have to care.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.