?/TD> |
Microsoft DirectX 9.0 |
Before your application creates a rendering device, it can determine if the device supports texturing from compressed texture surfaces by calling the IDirect3D9::CheckDeviceFormat method. This method determines whether a surface format can be used as a texture on a device representing the adapter.
To test the adapter, specify any pixel format that uses the DXT1, DXT2, DXT3, DXT4, or DXT5 four-character codes (FOURCCs). If IDirect3D9::CheckDeviceFormat returns D3D_OK, the device can create texture directly from a compressed texture surface that uses that format. If so, you can use compressed texture surfaces directly with Microsoft?Direct3D?by calling the IDirect3DDevice9::SetTexture method. The following code example shows how to determine if the adapter supports a compressed texture format.
BOOL IsCompressedTextureFormatOk( D3DFORMAT TextureFormat, D3DFORMAT AdapterFormat ) { HRESULT hr = pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, AdapterFormat, 0, D3DRTYPE_TEXTURE, TextureFormat); return SUCCEEDED( hr ); }
If the device does not support texturing from compressed texture surfaces, you can still store texture data in a compressed format surface, but you must convert any compressed textures to a supported format before they can be used for texturing.
After creating a device that supports a compressed texture format on the adapter, you can create a compressed texture resource. Call IDirect3DDevice9::CreateTexture and specify a compressed texture format for the Format parameter.
Before loading an image into a texture object, retrieve a pointer to the texture surface by calling the IDirect3DTexture9::GetSurfaceLevel method.
Now you can use any D3DXLoadSurfacexxx function to load an image to the surface that was retrieved by using IDirect3DTexture9::GetSurfaceLevel. These functions handle conversion to and from compressed texture formats.
You can create and convert compressed texture (DDS) files using the DXTex Tool supplied with the software development kit (SDK).
The advantage of this behavior is that an application can copy the contents of a compressed surface to a file without calculating how much storage is required for a surface of a particular width and height in the specific format.
The following table shows the five types of compressed textures. For more information about how the data is stored, see Compressed Texture Formats. You only need this information if you are writing your own compression routines.
FOURCC | Description | Alpha premultiplied? |
---|---|---|
DXT1 | Opaque/1-bit alpha | N/A |
DXT2 | Explicit alpha | Yes |
DXT3 | Explicit alpha | No |
DXT4 | Interpolated alpha | Yes |
DXT5 | Interpolated alpha | No |
?/p>
As with compressing a texture surface, decompressing a compressed texture is performed through Direct3D copying services.
To copy a compressed texture surface to a uncompressed texture surface, use the function D3DXLoadSurfaceFromSurface. This functions handles compression to and from compressed and uncompressed surfaces.