Platform SDK: DirectX |
To create a mipmap chain, specify the DDSCAPS_MIPMAP and DDSCAPS_COMPLEX flags in the DDSURFACEDESC2 structure passed to the IDirectDraw7::CreateSurface method. Because all mipmaps are also textures, the DDSCAPS_TEXTURE flag must also be specified.
The following example demonstrates how your application can use the IDirectDraw7::CreateSurface method to build a chain of five mipmap levels of sizes 256×256, 128×128, 64×64, 32×32, and 16×16.
// This code fragment assumes that the variable lpDD is a // valid pointer to a DirectDraw interface. DDSURFACEDESC2 ddsd; LPDIRECTDRAWSURFACE7 lpDDMipMap; ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_MIPMAPCOUNT; ddsd.dwMipMapCount = 5; ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_MIPMAP | DDSCAPS_COMPLEX; ddsd.dwWidth = 256UL; ddsd.dwHeight = 256UL; ddres = lpDD->CreateSurface(&ddsd, &lpDDMipMap); if (FAILED(ddres)) . . .
You can omit the number of mipmap levels, in which case the IDirectDraw7::CreateSurface method will create a chain of surfaces, each a power of two smaller than the previous one, down to the smallest possible size. It is also possible to omit the width and height, in which case IDirectDraw7::CreateSurface will create the number of levels you specify, with a minimum level size of 1×1.
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 2×1. If you explicitly specify dimensions in the dwWidth and dwHeight members, you should be aware of some restrictions. Namely, you cannot request a number of mipmap levels in dwMipMapCount that would cause either the width or height of any mipmap in the chain to be smaller than 1. Take the very simple case of a 4×2 top-level mipmap surface: the maximum value allowed for dwMipMapCount here is 2: the top-level dimensions are 4×2, and the dimensions for the second level 2×1. A value larger than 2 in dwMipMapCount would result in a fractional value in the height of the second-level mipmap, and is therefore disallowed.
To create a mipmap chain, specify the DDSCAPS_MIPMAP and DDSCAPS_COMPLEX flags in the DDSURFACEDESC2 type passed to the DirectDraw7.CreateSurface method. Because all mipmaps are also textures, the DDSCAPS_TEXTURE flag must also be specified.
The following example demonstrates how your application can use the DirectDraw7.CreateSurface method to build a chain of five mipmap levels of sizes 256×256, 128×128, 64×64, 32×32, and 16×16.
' This code fragment assumes that the variable DD contains ' a valid reference to a DirectDraw7 object. On Local Error Resume Next Dim ddsd As DDSURFACEDESC2 Dim DDMipMap As DirectDrawSurface7 ddsd.lFlags = DDSD_CAPS Or DDSD_MIPMAPCOUNT ddsd.lMipMapCount = 5 ddsd.ddsCaps.lCaps = DDSCAPS_TEXTURE Or DDSCAPS_MIPMAP Or DDSCAPS_COMPLEX ddsd.lWidth = 256 ddsd.lHeight = 256 Set DDMipMap = DD.CreateSurface(ddsd) If Err.Number <> DD_OK Then ' Code to handle error goes here End If
You can omit the number of mipmap levels, in which case the DirectDraw7.CreateSurface method will create a chain of surfaces, each a power of two smaller than the previous one, down to the smallest possible size. It is also possible to omit the width and height, in which case DirectDraw7.CreateSurface will create the number of levels you specify, with a minimum level size of 1×1.
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 2×1. If you explicitly specify dimensions in the lWidth and lHeight members, you should be aware of some restrictions. Namely, you cannot request a number of mipmap levels in lMipMapCount that would cause either the width or height of any mipmap in the chain to be smaller than 1. Take the very simple case of a 4×2 top-level mipmap surface: the maximum value allowed for lMipMapCount here is 2: the top-level dimensions are 4×2, and the dimensions for the second level 2×1. A value larger than 2 in lMipMapCount would result in a fractional value in the height of the second-level mipmap, and is therefore disallowed.