Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
97 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

by Nathan Davies from Alamar's Domain

  Contents

 Introduction
 Display Drivers
 Display Modes
 D3D Devices
 Cleanup and
 Conclusion


 Printable version

 


The Basics of Enumeration and the Structures Involved

The purpose of this article is to explain a method of enumeration in DirectX 7. If you are developing a Direct Draw application, the Driver and Display Mode enumeration areas are relevant. If you are developing a Direct 3D application, all areas are relevant.

A Driver can be thought of as a video card. Enumerating the Drivers is equivalent to determining what video cards are installed. In a system with one video card, enumerating the drivers will reveal only one option, usually named "Primary Display Driver". If you have more than one video card, n + 1 drivers will be enumerated, where n is the number of video cards installed(If you have 2 video cards, 3 drivers will be enumerated). The reason n + 1 Drivers are enumerated is because the Primary Display Driver is always enumerated first. This is the Driver that your start menu will be located on. The Primary Display Driver will then be enumerated a second time, but with the manufacturer's identification made available. Each of the drivers enumerated will be identified by a descriptive name, as well as a GUID(Global Unique Identifier). The GUID is the value you later use when creating the DirectDraw object.

A Display Mode is simply a combination of width, height, depth and other more advanced information. When you enumerate the Display Modes, you will be given a list of Resolutions that you can save for later use.

A Device is a way for Direct 3D to determine how to render primitives. On a Driver that supports Hardware 3D acceleration, you will usually enumerate a minimum of 2 Devices. The first is the Software RGB Rasterizer which DirectX describes as RGB Emulation. The second Device is the Direct3D HAL(Hardware Abstraction Layer), or simply, the 3D accelerated card installed. Each Device also has a GUID that can be saved and later used when Creating a Device.

Each type of enumeration is accomplished by calling an Enumeration function(such as DirectDrawEnumerateEx) and passing the pointer of a callback function. The callback function is called by the Enumeration function once for every object enumerated. For example:

// Callback Declaration HRESULT CALLBACK EnumDisplayDrivers( GUID FAR* pGuid, LPSTR Desc, LPSTR Name, LPVOID Context, HMONITOR hMonitor ); // Enumeration Function DirectDrawEnumerateEx(( LPDDENUMCALLBACKEX )EnumDisplayDrivers, NULL, DDENUM_ATTACHEDSECONDARYDEVICES | DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_NONDISPLAYDEVICES );

In this example, calling DirectDrawEnumerateEx would invoke DirectX to call EnumDisplayDrivers once for each Driver enumerated.

For this article, I have decided to create some structures to hold the various enumeration information and linked the structures together in a singly linked list. The DisplayDriver structures is as follows:

struct D3DDeviceList; struct DisplayModeList; struct DisplayDriver { DisplayDriver* Next; GUID Guid; char* Description; D3DDevice* D3DDeviceList; DisplayMode* DisplayModeList; }; DisplayDriver* DisplayDriverList;

This structure can be used to save the Driver's GUID and Description. DisplayDriverList is declared as a global variable to access the List for Display Drivers. Since Display Modes and Devices are dependant on the Driver, their Lists are included inside the Driver structure.

D3Device and DisplayMode are defined in a similiar way:

struct D3DDevice { D3DDevice* Next; GUID Guid; char* Name; BOOL IsHW; }; struct DisplayMode { DisplayMode* Next; int Width; int Height; int Depth; };



Next : Display Drivers