Should VBO be unbound before calling glDeleteBuffers?

论坛 期权论坛 脚本     
匿名网站用户   2020-12-20 02:45   22   0

http://stackoverflow.com/questions/23564945/should-vbo-be-unbound-before-calling-gldeletebuffers#
The only time you would want to manually unbind a resource in GL prior to deletion is if you have it bound in a separate context. That is because one the criteria for actually freeing the memory associated with a GL resource is that it have a reference count of 0. glDelete* (…) only unbinds an object from the current context prior to putting it on a queue of objects to free.
If you delete it while a VAO that is not currently bound holds a pointer to this buffer, or if it is bound in a completely different OpenGL context from the one you call glDelete* (…) in, then the reference count does not reach 0 before glDelete* (…) finishes. As a result, the memory will not be freeduntil you actually unbind it from or destroy all VAO / render contexts that are holding references. You will effectively leak memory until you take care of all the dangling references.
In short, glDelete* (…) will always unbind resources from the current context and reclaim any names for immediate reuse, but it will only free the associated memory if after unbinding it the reference count is 0.
In this case, unbinding is completely unnecessary because you are doing so in the same context you call glDeleteBuffers (…) from. This call implicitly unbinds the object you are deleting, so you are doing something redundant. What is more, you already deleted your VAO prior to calling glDeleteBuffers (…) – when that VAO was deleted, it relinquished all of its pointers and thus decremented the reference count to your buffer.

The only time you would want to manually unbind a resource in GL prior to deletion is if you have it bound in a separate context. That is because one the criteria for actually freeing the memory associated with a GL resource is that it have a reference count of 0. glDelete* (…) only unbinds an object from the current context prior to putting it on a queue of objects to free.
If you delete it while a VAO that is not currently bound holds a pointer to this buffer, or if it is bound in a completely different OpenGL context from the one you call glDelete* (…) in, then the reference count does not reach 0 before glDelete* (…) finishes. As a result, the memory will not be freeduntil you actually unbind it from or destroy all VAO / render contexts that are holding references. You will effectively leak memory until you take care of all the dangling references.
In short, glDelete* (…) will always unbind resources from the current context and reclaim any names for immediate reuse, but it will only free the associated memory if after unbinding it the reference count is 0.
In this case, unbinding is completely unnecessary because you are doing so in the same context you call glDeleteBuffers (…) from. This call implicitly unbinds the object you are deleting, so you are doing something redundant. What is more, you already deleted your VAO prior to calling glDeleteBuffers (…) – when that VAO was deleted, it relinquished all of its pointers and thus decremented the reference count to your buffer.

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP