DirectX SDK

Generating Mipmaps

By default, the texture creation methods provided by the Direct3DX utility library will generate mipmaps for textures as long as the rasterizer supports mipmaps. However, mipmap generation can be disabled with the D3DX_TEXTURE_NOMIPMAP flag.

The following code fragment sets the D3DX_TEXTURE_NOMIPMAP flag to create a texture that does not support mipmaps:

    DWORD flags = D3DX_TEXTURE_NOMIPMAP;
    pFlags = &flags;
 
    hr = D3DXCreateTexture(
            pd3dDevice,         // d3ddevice passed in
            pFlags,             // loading options
            pWidth,             // width
            pHeight,            // height
            pTmpPixelFormat,    // desired pixel format
            NULL,               // palette
            &pSurf,             // return surface
            pNumMipMaps);       // number of mipmap levels

The following code example then queries the created texture for mipmap support:

    DDCAPS ddcaps;
    ZeroMemory(&ddcaps, sizeof(ddcaps));
    ddcaps.dwSize = sizeof(ddcaps);
 
    hr = pDD->GetCaps(&ddcaps, NULL);
    if (SUCCEEDED(hr))
    {
    // Check for mipmapping
        if (!(*pFlags & D3DX_TEXTURE_NOMIPMAP))
        {
            if (!(ddcaps.ddsCaps.dwCaps & DDSCAPS_MIPMAP))
            {
                // Disable mipmapping
                *pFlags |= D3DX_TEXTURE_NOMIPMAP;
            }
        }
    }

The D3DXLoadTextureFromSurface and D3DXLoadTextureFromFile functions allow the specification of the particular mipmap level that you want to update. If you specify D3DX_DEFAULT as the mipmap level, then the top-most level is updated and the other mipmap levels are automatically updated to match.

Applications that need to carefully update the individual levels of a mipmap should pass explicit mipmap levels to the Direct3DX texture loading methods. Also, applications that directly use the IDirectDrawSurface7::Blt and IDirectDrawSurface7::Lock methods to modify surfaces should update mipmap levels as necessary.