1
votes

If I create a QGLWidget, and then I allocate my own textures using something like glGenTextures, glTex2DImage, etc, will all that texture data get cleaned up when I delete the widget? (Also, I will also have shared widgets which will get deleted too).

I looked at the source for the destructor and it looks like it is deleting the context, which I assume will also clean up any textures I generated with that context

https://qt.gitorious.org/qt/qt/source/ca5b49a2ec0ee9d7030b8d03b561717addd3441f:src/opengl/qgl.cpp#L3409

Just want to make sure incase I am missing something

1

1 Answers

1
votes

No, the texture storage will only be released when an object that uses it is not bound in any of the contexts that share it. Moreover, it is not implicitly released just because 1 context is destroyed. You share the same object name space between all of your shared contexts, so there is no way that could be allowed to happen (all contexts in the share group would have to be destroyed).

Each context maintains its own set of bound textures, so if you bind texture 1 in context A and B, then delete context A the texture cannot be freed until you also delete (or unbind it from) context B. This behavior applies to calling glDeleteTextures (...) as well.

That function will implicitly unbind the texture(s) you pass it from the current (calling) context, but until it is unbound in any other context the memory is not allowed to be freed. The only thing that will happen immediately is that the texture name is immediately re-usable and may be returned by a subsequent call to glGenTextures (...).

Long story short, in your case the memory will eventually be freed (you claim that you are going to destroy all of the contexts). It just will not necessarily be freed immediately when you destroy your first context - other conditions described above have to be met first.