Im currently trying to find out how to free a mipmap level after it has been initialized for a texture object.
Let say you initialize level 2,3,4,5,… as an initial step and at some point in your program you initialize level 1, because you need a greater level of detail. After a while you don’t really need level 1 anymore and you want to free this texture memory.
Im not perfectly sure how to obtain this. Can one just call glTexImage*D again with the level=1, and specify zero width and height or is it enough to change the BASE_LEVEL parameter. Or do one have to use glDeleteTexture and start over in order to obtain this?
I cannot guarantee, that what i am telling you is correct, but as far as i know it is not possible to do what you imagine. You would need to delete the whole texture and recreate it. You certainly can just set the mipmap-bias, so that your texture level 0 or 1 is never used, and the driver might even be smart enough not to load those levels into GPU RAM, but it will definitely stay in memory.
The thing is, every texture starts as a texture with mipmap level 0. Everything else is the “scaled down” version. So, if you set your level 0 to zero size, i am pretty certain drivers won’t accept this and throw an INVALID_OPERATION at you.
Even if the spec would allow this, i am absolutely sure, that drivers don’t implement this very rare corner-case. Though it is an interessting thought
The spec describes what happens when you send a zero sized texture in chapter 3.8 page 157:
“An image with zero width, height, or depth indicates the null texture. If the null texture is specified for the level-of-detail specified by texture parameter TEXTURE_BASE_LEVEL (see section 3.8.4), it is as if texturing were disabled”
Sounds like this is what you want for the levels you don’t need.
To use the rest of the mipmap chain you would need to limit the LOD levels with TEXTURE_BASE_LEVEL and TEXTURE_MAX_LEVEL to the mipmaps you actually downloaded or the texture would be inconsistent (=> texture unit switched off).
I also read that section in the spec, but I was not sure if this meant that one could call glTexImage*D twice at the same level-of-detail in order to make opengl free the previous initialized memory.
I am glad that you interpreted it the same way as I suspected it. Hel.