PDA

View Full Version : Just Curious, How Many Mipmaps does glGenerateMipmap generate?



larryl
01-13-2017, 03:37 PM
Hi Folks:

This (https://learnopengl.com/#!Getting-started/Textures) texture lesson says glGenerateMipmap "will automatically generate all the required mipmaps for the currently bound texture."

How many mipmaps does it generate?

Thanks
Larry

Dark Photon
01-13-2017, 04:42 PM
Just search for this API in the latest OpenGL spec (minus the "gl" prefix) at http://www.opengl.org/registry:

* OpenGL 4.5 Compatibility Specification (https://www.opengl.org/registry/doc/glspec45.compatibility.pdf)

In it, you'll find:



void GenerateMipmap( enum target );
void GenerateTextureMipmap( uint texture );
...
Mipmap generation replaces texture image levels levelbase + 1 through q with
images derived from the levelbase image, regardless of their previous contents. All
other mipmap levels, including levelbase, are left unchanged by this computation.


For details on how levelbase and q are defined, see the spec.

GClements
01-13-2017, 11:08 PM
To save you from having to rummage around the specification (8.14.3):

maxsize =max(ws,hs,ds)
p = floor(log2(maxsize)) + levelbase
q = min(p,levelmax)

where levelbase is the value of GL_TEXTURE_BASE_LEVEL, levelmax is the value of GL_TEXTURE_MAX_LEVEL, and ws, hs and ds are the width, height and depth of the base level.

IOW, it generates all the levels from the one above the base level (i.e. the half-size level) up to either the 1x1x1 level or the configured maximum level, whichever is lower.