I'm trying to get a grip on mipmaps with OpenGL. I believe I understand the concept, but when trying to have OpenGL generate them I wonder how it determines how many mipmaps to generate?

Here's what I'm running with right now to initialize a 2d texture:

    glGenTextures(1, &mTexture);
    glBindTexture(GL_TEXTURE_2D, mTexture);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA , textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &textureData[0]);
    glBindTexture(GL_TEXTURE_2D, 0);

Nowhere do I specify how many mipmap levels to generate. How many mipmaps are generated in this case? Where do you specify this number?

I've also seen another technique from http://www.opengl.org/wiki/Common_Mistakes where you use glTexStorage2D to specify all the mipmaps levels instead - but how many levels can you specify and what is a reasonable number for quality?


1 Answer 1


The number of mip map levels on a texture is defined by the range between GL_TEXTURE_BASE_LEVEL (default 0) and GL_TEXTURE_MAX_LEVEL (default 1000). You can set these manually via glTexParameteri or via glTextureStorage. In case of glTextureStorage the min level will be 0 and the max level will be whatever you hand over as a parameter to glTextureStorage - 1.

glGenerateMipmap populates the entire range (in this case 1000 textures). Obviously after the generated mipmap texture reaches a certain size (e.g. 2x2, I'm not sure what the standardized minimum size is) all mip map levels after it will use the same texture. I'm not sure if space is actually allocated for those extra textures or if they just refer to the same texture somehow (probably implementation dependent).

If you want to avoid that overhead and make sure, set GL_TEXTURE_MAX_LEVEL to log_2(n) where n is max(texture_resolution_x,texture_resolution_y) since that is the maximum amount of levels required before the textures gets to a size of 1x1 pixels.

  • \$\begingroup\$ I see; so the above solution with glTexImage2D will generate all the possible mipmaps up untill 1000? \$\endgroup\$ Dec 1, 2013 at 19:49
  • \$\begingroup\$ @KaiserJohaan yes \$\endgroup\$
    – TravisG
    Dec 1, 2013 at 20:04
  • 2
    \$\begingroup\$ Not specifically up until 1000; up until you get to a 1x1 miplevel. \$\endgroup\$ Dec 1, 2013 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .