Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Device Enumeration Basics


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Wargrave   Members   -  Reputation: 108

Like
0Likes
Like

Posted 28 February 2006 - 11:26 PM

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.

Sponsor:

#2 jollyjeffers   Crossbones+   -  Reputation: 1542

Like
0Likes
Like

Posted 28 February 2006 - 11:35 PM

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>

#3 Wargrave   Members   -  Reputation: 108

Like
0Likes
Like

Posted 21 March 2006 - 08:26 AM

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.

#4 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

Posted 21 March 2006 - 08:31 AM

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.

#5 Demirug   Members   -  Reputation: 884

Like
0Likes
Like

Posted 21 March 2006 - 08:35 AM

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

#6 Wargrave   Members   -  Reputation: 108

Like
0Likes
Like

Posted 23 March 2006 - 06:53 AM

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]

#7 Wargrave   Members   -  Reputation: 108

Like
0Likes
Like

Posted 25 March 2006 - 07:36 AM

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

#8 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

Posted 25 March 2006 - 09:24 AM

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[i]);
for(UINT j=0; j<nCount; ++j)
{
if(SUCCEEDED(pD3D->EnumAdapterModes(D3DADAPTER_DEFAULT,fmts[i],j,&theMode.theMode)))
{
theMode.fmt = fmts[i];
theMode.nBits = nBits[i];
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.

#9 Wargrave   Members   -  Reputation: 108

Like
0Likes
Like

Posted 26 March 2006 - 10:30 AM

Hi!

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS