DirectX SDK

Selecting and Displaying a Mipmap

[C++]

Call the IDirect3DDevice7::SetTexture method to 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 D3DTEXTUREMIPFILTER enumerated type to the D3DTSS_MIPFILTER texture stage state. Direct3D will then automatically perform mipmap texture filtering.

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

LPDIRECTDRAWSURFACE7 lpDDLevel, lpDDNextLevel; 
DDSCAPS2 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 IDirectDrawSurface7::Lock or IDirectDrawSurface7::GetSurfaceDesc method), the dwMipMapCount member of the DDSURFACEDESC2 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.

[Visual Basic]

Call the Direct3DDevice7.SetTexture method to 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 CONST_D3DTEXTUREMIPFILTER enumerated type to the D3DTSS_MIPFILTER texture stage state. Direct3D will then automatically perform mipmap texture filtering.

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

On Local Error Resume Next

Dim DDLevel As DirectDrawSurface7, _
    DDNextLevel As DirectDrawSurface7

Dim ddsCaps As DDSCAPS2

DDLevel = DDMipMap
ddsCaps.lCaps = DDSCAPS_TEXTURE Or DDSCAPS_MIPMAP
While Err.Number = DD_OK
    ' Process this level.
    ' .
    ' .
    ' .
    Set DDNextLevel = DDLevel.GetAttachedSurface(ddsCaps)
    DDLevel = DDNextLevel
Wend
If ((Err.Number <> DD_OK) And (Err.Number <> DDERR_NOTFOUND)) Then
    ' Code to handle the error goes here
End If
. 
. 
. 

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 DirectDrawSurface7.Lock or DirectDrawSurface7.GetSurfaceDesc method), the lMipMapCount member of the DDSURFACEDESC2 type contains the number of levels in the mipmap, including the top level. For levels other than the top level in the mipmap, the lMipMapCount member specifies the number of levels from that mipmap to the smallest mipmap in the chain.