Platform SDK: DirectX

Enumerating Direct3DX Devices

This section details the components that comprise a particular display device and the functionality that the Direct3DX utility library provides for enumerating devices on a system.

A graphics configuration (display device) for a Direct3D application using the Direct3DX utility library may consist of the following components:

Given the preceding components, it is possible for a wide range of display options to be available on a particular system. For example, there may be several monitors on a system; the 2-D graphics device may or may not be using video acceleration; and the 3-D graphics device could be using any number of devices: RAMP, RGB, REFERENCE, HW, or TL HW.

For more information on device types, see the Direct3D Device Types topic in the Direct3D Immediate Mode documentation.

In most cases, not all of the display option combinations will be supported by the system. Typically, a 3-D card will be connected to a particular monitor. Also, choosing emulation for the 2-D engine may eliminate hardware choices for the 3-D engine. In order to resolve these conflicts and determine valid hardware configurations, your application should go through the process of enumerating the devices on the system.

As an example, the following code determines how many DirectDraw devices there are on the system, and for each DirectDraw device selects its highest level of hardware acceleration. The result is a list of indices into the device list that corresponds to the chosen device.

    dwNumDevices = D3DXGetDeviceCount();
 
    hr = D3DXGetDeviceDescription( 0, &pDeviceList[0] );
 
    GUID guidLastUniqueDeviceId = pDeviceList[0].ddDeviceID;
    cNumDDObjs = 1;
    indexOfChosenD3DXDevices[0] = 0; // start by picking the first device
 
    for( i = 1; i < dwNumDevices; i++ )
    {
        hr = D3DXGetDeviceDescription( i, &pDeviceList[i] );
 
        if( pDeviceList[i].ddDeviceID != guidLastUniqueDeviceId )
        {
            guidLastUniqueDeviceId = pDeviceList[i].ddDeviceID;
            cNumDDObjs++;
            indexOfChosenD3DXDevices[cNumDDObjs-1] = i;
        }
        else
        {
            int currIndex = indexOfChosenD3DXDevices[cNumDDObjs-1];
            if( pDeviceList[i].hwLevel > pDeviceList[currIndex].hwLevel )
            {
                indexOfChosenD3DXDevices[cNumDDObjs-1] = i;
            }
        }
    }

In the preceding example, the D3DXGetDeviceCount function is used to obtain the number of devices available for enumeration on the system. The D3DXGetDeviceDescription function is used to obtain a description of an enumerated device, identifying the device by its index value.

Note  When you use the Direct3DX utility library your application does not have to manually enumerate devices; since reasonable defaults are built-into the Direct3DX context object.

Both the D3DXCreateContext and D3DXCreateContextEx functions supply parameters to allow for default device creation. However, sophisticated games and applications may want to expose the full device enumeration, so that users will be able to customize their own graphics experience.