Device Enumeration Basics

Started by
7 comments, last by Wargrave 18 years ago
Hello folks, I work on a small game which has to be able to list the device capabilities. I want the player to be able to choose different screen resolutions and refresh rates for instance. I've been searching for info for a while, looked in some books. But I don't know where to begin. Has anybody seen any good tutorials I can look at? Where do I begin? Thanks, Wargrave.
Advertisement
You need to specify which version of the API and via what language you're using it [wink]

We've got 4 versions of Direct3D/X kicking around, accessible in a variety of different ways. I'm going to assume Direct3D9 and C/C++:

Create an IDirect3D9 object as usual,

Retrieve IDirect3D9::GetAdapterCount(), this represents how many adapters in your system. Usually this will only be one, but it is quite possible for people to have more in the case of multimon setups.

For each adapter:

Call IDirect3D9::GetAdapterIdentifier() - this allows you to get some "friendly" information about it. Excellent for putting in your GUI so the user knows what you're referring to (e.g. have "GeForce 6600" in the device list).

Also use IDirect3D9::GetDeviceCaps() to retrieve the device caps. Of particular interest is probably the shader model(s) supported by the device.

Next use IDirect3D9::GetAdapterModeCount() to determine how many display modes are supported. This can be quite a large list - it'll include all the resolutions and colour depths supported.

Iteratate through the actual information using IDirect3D9::EnumAdapterModes() to retrieve the information for that mode.

That should get you rolling [smile]

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Hi again!

Thanks for the latest reply. It has helped me a lot. But I cannot find what is wrong with the following code:

#include <iostream>
#include <windows.h>
#include "d3d9.h"
#include "d3dx9.h"
using namespace std;

int main()
{
LPDIRECT3D9 g_pD3D = NULL;
if( NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
return E_FAIL;

UINT iAmountDevices = g_pD3D->GetAdapterCount();
D3DADAPTER_IDENTIFIER9* psAdapterIdentifier=new(D3DADAPTER_IDENTIFIER9[iAmountDevices]);

for(UINT n=0;n++<iAmountDevices;)
{
g_pD3D->GetAdapterIdentifier(n, 0, psAdapterIdentifier[n]);
char DeviceName[20];
cout << psAdapterIdentifier.DeviceName;
}
delete(psAdapterIdentifier);


system("PAUSE");
return 0;
}

And the compiler says:

Compiling...
EggEnum.cpp
c:\Documents and Settings\Eddie\Mina dokument\Visual Studio Projects\EggEnum\EggEnum.cpp(21) : error C2664: 'IDirect3D9::GetAdapterIdentifier' : cannot convert parameter 3 from 'D3DADAPTER_IDENTIFIER9' to 'D3DADAPTER_IDENTIFIER9 *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
c:\Documents and Settings\Eddie\Mina dokument\Visual Studio Projects\EggEnum\EggEnum.cpp(23) : error C2228: left of '.DeviceName' must have class/struct/union type
type is 'D3DADAPTER_IDENTIFIER9 *'
did you intend to use '->' instead?

Thanks again,
Wargrave.
This part needs editing:
for(UINT n=0;n++<iAmountDevices;){   // Use &psAdapterIdentifier here:   g_pD3D->GetAdapterIdentifier(n, 0, &psAdapterIdentifier[n]);   // Add [n] here:   cout << psAdapterIdentifier[n].DeviceName;}delete(psAdapterIdentifier);

For future reference, it's best to post code in [ source ] and [ /source ] tags to format the code a bit more nicely.
GetAdapterIdentifier wants a pointer to a D3DADAPTER_IDENTIFIER9 structure.

As you have created an array of D3DADAPTER_IDENTIFIER9 structures you need to use an index to select the structure you want.

int main(){LPDIRECT3D9 g_pD3D = NULL; if( NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION))) return E_FAIL; UINT iAmountDevices = g_pD3D->GetAdapterCount();D3DADAPTER_IDENTIFIER9* psAdapterIdentifier=new(D3DADAPTER_IDENTIFIER9[iAmountDevices]);for(UINT n=0;n++<iAmountDevices;){	g_pD3D->GetAdapterIdentifier(n, 0, &psAdapterIdentifier[n]);	char DeviceName[20];	cout << psAdapterIdentifier[n].DeviceName;}delete(psAdapterIdentifier);system("PAUSE");return 0;}


EDIT: Evil Steve was faster
Hello again!
And thank you very much for the latest replies.

I'd like to ask you for help. I sit here hour after hour compiling and looking for faults that I can't seem to find. What I'm going to ask, I'm only asking because I'm getting really desperate and because the device enumeration part of the project is taking too much time from the whole project. I also know that it probably takes less than half an hour for you guys.

My code so far is above and I need help with the following (this is the quote from the first guy who helped me):

"For each adapter:

Call IDirect3D9::GetAdapterIdentifier() - this allows you to get some "friendly" information about it. Excellent for putting in your GUI so the user knows what you're referring to (e.g. have "GeForce 6600" in the device list).

Also use IDirect3D9::GetDeviceCaps() to retrieve the device caps. Of particular interest is probably the shader model(s) supported by the device.

Next use IDirect3D9::GetAdapterModeCount() to determine how many display modes are supported. This can be quite a large list - it'll include all the resolutions and colour depths supported.

Iteratate through the actual information using IDirect3D9::EnumAdapterModes() to retrieve the information for that mode."

I would appreciate your help extremely much.
Thanks,
Wargrave.

[Edited by - Wargrave on March 25, 2006 1:53:55 PM]
Hi,

Is there really no one that could help me with what I've written above. It'd be of enormous help for me. I had to go on with the sound core because my project time is limited and the device enumeration part was taking me very, very long time.

Thanks,
Wargrave
If you just want to see all the resolutions for one card, you can do this:
struct ScreenMode{   D3DDISPLAYMODE theMode;   D3DFORMAT      fmt;   int            nBits;}void GetModes(std::vector& vModes, IDirect3D9* pD3D){   const D3DFORMAT fmts[] =    {      D3DFMT_A1R5G5B5,      D3DFMT_A2R10G10B10,      D3DFMT_A8R8G8B8,      D3DFMT_R5G6B5,      D3DFMT_X1R5G5B5,      D3DFMT_X8R8G8B8,   };   const int nBits[] = {16, 32, 32, 16, 16, 32};   const int nNumFormats = 6;   ScreenMode theMode;   vModes.clear();   for(int i=0; i<nNumFormats; ++i)   {      UINT nCount = pD3D->GetAdapterModeCount(D3DADAPTER_DEFAULT,fmts);      for(UINT j=0; j<nCount; ++j)      {         if(SUCCEEDED(pD3D->EnumAdapterModes(D3DADAPTER_DEFAULT,fmts,j,&theMode.theMode)))         {            theMode.fmt = fmts;            theMode.nBits = nBits;            vModes.push_back(theMode)         }      }   }}

That function should fill a vector with all the screen modes supported by the first card on the system. If you want to support more than one card, you need to change D3DADAPTER_DEFAULT to the index of the card you want to check.

Also node that the code is untested, so there may be some bugs in it.
Hi!

Thanks a lot! The code has helped me very much.

This topic is closed to new replies.

Advertisement