Platform SDK: DirectX

Step 1.3: Enumerate the Texture Formats

[C++]

This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.

[Visual Basic]

Before you enumerate your textures, you need to declare a Direct3DEnumPixelFormats object:

    Dim TextureEnum As Direct3DEnumPixelFormats

Then, you can call the Direct3DDevice7.GetTextureFormatsEnum method on the rendering device to return a Direct3DEnumPixelFormats object:

    Set TextureEnum = g_d3dDevice.GetTextureFormatsEnum()

Now, you can call methods on the Direct3DEnumPixelFormats object, TextureEnum, to retrieve information about the pixel formats that the device supports for textures.

In the following code excerpt from the Texture application, the loop is looking for a device-supported texture pixel format. Specifically, the code looks for a 16-bit texture. Note that all other formats, such as alpha textures, are ignored:

    For i = 1 To TextureEnum.GetCount()
        bIsFound = True
        Call TextureEnum.GetItem(i, ddsd.ddpfPixelFormat)
        
        With ddsd.ddpfPixelFormat
            ' Skip unusual modes.
            If .lFlags And (DDPF_LUMINANCE Or DDPF_BUMPLUMINANCE Or DDPF_BUMPDUDV) Then bIsFound = False
            
            ' Skip any FourCC formats.
            If .lFourCC <> 0 Then bIsFound = False
            
            'Skip alpha modes.
            If .lFlags And DDPF_ALPHAPIXELS Then bIsFound = False
            
            'We only want 16-bit formats, so skip all others.
            If .lRGBBitCount <> 16 Then bIsFound = False
        End With
        
        If bIsFound Then Exit For
        
    Next i

Now that a texture format supported by the rendering device has been selected from the enumeration of texture formats, TextureEnum, you can create a surface for the texture. This step is detailed in Step 1.4: Create a New Surface for the Texture.