CR的代码文本

all for learning about the world
  订阅 订阅  :: 管理

使用DXGI获得精确的显存大小

Posted on 2012-06-14 09:50  mumuliang  阅读(1342)  评论(0编辑  收藏  举报

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;
}

 

然后通过访问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);