Graphics Reference
In-Depth Information
Automatic Mipmap Generation
In the MipMap2D example in the previous section, the application
created an image for level zero of the mipmap chain. It then generated
the rest of the mipmap chain by performing a box filter on each image
and successively halving the width and height. This is one way to
generate mipmaps, but OpenGL ES 3.0 also provides a mechanism for
automatically generating mipmaps using glGenerateMipmap .
void glGenerateMipmap (GLenum target )
the texture target to generate mipmaps for; can be
GL_TEXTURE_2D , GL_TEXTURE_3D , GL_TEXTURE_2D_ARRAY , or
GL_TEXTURE_CUBE_MAP
target
When calling glGenerateMipmap on a bound texture object, this function
will generate the entire mipmap chain from the contents of the image
in level zero. For a 2D texture, the contents of texture level zero will be
successively filtered and used for each of the subsequent levels. For a
cubemap, each of the cube faces will be generated from the level zero in
each cube face. Of course, to use this function with cubemaps, you must
have specified level zero for each cube face and each face must have a
matching internal format, width, and height. For a 2D texture array, each
slice of the array will be filtered as it would be for a 2D texture. Finally,
for a 3D texture, the entire volume will be mipmapped by performing
filtering across slices.
OpenGL ES 3.0 does not mandate that a particular filtering algorithm be
used for generating mipmaps (although the specification recommends
box filtering, implementations have latitude in choosing which algorithm
they use). If you require a particular filtering method, then you will still
need to generate the mipmaps on your own.
Automatic mipmap generation becomes particularly important when
you start to use framebuffer objects for rendering to a texture. When
rendering to a texture, we don't want to have to read back the contents of
the texture to the CPU to generate mipmaps. Instead, glGenerateMipmap
can be used and the graphics hardware can then potentially generate the
mipmaps without ever having to read the data back to the CPU. When
we cover framebuffer objects in more detail in Chapter 12, “Framebuffer
Objects,” this point should become clear.
 
 
 
Search WWH ::




Custom Search