Usually we might not need to explicitly do this to fully clean up full-chain of OpenGL context which ranges from VBO, VAO, texture objects, disabling all enabled vertex attribute arrays, or even pragamatic setting variable to NULL
or 0
.
Most likely after the program quits, it will be automatically destroyed and returned back claimed memory to OS. But some says we cannot be relied on such behavior as it might not happen cleanly.
So here is the sequence in shutting down or destroying sequence sequence of OpenGL.
glDisableVertexAttribArray()
glDeleteBuffers()
Reset binded texture object via glBindTexture(GL_TEXTURE_2D, 0)
and other binding targets i.e. GL_TEXTURE_1D
, GL_TEXTURE_3D
, and so on.
Note: Reset currently using program via
glUseProgram(0)
will result in undefined behavior as noted in its man page “If program is zero, then the current rendering state refers to an invalid program object and the results of shader execution are undefined. However, this is not an error.
”.
glDeleteTextures()
glDeleteProgram()
Delete all VAOs via glDeleteVertexArrays()
First published on Aug, 16, 2019
Written by Wasin Thonkaew
In case of reprinting, comments, suggestions
or to do anything with the article in which you are unsure of, please
write e-mail to wasin[add]wasin[dot]io
Copyright © 2019-2021 Wasin Thonkaew. All Rights Reserved.