Home | History | Annotate | Download | only in checks
      1 #include <windows.h>
      2 
      3 #include <d3d11.h>
      4 #pragma comment (lib, "d3d11.lib")
      5 
      6 HINSTANCE g_hInst = NULL;
      7 D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
      8 D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
      9 ID3D11Device* g_pd3dDevice = NULL;
     10 ID3D11DeviceContext* g_pImmediateContext = NULL;
     11 IDXGISwapChain* g_pSwapChain = NULL;
     12 
     13 static HRESULT InitDevice()
     14 {
     15     HRESULT hr = S_OK;
     16 
     17     UINT width = 640;
     18     UINT height = 480;
     19 
     20     UINT createDeviceFlags = 0;
     21 
     22     D3D_DRIVER_TYPE driverTypes[] =
     23     {
     24         D3D_DRIVER_TYPE_HARDWARE,
     25         D3D_DRIVER_TYPE_WARP,
     26         D3D_DRIVER_TYPE_REFERENCE,
     27     };
     28     UINT numDriverTypes = ARRAYSIZE(driverTypes);
     29 
     30     D3D_FEATURE_LEVEL featureLevels[] =
     31     {
     32         D3D_FEATURE_LEVEL_11_0,
     33         D3D_FEATURE_LEVEL_10_1,
     34         D3D_FEATURE_LEVEL_10_0,
     35     };
     36     UINT numFeatureLevels = ARRAYSIZE(featureLevels);
     37 
     38     DXGI_SWAP_CHAIN_DESC sd;
     39     ZeroMemory( &sd, sizeof( sd ) );
     40     sd.BufferCount = 1;
     41     sd.BufferDesc.Width = width;
     42     sd.BufferDesc.Height = height;
     43     sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
     44     sd.BufferDesc.RefreshRate.Numerator = 60;
     45     sd.BufferDesc.RefreshRate.Denominator = 1;
     46     sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
     47     sd.OutputWindow = NULL; //g_hWnd;
     48     sd.SampleDesc.Count = 1;
     49     sd.SampleDesc.Quality = 0;
     50     sd.Windowed = TRUE;
     51 
     52     for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++)
     53     {
     54         g_driverType = driverTypes[driverTypeIndex];
     55         hr = D3D11CreateDeviceAndSwapChain(NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels,
     56                 D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext);
     57         if (SUCCEEDED(hr))
     58             break;
     59     }
     60     if (FAILED(hr))
     61         return hr;
     62 
     63     return S_OK;
     64 }
     65 
     66 int main(int /*argc*/, char** /*argv*/)
     67 {
     68     InitDevice();
     69     return 0;
     70 }
     71