Microsoft DirectX 8.0 (Visual Basic)

Creating a Set of Mipmaps

The following example shows how your application can call Direct3DDevice8.CreateTexture to build a chain of five mipmap levels: 256×256, 128×128, 64×64, 32×32, and 16×16.

' This code example assumes that the variable m_D3D contains
' a valid reference to a Direct3DDevice8 object.
Dim DDMipmap as Direct3DTexture8

Set DDMipmap = m_D3D.CreateTexture(256, 256, 5, 0, D3DFMT_R8G8B8, D3DPOOL_DEFAULT)

The first two parameters that are accepted by CreateTexture are the size and width of the top-level texture. The third parameter specifies the number of levels in the texture. If you set this to zero, Microsoft® Direct3D® creates a chain of surfaces, each a power of two smaller than the previous one, down to the smallest possible size of 1x1. The fourth parameter specifies the usage for this resource; in this case, 0 is specified to indicate no specific usage for the resource. The fifth parameter specifies the surface format for the texture. Use a value from the CONST_D3DFORMAT enumerated type for this parameter. The sixth parameter specifies a member of the CONST_D3DPOOL enumerated type indicating the memory class into which to place the created resource. Unless you are using dynamic textures, D3DPOOL_MANAGED is recommended.

Note  Each surface in a mipmap chain has dimensions that are one-half that of the previous surface in the chain. If the top-level mipmap has dimensions of 256×128, the dimensions of the second-level mipmap are 128×64, the third-level is 64×32, and so on, down to 1×1. You cannot request a number of mipmap levels in Levels that would cause either the width or height of any mipmap in the chain to be smaller than 1. In the simple case of a 4×2 top-level mipmap surface, the maximum value allowed for Levels is three. The top-level dimensions are 4×2, the second-level dimensions are 2×1, and the dimensions for the third level are 1×1. A value larger than 3 in Levels results in a fractional value in the height of the second-level mipmap, and is therefore disallowed.