1 // Dear ImGui: standalone example application for DirectX 12
2 // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
3 // Read online: https://github.com/ocornut/imgui/tree/master/docs
4
5 // Important: to compile on 32-bit systems, the DirectX12 backend requires code to be compiled with '#define ImTextureID ImU64'.
6 // This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*.
7 // This define is set in the example .vcxproj file and need to be replicated in your app or by adding it to your imconfig.h file.
8
9 #include "imgui.h"
10 #include "imgui_impl_win32.h"
11 #include "imgui_impl_dx12.h"
12 #include <d3d12.h>
13 #include <dxgi1_4.h>
14 #include <tchar.h>
15
16 #ifdef _DEBUG
17 #define DX12_ENABLE_DEBUG_LAYER
18 #endif
19
20 #ifdef DX12_ENABLE_DEBUG_LAYER
21 #include <dxgidebug.h>
22 #pragma comment(lib, "dxguid.lib")
23 #endif
24
25 struct FrameContext
26 {
27 ID3D12CommandAllocator* CommandAllocator;
28 UINT64 FenceValue;
29 };
30
31 // Data
32 static int const NUM_FRAMES_IN_FLIGHT = 3;
33 static FrameContext g_frameContext[NUM_FRAMES_IN_FLIGHT] = {};
34 static UINT g_frameIndex = 0;
35
36 static int const NUM_BACK_BUFFERS = 3;
37 static ID3D12Device* g_pd3dDevice = NULL;
38 static ID3D12DescriptorHeap* g_pd3dRtvDescHeap = NULL;
39 static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = NULL;
40 static ID3D12CommandQueue* g_pd3dCommandQueue = NULL;
41 static ID3D12GraphicsCommandList* g_pd3dCommandList = NULL;
42 static ID3D12Fence* g_fence = NULL;
43 static HANDLE g_fenceEvent = NULL;
44 static UINT64 g_fenceLastSignaledValue = 0;
45 static IDXGISwapChain3* g_pSwapChain = NULL;
46 static HANDLE g_hSwapChainWaitableObject = NULL;
47 static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS] = {};
48 static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
49
50 // Forward declarations of helper functions
51 bool CreateDeviceD3D(HWND hWnd);
52 void CleanupDeviceD3D();
53 void CreateRenderTarget();
54 void CleanupRenderTarget();
55 void WaitForLastSubmittedFrame();
56 FrameContext* WaitForNextFrameResources();
57 LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
58
59 // Main code
main(int,char **)60 int main(int, char**)
61 {
62 // Create application window
63 //ImGui_ImplWin32_EnableDpiAwareness();
64 WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
65 ::RegisterClassEx(&wc);
66 HWND hwnd = ::CreateWindow(wc.lpszClassName, _T("Dear ImGui DirectX12 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
67
68 // Initialize Direct3D
69 if (!CreateDeviceD3D(hwnd))
70 {
71 CleanupDeviceD3D();
72 ::UnregisterClass(wc.lpszClassName, wc.hInstance);
73 return 1;
74 }
75
76 // Show the window
77 ::ShowWindow(hwnd, SW_SHOWDEFAULT);
78 ::UpdateWindow(hwnd);
79
80 // Setup Dear ImGui context
81 IMGUI_CHECKVERSION();
82 ImGui::CreateContext();
83 ImGuiIO& io = ImGui::GetIO(); (void)io;
84 //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
85 //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
86
87 // Setup Dear ImGui style
88 ImGui::StyleColorsDark();
89 //ImGui::StyleColorsClassic();
90
91 // Setup Platform/Renderer backends
92 ImGui_ImplWin32_Init(hwnd);
93 ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT,
94 DXGI_FORMAT_R8G8B8A8_UNORM, g_pd3dSrvDescHeap,
95 g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),
96 g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());
97
98 // Load Fonts
99 // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
100 // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
101 // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
102 // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
103 // - Read 'docs/FONTS.md' for more instructions and details.
104 // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
105 //io.Fonts->AddFontDefault();
106 //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
107 //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
108 //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
109 //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
110 //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
111 //IM_ASSERT(font != NULL);
112
113 // Our state
114 bool show_demo_window = true;
115 bool show_another_window = false;
116 ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
117
118 // Main loop
119 bool done = false;
120 while (!done)
121 {
122 // Poll and handle messages (inputs, window resize, etc.)
123 // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
124 // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
125 // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
126 // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
127 MSG msg;
128 while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
129 {
130 ::TranslateMessage(&msg);
131 ::DispatchMessage(&msg);
132 if (msg.message == WM_QUIT)
133 done = true;
134 }
135 if (done)
136 break;
137
138 // Start the Dear ImGui frame
139 ImGui_ImplDX12_NewFrame();
140 ImGui_ImplWin32_NewFrame();
141 ImGui::NewFrame();
142
143 // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
144 if (show_demo_window)
145 ImGui::ShowDemoWindow(&show_demo_window);
146
147 // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
148 {
149 static float f = 0.0f;
150 static int counter = 0;
151
152 ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
153
154 ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
155 ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
156 ImGui::Checkbox("Another Window", &show_another_window);
157
158 ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
159 ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
160
161 if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
162 counter++;
163 ImGui::SameLine();
164 ImGui::Text("counter = %d", counter);
165
166 ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
167 ImGui::End();
168 }
169
170 // 3. Show another simple window.
171 if (show_another_window)
172 {
173 ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
174 ImGui::Text("Hello from another window!");
175 if (ImGui::Button("Close Me"))
176 show_another_window = false;
177 ImGui::End();
178 }
179
180 // Rendering
181 ImGui::Render();
182
183 FrameContext* frameCtx = WaitForNextFrameResources();
184 UINT backBufferIdx = g_pSwapChain->GetCurrentBackBufferIndex();
185 frameCtx->CommandAllocator->Reset();
186
187 D3D12_RESOURCE_BARRIER barrier = {};
188 barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
189 barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
190 barrier.Transition.pResource = g_mainRenderTargetResource[backBufferIdx];
191 barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
192 barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
193 barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
194 g_pd3dCommandList->Reset(frameCtx->CommandAllocator, NULL);
195 g_pd3dCommandList->ResourceBarrier(1, &barrier);
196
197 // Render Dear ImGui graphics
198 const float clear_color_with_alpha[4] = { clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w };
199 g_pd3dCommandList->ClearRenderTargetView(g_mainRenderTargetDescriptor[backBufferIdx], clear_color_with_alpha, 0, NULL);
200 g_pd3dCommandList->OMSetRenderTargets(1, &g_mainRenderTargetDescriptor[backBufferIdx], FALSE, NULL);
201 g_pd3dCommandList->SetDescriptorHeaps(1, &g_pd3dSrvDescHeap);
202 ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData(), g_pd3dCommandList);
203 barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
204 barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
205 g_pd3dCommandList->ResourceBarrier(1, &barrier);
206 g_pd3dCommandList->Close();
207
208 g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList);
209
210 g_pSwapChain->Present(1, 0); // Present with vsync
211 //g_pSwapChain->Present(0, 0); // Present without vsync
212
213 UINT64 fenceValue = g_fenceLastSignaledValue + 1;
214 g_pd3dCommandQueue->Signal(g_fence, fenceValue);
215 g_fenceLastSignaledValue = fenceValue;
216 frameCtx->FenceValue = fenceValue;
217 }
218
219 WaitForLastSubmittedFrame();
220
221 // Cleanup
222 ImGui_ImplDX12_Shutdown();
223 ImGui_ImplWin32_Shutdown();
224 ImGui::DestroyContext();
225
226 CleanupDeviceD3D();
227 ::DestroyWindow(hwnd);
228 ::UnregisterClass(wc.lpszClassName, wc.hInstance);
229
230 return 0;
231 }
232
233 // Helper functions
234
CreateDeviceD3D(HWND hWnd)235 bool CreateDeviceD3D(HWND hWnd)
236 {
237 // Setup swap chain
238 DXGI_SWAP_CHAIN_DESC1 sd;
239 {
240 ZeroMemory(&sd, sizeof(sd));
241 sd.BufferCount = NUM_BACK_BUFFERS;
242 sd.Width = 0;
243 sd.Height = 0;
244 sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
245 sd.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
246 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
247 sd.SampleDesc.Count = 1;
248 sd.SampleDesc.Quality = 0;
249 sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
250 sd.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
251 sd.Scaling = DXGI_SCALING_STRETCH;
252 sd.Stereo = FALSE;
253 }
254
255 // [DEBUG] Enable debug interface
256 #ifdef DX12_ENABLE_DEBUG_LAYER
257 ID3D12Debug* pdx12Debug = NULL;
258 if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&pdx12Debug))))
259 pdx12Debug->EnableDebugLayer();
260 #endif
261
262 // Create device
263 D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
264 if (D3D12CreateDevice(NULL, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK)
265 return false;
266
267 // [DEBUG] Setup debug interface to break on any warnings/errors
268 #ifdef DX12_ENABLE_DEBUG_LAYER
269 if (pdx12Debug != NULL)
270 {
271 ID3D12InfoQueue* pInfoQueue = NULL;
272 g_pd3dDevice->QueryInterface(IID_PPV_ARGS(&pInfoQueue));
273 pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, true);
274 pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_CORRUPTION, true);
275 pInfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, true);
276 pInfoQueue->Release();
277 pdx12Debug->Release();
278 }
279 #endif
280
281 {
282 D3D12_DESCRIPTOR_HEAP_DESC desc = {};
283 desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
284 desc.NumDescriptors = NUM_BACK_BUFFERS;
285 desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
286 desc.NodeMask = 1;
287 if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dRtvDescHeap)) != S_OK)
288 return false;
289
290 SIZE_T rtvDescriptorSize = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
291 D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = g_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
292 for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
293 {
294 g_mainRenderTargetDescriptor[i] = rtvHandle;
295 rtvHandle.ptr += rtvDescriptorSize;
296 }
297 }
298
299 {
300 D3D12_DESCRIPTOR_HEAP_DESC desc = {};
301 desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
302 desc.NumDescriptors = 1;
303 desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
304 if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dSrvDescHeap)) != S_OK)
305 return false;
306 }
307
308 {
309 D3D12_COMMAND_QUEUE_DESC desc = {};
310 desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
311 desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
312 desc.NodeMask = 1;
313 if (g_pd3dDevice->CreateCommandQueue(&desc, IID_PPV_ARGS(&g_pd3dCommandQueue)) != S_OK)
314 return false;
315 }
316
317 for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
318 if (g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g_frameContext[i].CommandAllocator)) != S_OK)
319 return false;
320
321 if (g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g_frameContext[0].CommandAllocator, NULL, IID_PPV_ARGS(&g_pd3dCommandList)) != S_OK ||
322 g_pd3dCommandList->Close() != S_OK)
323 return false;
324
325 if (g_pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g_fence)) != S_OK)
326 return false;
327
328 g_fenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
329 if (g_fenceEvent == NULL)
330 return false;
331
332 {
333 IDXGIFactory4* dxgiFactory = NULL;
334 IDXGISwapChain1* swapChain1 = NULL;
335 if (CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)) != S_OK)
336 return false;
337 if (dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1) != S_OK)
338 return false;
339 if (swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain)) != S_OK)
340 return false;
341 swapChain1->Release();
342 dxgiFactory->Release();
343 g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
344 g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
345 }
346
347 CreateRenderTarget();
348 return true;
349 }
350
CleanupDeviceD3D()351 void CleanupDeviceD3D()
352 {
353 CleanupRenderTarget();
354 if (g_pSwapChain) { g_pSwapChain->SetFullscreenState(false, NULL); g_pSwapChain->Release(); g_pSwapChain = NULL; }
355 if (g_hSwapChainWaitableObject != NULL) { CloseHandle(g_hSwapChainWaitableObject); }
356 for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
357 if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = NULL; }
358 if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = NULL; }
359 if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = NULL; }
360 if (g_pd3dRtvDescHeap) { g_pd3dRtvDescHeap->Release(); g_pd3dRtvDescHeap = NULL; }
361 if (g_pd3dSrvDescHeap) { g_pd3dSrvDescHeap->Release(); g_pd3dSrvDescHeap = NULL; }
362 if (g_fence) { g_fence->Release(); g_fence = NULL; }
363 if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = NULL; }
364 if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
365
366 #ifdef DX12_ENABLE_DEBUG_LAYER
367 IDXGIDebug1* pDebug = NULL;
368 if (SUCCEEDED(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug))))
369 {
370 pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_SUMMARY);
371 pDebug->Release();
372 }
373 #endif
374 }
375
CreateRenderTarget()376 void CreateRenderTarget()
377 {
378 for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
379 {
380 ID3D12Resource* pBackBuffer = NULL;
381 g_pSwapChain->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer));
382 g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, g_mainRenderTargetDescriptor[i]);
383 g_mainRenderTargetResource[i] = pBackBuffer;
384 }
385 }
386
CleanupRenderTarget()387 void CleanupRenderTarget()
388 {
389 WaitForLastSubmittedFrame();
390
391 for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
392 if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = NULL; }
393 }
394
WaitForLastSubmittedFrame()395 void WaitForLastSubmittedFrame()
396 {
397 FrameContext* frameCtx = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT];
398
399 UINT64 fenceValue = frameCtx->FenceValue;
400 if (fenceValue == 0)
401 return; // No fence was signaled
402
403 frameCtx->FenceValue = 0;
404 if (g_fence->GetCompletedValue() >= fenceValue)
405 return;
406
407 g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
408 WaitForSingleObject(g_fenceEvent, INFINITE);
409 }
410
WaitForNextFrameResources()411 FrameContext* WaitForNextFrameResources()
412 {
413 UINT nextFrameIndex = g_frameIndex + 1;
414 g_frameIndex = nextFrameIndex;
415
416 HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, NULL };
417 DWORD numWaitableObjects = 1;
418
419 FrameContext* frameCtx = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
420 UINT64 fenceValue = frameCtx->FenceValue;
421 if (fenceValue != 0) // means no fence was signaled
422 {
423 frameCtx->FenceValue = 0;
424 g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
425 waitableObjects[1] = g_fenceEvent;
426 numWaitableObjects = 2;
427 }
428
429 WaitForMultipleObjects(numWaitableObjects, waitableObjects, TRUE, INFINITE);
430
431 return frameCtx;
432 }
433
434 // Forward declare message handler from imgui_impl_win32.cpp
435 extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
436
437 // Win32 message handler
WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)438 LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
439 {
440 if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
441 return true;
442
443 switch (msg)
444 {
445 case WM_SIZE:
446 if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
447 {
448 WaitForLastSubmittedFrame();
449 CleanupRenderTarget();
450 HRESULT result = g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT);
451 assert(SUCCEEDED(result) && "Failed to resize swapchain.");
452 CreateRenderTarget();
453 }
454 return 0;
455 case WM_SYSCOMMAND:
456 if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
457 return 0;
458 break;
459 case WM_DESTROY:
460 ::PostQuitMessage(0);
461 return 0;
462 }
463 return ::DefWindowProc(hWnd, msg, wParam, lParam);
464 }
465