) grTexCalcMemRequired() calculates and returns the amount of memory required by a mipmap of the specified LOD range, aspect ratio, and format. The first two arguments, smallLOD and largeLOD, define the range of LODs in the mipmap. The third argument, aspectRatio, specifies the aspect ratio of the mipmap and the fourth argument, format, gives the texture format. All four arguments are specified using Glide constants; the choices are listed in Table Managing Texture Memory.2.
The memory requirements for the mipmap can be computed directly from these four parameters. The LOD range determines the length of the longest edge of each LOD. The aspect ratio provides a way to compute the length of the shorter edge of the LOD and hence the number of texels in the mipmap. The texture format determines the space requirements for one texel, which can be multiplied by the number of texels in order to compute the storage requirements for the mipmap. The two functions described here, grTexCalcMemRequired() and grTexTextureMemRequired(), will do the calculations.
Many of Glide’s texture management routines make use of the GrTexInfo structure to collect the mipmap parameters together with the mipmap data.
typedef struct {
GrLOD_t smallLod;
GrLOD_t largeLod;
GrAspectRatio_t aspectRatio;
GrTextureFormat_t format;
void *data;
} GrTexInfo;
grTexTextureMemRequired() calculates and returns the number of bytes required to store the texture described in the structure pointed to by info. The number returned may be added to the starting address for a texture download to determine the next free location in texture memory.
The range of LODs in the mipmap is defined in the info structure. The other argument, evenOdd, indicates whether even, odd, or all LODs within the specified range should be used in computing the space requirements. For example, if the mipmap is used for trilinear filtering, the even LODs will be downloaded and used on one TMU, and the odd LODs on another. evenOdd is specified symbolically: valid values are GR_MIPMAPLEVELMASK_EVEN, GR_MIPMAPLEVELMASK_ODD, and GR_MIPMAPLEVELMASK_BOTH. Figure Managing Texture Memory.2 describes the evenOdd flag and even and odd LODs. In general, an LOD is even if its size is an even power of 2, and odd otherwise. Thus, the even LODs are GR_LOD_256, GR_LOD_64, GR_LOD_16, GR_LOD_4, and GR_LOD_1. The other LODs are odd: GR_LOD_128, GR_LOD_32, GR_LOD_8, and GR_LOD_2.