开发者

C++ function to do DxDiag "Direct3D Acceleration" detection

Microsoft DxDiag can detect whether a system has "Direct3D Acceleration".

If the system has not the capability, DxDiag will write "Direct3D Acceleration not available" and will write in the console "Direct3D functionality not available. You should verify that the driver is a final version from the hardware manufacturer."

I would like the same with a C++ function.

I made some tests and the following function seems to do the job.

Any other better idea?

Thank you.

Alessandro

#include <ddraw.h>
#include <atlbase.h>

bool has3D()
{
   CComPtr< IDirectDraw > dd;
   HRESULT hr = ::DirectDrawCreate( 0, &dd, 0 );
   if ( hr != DD_OK ) return false;

   DDCAPS hel_caps, hw_caps;
   ::ZeroMemory( &hel_caps, sizeof( DDCAPS ) );
   ::ZeroMemory( &hw_caps, sizeof( DDCAPS ) );
   hw_caps.dwSi开发者_开发技巧ze = sizeof( DDCAPS );
   hel_caps.dwSize = sizeof( DDCAPS );
   hr = dd->GetCaps( &hw_caps, &hel_caps );
   if ( hr != DD_OK ) return false;

   return (hw_caps.dwCaps & DDCAPS_3D) && (hel_caps.dwCaps & DDCAPS_3D);
}


As DirectDraw is now deprecated, it's maybe preferable to use the Direct3D functions.

If the purpose is to detect if 3D acceleration is available for an application, I would initialize Direct3D and then check if the HAL Device Type is available.

LPDIRECT3D9 d3d = Direct3DCreate9( D3D_SDK_VERSION );

D3DCAPS9 caps;

if ( FAILED(d3d->GetDeviceCaps(D3DADAPTER_DEFAULT , D3DDEVTYPE_HAL, &caps)) )
{
    return false;    
}

You can check the validity of this code by forcing the software rendering in the DirectX Control Panel by checking the "Software only" checkbox in the Direct3D tab.
Test the code with and without the checkbox checked and see if it suits your needs.


You can access DX Diag via IDXDiagContainer and IDXDiagProvider

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜