|Microsoft DirectX 9.0|
Automatic generation of mipmaps takes advantage of hardware filtering during texture creation to allow functionality such as full transparency. In particular, mipmap render targets benefit from automatic generation. Because they reside in video memory, software filtering is unable to be applied efficiently.
To generate a mipmap automatically, set a new usage D3DUSAGE_AUTOGENMIPMAP at creation time. Sublevel generation from this point on is completely transparent to the application. In some instances, on some hardware, sublevel generation may take a lot of time so IDirect3DBaseTexture9::GenerateMipSubLevels can be used to provide hints to the driver to generate the sublevels at a time appropriate for the application.
IDirect3DBaseTexture9::SetAutoGenFilterType controls the filtering quality during automatic generation. Changing the filter type "dirties" the mipmap sublevels and causes them to be regenerated.
Use IDirect3DBaseTexture9::GetAutoGenFilterType to get the current filter type. The (default) filter type set at texture creation time 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.
IDirect3DDevice9::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.
When creating an automatically generated mipmap, the Levels parameter must be set to zero or one.
To check for support for automatic generation of mipmaps, check to see that D3DCAPS2_CANAUTOGENMIPMAP is set. If it is, call IDirect3D9::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.
To check which filter types are supported, check to see which caps are supported by the TextureFilterCaps and/or CubeTextureFilterCaps members of D3DCAPS9.
Finally, note that D3DUSAGE_AUTOGENMIPMAP is only a hint, and specifying this during texture creation or when calling IDirect3D9::CheckDeviceFormat would not cause an error on any of the device driver interface (DDI) types.