@@ -54,7 +54,6 @@ void CreateRenderTarget();
54
54
void CleanupRenderTarget ();
55
55
void WaitForLastSubmittedFrame ();
56
56
FrameContext* WaitForNextFrameResources ();
57
- void ResizeSwapChain (HWND hWnd, int width, int height);
58
57
LRESULT WINAPI WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
59
58
60
59
// Main code
@@ -352,7 +351,7 @@ bool CreateDeviceD3D(HWND hWnd)
352
351
void CleanupDeviceD3D ()
353
352
{
354
353
CleanupRenderTarget ();
355
- if (g_pSwapChain) { g_pSwapChain->Release (); g_pSwapChain = NULL ; }
354
+ if (g_pSwapChain) { g_pSwapChain->SetFullscreenState ( false , NULL ); g_pSwapChain-> Release (); g_pSwapChain = NULL ; }
356
355
if (g_hSwapChainWaitableObject != NULL ) { CloseHandle (g_hSwapChainWaitableObject); }
357
356
for (UINT i = 0 ; i < NUM_FRAMES_IN_FLIGHT; i++)
358
357
if (g_frameContext[i].CommandAllocator ) { g_frameContext[i].CommandAllocator ->Release (); g_frameContext[i].CommandAllocator = NULL ; }
@@ -432,31 +431,6 @@ FrameContext* WaitForNextFrameResources()
432
431
return frameCtx;
433
432
}
434
433
435
- void ResizeSwapChain (HWND hWnd, int width, int height)
436
- {
437
- DXGI_SWAP_CHAIN_DESC1 sd;
438
- g_pSwapChain->GetDesc1 (&sd);
439
- sd.Width = width;
440
- sd.Height = height;
441
-
442
- IDXGIFactory4* dxgiFactory = NULL ;
443
- g_pSwapChain->GetParent (IID_PPV_ARGS (&dxgiFactory));
444
-
445
- g_pSwapChain->Release ();
446
- CloseHandle (g_hSwapChainWaitableObject);
447
-
448
- IDXGISwapChain1* swapChain1 = NULL ;
449
- dxgiFactory->CreateSwapChainForHwnd (g_pd3dCommandQueue, hWnd, &sd, NULL , NULL , &swapChain1);
450
- swapChain1->QueryInterface (IID_PPV_ARGS (&g_pSwapChain));
451
- swapChain1->Release ();
452
- dxgiFactory->Release ();
453
-
454
- g_pSwapChain->SetMaximumFrameLatency (NUM_BACK_BUFFERS);
455
-
456
- g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject ();
457
- assert (g_hSwapChainWaitableObject != NULL );
458
- }
459
-
460
434
// Forward declare message handler from imgui_impl_win32.cpp
461
435
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
462
436
@@ -472,11 +446,10 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
472
446
if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
473
447
{
474
448
WaitForLastSubmittedFrame ();
475
- ImGui_ImplDX12_InvalidateDeviceObjects ();
476
449
CleanupRenderTarget ();
477
- ResizeSwapChain (hWnd, (UINT)LOWORD (lParam), (UINT)HIWORD (lParam));
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." );
478
452
CreateRenderTarget ();
479
- ImGui_ImplDX12_CreateDeviceObjects ();
480
453
}
481
454
return 0 ;
482
455
case WM_SYSCOMMAND:
0 commit comments