Microsoft DxDiag 可以检测系统是否具有“Direct3D 加速”。
如果系统不具备此功能,DxDiag 将写入“Direct3D 加速不可用”,并在控制台中写入“Direct3D 功能不可用。您应验证该驱动程序是否为硬件制造商提供的最终版本。”
我希望 C++ 函数也能做到这一点。
我做了一些测试,下面的函数似乎可以完成这项工作。
还有其他更好的主意吗?
谢谢。
亚历山德罗
#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.dwSize = 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);
}
最佳答案
由于 DirectDraw 现已弃用,因此最好使用 Direct3D 函数。
如果目的是检测应用程序是否可以使用 3D 加速,我将初始化 Direct3D,然后检查 HAL Device Type 是否可用。可用。
LPDIRECT3D9 d3d = Direct3DCreate9( D3D_SDK_VERSION );
D3DCAPS9 caps;
if ( FAILED(d3d->GetDeviceCaps(D3DADAPTER_DEFAULT , D3DDEVTYPE_HAL, &caps)) )
{
return false;
}
您可以通过选中 Direct3D 选项卡中的“仅软件”复选框来强制 DirectX 控制面板中的软件渲染来检查此代码的有效性。
在选中和不选中复选框的情况下测试代码,看看它是否满足您的需求。
关于directx - C++函数进行DxDiag "Direct3D Acceleration"检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1901464/