Automatic Generation of Mipmaps (Direct3D 9)

You can now automatically create a mipmap which is a series of textures, each filtered to a different resolution. Mipmaps are commonly used to provide different levels of detail when rendering. Automatically generating mipmaps at texture creation time takes advantage of hardware filtering because the mipmap resides in video memory.

To generate a mipmap automatically, set a new usage D3DUSAGE_AUTOGENMIPMAP before calling CreateTexture. Sublevel generation from this point on is completely transparent to the application. Only the top texture level is accessible to the application; the texture sublevels are not accessible since they will be created only when needed by the driver. In cases where sublevel generation may take a lot of time, use GenerateMipSubLevels to hint to the driver that it should generate sublevels at a time appropriate for the application.

Mipmap Filtering

SetAutoGenFilterType controls the filtering quality during automatic generation. Changing the filter type dirties the mipmap sublevels and causes them to be regenerated. Use GetAutoGenFilterType to get the current filter type. The default filter type is D3DTEXF_LINEAR. If the driver doesn't support a linear filter, the filter type will be set to D3DTEXF_POINT.

These methods have no effect if the texture is not created with D3DUSAGE_AUTOGENMIPMAP And no failure is returned. All filter types supported by the driver for regular texture filtering are supported for autogenerated except D3DTEXF_NONE. For each resource type, drivers should support all the filter types reported in the corresponding texture, CubeTexture, and volumetexture filter caps.

To check which filter types are supported, check to see which caps are supported by the TextureFilterCaps and/or CubeTextureFilterCaps members of D3DCAPS9.

Mipmap Support

D3DUSAGE_AUTOGENMIPMAP is only a hint, and specifying this during texture creation or when calling CheckDeviceFormat would not cause an error on any of the device driver interface (DDI) types.

Calling UpdateTexture is illegal when the source is an automatically generated mipmap, but the destination is not. The source can be a non-automatically generated mipmap and the destination can be an automatically generated mipmap. In this case, only the topmost matching level is updated. All other source sublevels are ignored. Similarly, when both the source and destination are automatically generated, only the topmost matching level is updated. The sublevels from the source are ignored and the destination sublevels are regenerated.

To check for support for automatic generation of mipmaps, check to see that D3DCAPS2_CANAUTOGENMIPMAP is set. If it is, call CheckDeviceFormat with D3DUSAGE_AUTOGENMIPMAP. If the return value is D3D_OK, the mipmaps are guaranteed to be autogenerated. If the return value is D3DOK_NOAUTOGEN, this means that the create call will succeed, but there won't be any mipmaps generated.

Direct3D Textures