Question

I call glTexImage2D with a parameter level = 0. Then I call glGenerateMipmap(GL_TEXTURE_2D). What happens with GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL ? I assume that they are automatically set this way:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmapsCount - 1);

Later I can set above parameters manually and for example reduce the max level. Is that right ?

Was it helpful?

Solution

GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL values of the mipmap stack are derived as you mention. Those values define the range of mipmap levels required for what's called texture completeness. When you ask OpenGL to generate mipmaps automatically using glGenerateMipmap, the entire stack is populated. If you use glTextureStorage to specify the number of levels, GL_TEXTURE_MAX_LEVEL is set to one less than the maximum level provided in the call.

You're also correct that you can modify the base and max levels after building the mipmap stack, but if you're having OpenGL build the mipmap stack, I don't think it would gain you very much. If I remember this correctly, you'd modify the base and max levels when you were loading the mipmaps (by repeatedly calling glTexImage* and incrementing the level parameter) so that you wouldn't need to load the entire mipmap stack (you might do this to save texture memory, or perhaps to have better control over sampling for higher [i.e., smaller mipmaps in the stack] levels). You might also use the GL_TEXTURE_MIN_LOD, and GL_TEXTURE_MAX_LOD, to control which mipmaps from the mipmap stack were used in texturing. On reason for this was to allow asynchronous loading of mipmap levels while texturing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top