TexturesGL 3.0
glGenerateMipmap
Builds all the smaller mipmap levels from level 0 of the bound texture.
Signature
void glGenerateMipmap(GLenum target);
How it works
Mipmaps are pre-shrunk copies of a texture: 1/2, 1/4, 1/8… of the size. When a surface is far away the GPU samples a small copy, which removes shimmering and is faster. This call computes them all automatically.
Call it after uploading level 0, and again whenever the image changes.
Parameters
targetGLenum
GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_2D_ARRAY…
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_OPERATION
- The texture is a cube map whose faces are not all the same size/format.
Example
example.cpp
1glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
2glGenerateMipmap(GL_TEXTURE_2D);