MCPcopy Create free account
hub / github.com/DavidColson/Polybox / GraphicsBackendInit

Function GraphicsBackendInit

source/graphics_platform_d3d11.cpp:16–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14// ***********************************************************************
15
16bool GraphicsBackendInit(SDL_Window* pWindow, int width, int height) {
17 winWidth = width;
18 winHeight = height;
19
20 SDL_SysWMinfo wmInfo;
21 SDL_VERSION(&wmInfo.version);
22 SDL_GetWindowWMInfo(pWindow, &wmInfo);
23 HWND hwnd = wmInfo.info.win.window;
24
25 // Create DirectX device
26 DXGI_SWAP_CHAIN_DESC scd = {0};
27 scd.BufferCount = 1;
28 scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29 scd.BufferDesc.RefreshRate.Numerator = 60;
30 scd.BufferDesc.RefreshRate.Denominator = 1;
31 scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
32 scd.OutputWindow = hwnd;
33 scd.SampleDesc.Count = 1;
34 scd.SampleDesc.Quality = 0;
35 scd.Windowed = true;
36
37 if (D3D11CreateDeviceAndSwapChain(
38 NULL,
39 D3D_DRIVER_TYPE_HARDWARE,
40 NULL,
41 D3D11_CREATE_DEVICE_DEBUG,
42 NULL,
43 0,
44 D3D11_SDK_VERSION,
45 &scd,
46 &pSwapChain,
47 &pDevice,
48 NULL,
49 &pDeviceContext) != S_OK) {
50 return false;
51 }
52
53 // Create render target and depth stencil
54 {
55 pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pRenderTarget);
56 pDevice->CreateRenderTargetView((ID3D11Resource*)pRenderTarget, nullptr, &pRenderTargetView);
57
58 D3D11_TEXTURE2D_DESC dsd = {
59 .Width = (UINT)width,
60 .Height = (UINT)height,
61 .MipLevels = 1,
62 .ArraySize = 1,
63 .Format = DXGI_FORMAT_D24_UNORM_S8_UINT,
64 .SampleDesc = {.Count = (UINT)1, .Quality = (UINT)0 },
65 .Usage = D3D11_USAGE_DEFAULT,
66 .BindFlags = D3D11_BIND_DEPTH_STENCIL,
67 };
68 pDevice->CreateTexture2D(&dsd, nullptr, &pDepthStencil);
69 D3D11_DEPTH_STENCIL_VIEW_DESC dsvd = {
70 .Format = dsd.Format, .ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS
71 };
72 pDevice->CreateDepthStencilView((ID3D11Resource*)pDepthStencil, &dsvd, &pDepthStencilView);
73 }

Callers 1

GraphicsInitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected