Texture management, in short, is the process of determining which textures are needed for rendering at a given time, and ensuring that those textures are loaded into video memory. Like any algorithm, texture management schemes vary in complexity, but any approach to texture management involves the following key tasks:
Previously, Direct3D applications were responsible for managing textures on their own. Direct3D Immediate Mode for DirectX 6.0 introduces system supported texture management, where Direct3D efficiently and intelligently performs texture management, ensuring that textures are loaded for optimal performance. (Texture surfaces that Direct3D manages are casually referred to as "managed textures.")
You request automatic texture management for textures when you create them. To get a managed texture, simply create a texture surface that also includes the DDSCAPS2_TEXTUREMANAGE flag in the dwCaps2 member of the associated DDSCAPS2 structure. Note that you are not allowed to specify where you want the texture created–you can't use the DDSCAPS_SYSTEMMEMORY or DDSCAPS_VIDEOMEMORY flags when creating a managed texture. After creating the managed texture, you can call the IDirect3DDevice3::SetTexture method to set it to a stage in the rendering device's texture cascade.
Direct3D automatically downloads textures into video memory as needed. (The system might cache managed textures in local or non-local video memory, depending on the availability of non-local video memory or other factors. Where your managed textures are cached is not communicated to your application, nor is this knowledge required to take advantage of automatic texture management.) If your application uses more textures than can fit in video memory, Direct3D will evict older textures from video memory to make room for the new textures. If you use an evicted texture again, the system uses the original system memory texture surface to reload the texture in the video memory cache. Reloading the texture is a minor, but obviously necessary, performance hit to the application.
You can dynamically modify the original system memory copy of the texture by blitting or locking the texture surface. When the system detects a "dirty" surface–after a blit is completed, or when the surface is unlocked–the texture manager automatically updates the video memory copy of the texture. The performance hit incurred is similar to reloading an evicted texture.
When entering a new level in a game, your application may need to flush all managed textures from video memory. You can explicitly request that all managed textures be evicted by calling the IDirect3D3::EvictManagedTextures method. When you call this method, Direct3D destroys any cached local and non-local video memory textures, but leaves the original system memory copies untouched.
Note You cannot retrieve a texture handle for a managed texture by calling the IDirect3DTexture2::GetHandle method.