| 207 | |
| 208 | |
| 209 | static void init_d3d11(HWND window_handle, int ww, int wh) { |
| 210 | |
| 211 | Graphics *ctx = &G->graphics; |
| 212 | |
| 213 | RECT rect; |
| 214 | GetClientRect(hwnd, &rect); |
| 215 | ww = rect.right - rect.left; |
| 216 | wh = rect.bottom - rect.top; |
| 217 | |
| 218 | D3D_FEATURE_LEVEL feature_levels[] = { |
| 219 | D3D_FEATURE_LEVEL_11_1, |
| 220 | D3D_FEATURE_LEVEL_11_0, |
| 221 | D3D_FEATURE_LEVEL_10_1, |
| 222 | D3D_FEATURE_LEVEL_10_0, |
| 223 | }; |
| 224 | ID3D11Device* base_device; |
| 225 | ID3D11DeviceContext* base_device_ctx; |
| 226 | UINT createDeviceFlags = 0; |
| 227 | #if DEBUG_MODE |
| 228 | createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; |
| 229 | #endif |
| 230 | |
| 231 | D3D11CreateDevice( |
| 232 | nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, createDeviceFlags, |
| 233 | feature_levels, array_size(feature_levels), |
| 234 | D3D11_SDK_VERSION, &base_device, |
| 235 | nullptr, &base_device_ctx |
| 236 | ); |
| 237 | |
| 238 | base_device->QueryInterface(__uuidof(ID3D11Device1), (void**)&ctx->device); |
| 239 | base_device_ctx->QueryInterface(__uuidof(ID3D11DeviceContext1), (void**)&ctx->device_ctx); |
| 240 | |
| 241 | IDXGIDevice1* dxgi_device; |
| 242 | (ctx->device)->QueryInterface(__uuidof(IDXGIDevice1), (void**)&dxgi_device); |
| 243 | IDXGIAdapter* dxgi_adapter; |
| 244 | dxgi_device->GetAdapter(&dxgi_adapter); |
| 245 | IDXGIFactory2* dxgi_factory; |
| 246 | dxgi_adapter->GetParent(__uuidof(IDXGIFactory2), (void**)&dxgi_factory); |
| 247 | |
| 248 | DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = { 0 }; |
| 249 | swap_chain_desc.Width = 0; |
| 250 | swap_chain_desc.Height = 0; |
| 251 | swap_chain_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; |
| 252 | swap_chain_desc.Stereo = FALSE; |
| 253 | swap_chain_desc.SampleDesc.Count = 1; |
| 254 | swap_chain_desc.SampleDesc.Quality = 0; |
| 255 | swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; |
| 256 | swap_chain_desc.BufferCount = 2; |
| 257 | swap_chain_desc.Scaling = DXGI_SCALING_STRETCH; |
| 258 | swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; |
| 259 | swap_chain_desc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED; |
| 260 | swap_chain_desc.Flags = 0; |
| 261 | dxgi_factory->CreateSwapChainForHwnd(ctx->device, window_handle, &swap_chain_desc, nullptr, nullptr, &ctx->swap_chain); |
| 262 | ctx->swap_chain->GetDesc1(&swap_chain_desc); |
| 263 | |
| 264 | D3D11_TEXTURE2D_DESC frame_buffer_desc = { 0 }; |
| 265 | frame_buffer_desc.Width = ww ; |
| 266 | frame_buffer_desc.Height = wh ; |
no test coverage detected