DXGI可以获得显存的精确大小。但因为DXGI是基于WDDM,因此要先判断当前系统的显示驱动模型是不是WDDM。
HasWDDMDriver()
{
LPDIRECT3DCREATE9EX pD3D9Create9Ex = NULL;
HMODULE hD3D9 = NULL;
hD3D9 = LoadLibrary( L"d3d9.dll" );
if ( NULL == hD3D9 ) {
return false;
}
//
/* Try to create IDirect3D9Ex interface (also known as a DX9L interface). This interface can only be created if the driver is a WDDM driver.
*/
//
pD3D9Create9Ex = (LPDIRECT3DCREATE9EX) GetProcAddress( hD3D9, "Direct3DCreate9Ex" );
return pD3D9Create9Ex != NULL;
}
{
LPDIRECT3DCREATE9EX pD3D9Create9Ex = NULL;
HMODULE hD3D9 = NULL;
hD3D9 = LoadLibrary( L"d3d9.dll" );
if ( NULL == hD3D9 ) {
return false;
}
//
/* Try to create IDirect3D9Ex interface (also known as a DX9L interface). This interface can only be created if the driver is a WDDM driver.
*/
//
pD3D9Create9Ex = (LPDIRECT3DCREATE9EX) GetProcAddress( hD3D9, "Direct3DCreate9Ex" );
return pD3D9Create9Ex != NULL;
}
然后通过访问Adapter的GetDesc得到一个DXGI_ADAPTER_DESC结构体,其内保存了显卡信息。
IDXGIDevice * pDXGIDevice;
hr = g_pd3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);
IDXGIAdapter * pDXGIAdapter;
pDXGIDevice->GetAdapter(&pDXGIAdapter);
DXGI_ADAPTER_DESC adapterDesc;
pDXGIAdapter->GetDesc(&adapterDesc);
hr = g_pd3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice);
IDXGIAdapter * pDXGIAdapter;
pDXGIDevice->GetAdapter(&pDXGIAdapter);
DXGI_ADAPTER_DESC adapterDesc;
pDXGIAdapter->GetDesc(&adapterDesc);