| 73 | } |
| 74 | |
| 75 | void DeviceManager::Initialize(HWND outputWindow) |
| 76 | { |
| 77 | CheckForSuitableOutput(); |
| 78 | |
| 79 | DXGI_SWAP_CHAIN_DESC desc; |
| 80 | ZeroMemory(&desc, sizeof(DXGI_SWAP_CHAIN_DESC)); |
| 81 | |
| 82 | if(fullScreen) |
| 83 | { |
| 84 | PrepareFullScreenSettings(); |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | refreshRate.Numerator = 60; |
| 89 | refreshRate.Denominator = 1; |
| 90 | } |
| 91 | |
| 92 | desc.BufferCount = 2; |
| 93 | desc.BufferDesc.Format = backBufferFormat; |
| 94 | desc.BufferDesc.Width = backBufferWidth; |
| 95 | desc.BufferDesc.Height = backBufferHeight; |
| 96 | desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; |
| 97 | desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; |
| 98 | desc.BufferDesc.RefreshRate = refreshRate; |
| 99 | desc.SampleDesc.Count = msCount; |
| 100 | desc.SampleDesc.Quality = msQuality; |
| 101 | desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; |
| 102 | desc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; |
| 103 | desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; |
| 104 | desc.OutputWindow = outputWindow; |
| 105 | desc.Windowed = !fullScreen; |
| 106 | |
| 107 | uint32 flags = D3D11_CREATE_DEVICE_SINGLETHREADED; |
| 108 | #if UseDebugDevice_ |
| 109 | flags |= D3D11_CREATE_DEVICE_DEBUG; |
| 110 | #endif |
| 111 | |
| 112 | DXCall(D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags, |
| 113 | NULL, 0, D3D11_SDK_VERSION, &desc, &swapChain, |
| 114 | &device, NULL, &immediateContext)); |
| 115 | |
| 116 | featureLevel = device->GetFeatureLevel(); |
| 117 | |
| 118 | if(featureLevel < minFeatureLevel) |
| 119 | { |
| 120 | wstring majorLevel = ToString<int>(minFeatureLevel >> 12); |
| 121 | wstring minorLevel = ToString<int>((minFeatureLevel >> 8) & 0xF); |
| 122 | throw Exception(L"The device doesn't support the minimum feature level required to run this sample (DX" + majorLevel + L"." + minorLevel + L")"); |
| 123 | } |
| 124 | |
| 125 | if(BreakOnDXError_ && D3DPERF_GetStatus() == 0) |
| 126 | { |
| 127 | ID3D11InfoQueuePtr infoQueue; |
| 128 | DXCall(device->QueryInterface(__uuidof(ID3D11InfoQueue), reinterpret_cast<void**>(&infoQueue))); |
| 129 | infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, TRUE); |
| 130 | infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, TRUE); |
| 131 | } |
| 132 | |