OpenGL es 1.1 - android - does gl.glDeleteTextures free video memory?

旧时模样 提交于 2019-12-23 05:14:14

问题


Context:

I load 2 textures into an int[] of size 2 using gl.glGenTextures and then bind a texture to each slot of the int[]. (This works fine, and I am able to draw each texture to the "texture squares" I had prepared)

Now, my actual concern:

Will running gl.glDeleteTextures(2, int[] containing 2 texture pointers, 0) clear up the memory used by the 2 textures generated into my int[]? Or does this just free up the "texture names"?


回答1:


It does delete the texture data. The memory might not be freed immediately when you make the call, but it will get freed eventually. Or at least made available for reuse by other allocations. The details of memory management are highly platform and driver specific. But as a user of the OpenGL API, you can consider the memory freed after the glDeleteTextures() call.

The reason why the memory might not be freed immediately is that OpenGL operates asynchronously. In a typical call sequence like this:

glBindTexture(GL_TEXTURE_2D, texId);
glDrawArrays(...);
glDeleteTextures(1, &texId);

The draw call is most likely still queued up for execution by the GPU when the glDeleteTextures() call is made. Since the draw call uses the texture data, it cannot be deleted immediately. The memory can only be freed after the GPU finished executing the draw call.

There are a couple of exceptions where the texture will actually not be freed after glDeleteTextures() is called on it. They are not very common scenarios, but should be mentioned for completeness:

  1. If the texture is attached to an FBO, and that FBO is not currently bound, the texture reference of the FBO will keep the texture alive until either the texture is detached from the FBO, or the FBO is deleted. Note that for a currently bound FBO, the texture will automatically be detached when it is deleted.

  2. If resources are shared between multiple contexts, things also get more complicated. It's best to consult the specs about the exact behavior in this case.



来源:https://stackoverflow.com/questions/25269383/opengl-es-1-1-android-does-gl-gldeletetextures-free-video-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!