Selecting and Displaying a Mipmap

If your program uses texture handles, it must assign the handle of the mipmap texture as the current texture. For details, see Current Texture.

If your application uses texture interface pointers, it must set the mipmap texture set as the first texture in the list of current textures. For more information, see Multiple Texture Blending.

After your application selects the mipmap texture set, it must assign values from the D3DTEXTUREFILTER enumerated type to the D3DRENDERSTATE_TEXTUREMAG and D3DRENDERSTATE_TEXTUREMIN render states. Direct3D will then automatically perform mipmap texture filtering.

Your application can also manually traverse a chain of mipmap surfaces by using the IDirectDrawSurface4::GetAttachedSurface method and specifying the DDSCAPS_MIPMAP and DDSCAPS_TEXTURE flags in the DDSCAPS structure. The following example traverses a mipmap chain from highest to lowest resolutions:

LPDIRECTDRAWSURFACE lpDDLevel, lpDDNextLevel; 
DDSCAPS ddsCaps; 
HRESULT ddres;
 
lpDDLevel = lpDDMipMap; 
lpDDLevel->AddRef(); 
ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP; 
ddres = DD_OK; 
while (ddres == DD_OK) 
{ 
    // Process this level. 
    . 
    . 
    . 
    ddres = lpDDLevel->GetAttachedSurface( 
        &ddsCaps, &lpDDNextLevel); 
    lpDDLevel->Release(); 
    lpDDLevel = lpDDNextLevel; 
} 
if ((ddres != DD_OK) && (ddres != DDERR_NOTFOUND)) 
{
    // Code to handle the error goes here
}
. 
. 
. 
 

Applications need to manually traverse a mipmap chain to load bitmap data into each surface in the chain. This is typically the only reason to traverse the chain.

Direct3D explicitly stores the number of levels in a mipmap chain. When an application obtains the surface description of a mipmap (by calling the IDirectDrawSurface4::Lock or IDirectDrawSurface4::GetSurfaceDesc method), the dwMipMapCount member of the DDSURFACEDESC structure contains the number of levels in the mipmap, including the top level. For levels other than the top level in the mipmap, the dwMipMapCount member specifies the number of levels from that mipmap to the smallest mipmap in the chain.