Sign in to follow this  
thechistoso

How do I check for Direct3D support?

Recommended Posts

I need to see if Direct3D is viable for output (Direct3D 9 to be exact) and then gracefully downgrade to DirectDraw if it's not. Both the DirectDraw and Direct3D portions are already coded and working fine. I'm just wiring up switching between the 2 automatically (if possible).

What's the best way to determine if there's full Direct3D support?

I'm doing this in C and right now I have the following:

static gboolean
is_direct3d_supported ()
{
HRESULT hr;
LPDIRECT3D9 d3d;
D3DDISPLAYMODE d3ddm;
LPDIRECT3DDEVICE9 d3ddev;
D3DPRESENT_PARAMETERS d3dpp;

d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (!d3d) {
return FALSE;
}

if (FAILED(IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm))) {
/* Prevent memory leak */
IDirect3D9_Release(d3d);
return FALSE;
}

ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.BackBufferWidth = 1;
d3dpp.BackBufferHeight = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; //D3DPRESENT_INTERVAL_IMMEDIATE;

if (FAILED(hr = IDirect3D9_CreateDevice(
d3d,
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
GetDesktopWindow(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE,
&d3dpp,
&d3ddev
))) {
/* Prevent memory leak */
IDirect3D9_Release(d3d);
return FALSE;
}

/* Prevent memory leak */
IDirect3DDevice9_Release(d3ddev);
IDirect3D9_Release(d3d);

return TRUE;
}

If I remember correctly, creating a device in a non-windows msg loop thread (and not when handling WM_CREATE) isn't a good idea. I have another variant where I comment out the CreateDevice() call. Would that be sufficient? I have yet another variant where I create my own window instead of using GetDesktopWindow(). Would that be better?

Also, how could I go about testing this? Is there a way to fake out the system and make it believe that Direct3D isn't functioning/working?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this