_C_ License Applicability. Except to the extent portions of this file are
_C_ made subject to an alternative license as permitted in the SGI Free
_C_ Software License B, Version 1.1 (the "License"), the contents of this
_C_ file are subject only to the provisions of the License. You may not use
_C_ this file except in compliance with the License. You may obtain a copy
_C_ of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
_C_ Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
_C_ 
_C_ http://oss.sgi.com/projects/FreeB
_C_ 
_C_ Note that, as provided in the License, the Software is distributed on an
_C_ "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
_C_ DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
_C_ CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
_C_ PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
_C_ 
_C_ Original Code. The Original Code is: OpenGL Sample Implementation,
_C_ Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
_C_ Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
_C_ Copyright in any portions created by third parties is as indicated
_C_ elsewhere herein. All Rights Reserved.
_C_ 
_C_ Additional Notice Provisions: The application programming interfaces
_C_ established by SGI in conjunction with the Original Code are The
_C_ OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
_C_ April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
_C_ 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
_C_ Window System(R) (Version 1.3), released October 19, 1998. This software
_C_ was created using the OpenGL(R) version 1.2.1 Sample Implementation
_C_ published by SGI, but has not been independently verified as being
_C_ compliant with the OpenGL(R) version 1.2.1 Specification.
_C_
_C_ $Date$ $Revision$
_C_ The first character in this file must be an '_'!
_C_ Anything on a line after _C_ is ignored
_define(_filters,eqn)_C_
_C_      eqn is automatically replaced with neqn for nroff
_header(Build3DMipmaps, builds a three-dimensional mipmap)
_names(Build3DMipmaps)
.EQ
delim $$
.EN
.SH PARAMETERS
_phead(_param1)
Specifies the target texture.  Must be _const(TEXTURE_3D).
_phead(_param2)
Requests the internal storage format of the texture image.  The most
current version of the SGI implementation of GLU does not check this
value for validity before passing it on to the underlying OpenGL
implementation.  A value that is not accepted by the OpenGL
implementation will lead to an OpenGL error.  The benefit of not
checking this value at the GLU level is that OpenGL extensions can add
new internal texture formats without requiring a revision of the GLU
implementation.  Older implementations of GLU check this value and
raise a GLU error if it is not 1, 2, 3, or 4 or one of the following
symbolic constants:
_const(ALPHA),
_const(ALPHA4),
_const(ALPHA8),
_const(ALPHA12),
_const(ALPHA16),
_const(LUMINANCE),
_const(LUMINANCE4),
_const(LUMINANCE8),
_const(LUMINANCE12),
_const(LUMINANCE16),
_const(LUMINANCE_ALPHA),
_const(LUMINANCE4_ALPHA4),
_const(LUMINANCE6_ALPHA2),
_const(LUMINANCE8_ALPHA8),
_const(LUMINANCE12_ALPHA4),
_const(LUMINANCE12_ALPHA12),
_const(LUMINANCE16_ALPHA16),
_const(INTENSITY),
_const(INTENSITY4),
_const(INTENSITY8),
_const(INTENSITY12),
_const(INTENSITY16),
_const(RGB),
_const(R3_G3_B2),
_const(RGB4),
_const(RGB5),
_const(RGB8),
_const(RGB10),
_const(RGB12),
_const(RGB16),
_const(RGBA),
_const(RGBA2),
_const(RGBA4),
_const(RGB5_A1),
_const(RGBA8),
_const(RGB10_A2),
_const(RGBA12), or
_const(RGBA16).
_phead(_param3 _param4 _param5)
Specifies in pixels the width, height and depth respectively, in pixels
of the texture image. 
_phead(_param6)
Specifies the format of the pixel data.
Must be one of
_const(COLOR_INDEX),
_const(DEPTH_COMPONENT),
_const(RED),
_const(GREEN),
_const(BLUE),
_const(ALPHA),
_const(RGB),
_const(RGBA),
_const(BGR),
_const(BGRA),
_const(LUMINANCE), or
_const(LUMINANCE_ALPHA).
_phead(_param7)
Specifies the data type for _param8.
Must be one of:
_const(UNSIGNED_BYTE),
_const(BYTE),
_const(BITMAP),
_const(UNSIGNED_SHORT),
_const(SHORT),
_const(UNSIGNED_INT),
_const(INT), 
_const(FLOAT), 
_const(UNSIGNED_BYTE_3_3_2),
_const(UNSIGNED_BYTE_2_3_3_REV),
_const(UNSIGNED_SHORT_5_6_5),
_const(UNSIGNED_SHORT_5_6_5_REV),
_const(UNSIGNED_SHORT_4_4_4_4),
_const(UNSIGNED_SHORT_4_4_4_4_REV),
_const(UNSIGNED_SHORT_5_5_5_1),
_const(UNSIGNED_SHORT_1_5_5_5_REV),
_const(UNSIGNED_INT_8_8_8_8),
_const(UNSIGNED_INT_8_8_8_8_REV),
_const(UNSIGNED_INT_10_10_10_2), or
_const(UNSIGNED_INT_2_10_10_10_REV).
_phead(_param8)
Specifies a pointer to the image data in memory.
.SH DESCRIPTION
_cmnd builds a series of prefiltered three-dimensional texture maps of
decreasing resolutions called a mipmap. This is used for the antialiasing of
texture-mapped primitives.
.P
A return value of zero indicates success, otherwise a GLU error code is
returned (see _cmnd(ErrorString)).
.P
Initially, the _param3, _param4 and _param5 of _param8 are checked to
see if they are a power of 2. If not, a copy of _param8 (not _param8),
is scaled up or down to the nearest power of 2. (If _param3, _param4 or
_param5 is exactly between powers of 2, then the copy of _param8 will
scale upwards.) This copy will be used for subsequent mipmapping
operations described below.  For example, if _param3 is 57, _param4 is
23 and _param5 is 24 then a copy of _param8 will scale up to 64 in
width, down to 16 in height and up to 32 in depth, before mipmapping
takes place.
.P
Then, proxy textures (see _glcmnd(TexImage3D)) are used to determine if
the implementation can fit the requested texture. If not, all three dimensions
are continually halved until it fits. 
.P
Next, a series of mipmap levels is built by decimating a copy of _param8
in half along all three dimensions until size $1 ~times~ 1 ~times~ 1$ is
reached. At each level, each texel in the halved mipmap level is an
average of the corresponding eight texels in the larger mipmap
level. (If exactly one of the dimensions is 1, four texels are averaged.
If exactly two of the dimensions are 1, two texels are averaged.)
.P
_glcmnd(TexImage3D) is called to load each of these mipmap levels.
Level 0 is a copy of _param8.  The highest level is
${log sub 2} ( max (_eqnparam3,_eqnparam4,_eqnparam5))$.
For example, if _param3 is 64, _param4 is
16 and _param5 is 32, and the implementation can store a texture of this
size, the following mipmap levels are built: $64 ~times~ 16 ~times~ 32$,
$32 ~times~ 8 ~times~ 16$, $16 ~times~ 4 ~times~ 8$,
$8 ~times~ 2 ~times~ 4$, $4 ~times~ 1 ~times~ 2$,
$2 ~times~ 1 ~times~ 1$
and $1 ~times~ 1 ~times~ 1$. These correspond
to levels 0 through 6, respectively.
.P
See the _glcmnd(TexImage1D) reference page for a description of the
acceptable values for _param6 parameter. See the _glcmnd(DrawPixels) 
reference page for a description of the acceptable values 
for _param7 parameter.
.SH NOTES
Note that there is no direct way of querying the maximum level. This can
be derived indirectly via _glcmnd(GetTexLevelParameter). First, query
for the width, height and depth actually used at level 0.  (The width,
height and depth may not be equal to _param3, _param4 and _param5
respectively since proxy textures might have scaled them to fit the
implementation.)  Then the maximum level can be derived from the formula
${log sub 2} ( max (_eqnparam3,_eqnparam4,_eqnparam5))$.
.P
_cmnd is only available if the GLU version is 1.3 or greater.
.P
Formats _const(BGR), and _const(BGRA), and types 
_const(UNSIGNED_BYTE_3_3_2),
_const(UNSIGNED_BYTE_2_3_3_REV),
_const(UNSIGNED_SHORT_5_6_5),
_const(UNSIGNED_SHORT_5_6_5_REV),
_const(UNSIGNED_SHORT_4_4_4_4),
_const(UNSIGNED_SHORT_4_4_4_4_REV),
_const(UNSIGNED_SHORT_5_5_5_1),
_const(UNSIGNED_SHORT_1_5_5_5_REV),
_const(UNSIGNED_INT_8_8_8_8),
_const(UNSIGNED_INT_8_8_8_8_REV),
_const(UNSIGNED_INT_10_10_10_2), and
_const(UNSIGNED_INT_2_10_10_10_REV) are only available if the GL version 
is 1.2 or greater.
.SH ERRORS
_gluconst(INVALID_VALUE) is returned if _param3, _param4, or _param5 is < 1.
.P
_gluconst(INVALID_ENUM) is returned if _param2, _param6, or _param7 is not 
legal.
.P
_gluconst(INVALID_OPERATION) is returned if _param7 is _const(UNSIGNED_BYTE_3_3_2) or _const(UNSIGNED_BYTE_2_3_3_REV)
and _param6 is not _const(RGB).
.P
_gluconst(INVALID_OPERATION) is returned if _param7 is _const(UNSIGNED_SHORT_5_6_5) or _const(UNSIGNED_SHORT_5_6_5_REV)
and _param6 is not _const(RGB).
.P
_gluconst(INVALID_OPERATION) is returned if _param7 is _const(UNSIGNED_SHORT_4_4_4_4) or _const(UNSIGNED_SHORT_4_4_4_4_REV)
and _param6 is neither _const(RGBA) nor _const(BGRA).
.P
_gluconst(INVALID_OPERATION) is returned if _param7 is _const(UNSIGNED_SHORT_5_5_5_1) or _const(UNSIGNED_SHORT_1_5_5_5_REV)
and _param6 is neither _const(RGBA) nor _const(BGRA).
.P
_gluconst(INVALID_OPERATION) is returned if _param7 is _const(UNSIGNED_INT_8_8_8_8) or _const(UNSIGNED_INT_8_8_8_8_REV)
and _param6 is neither _const(RGBA) nor _const(BGRA).
.P
_gluconst(INVALID_OPERATION) is returned if _param7 is _const(UNSIGNED_INT_10_10_10_2) or _const(UNSIGNED_INT_2_10_10_10_REV)
and _param6 is neither _const(RGBA) nor _const(BGRA).
.SH SEE ALSO
_glcmnd(DrawPixels),
_glcmnd(TexImage1D),
_glcmnd(TexImage2D), 
_glcmnd(TexImage3D),
_cmnd(Build1DMipmaps),
_cmnd(Build3DMipmaps),
_cmnd(ErrorString), 
_glcmnd(GetTexImage),
_glcmnd(GetTexLevelParameter),
_cmnd(Build1DMipmapLevels),
_cmnd(Build2DMipmapLevels),
_cmnd(Build3DMipmapLevels)
