Skip to content

Commit 923bd2f

Browse files
PathogenDavidocornut
authored andcommitted
Examples: DirectX12: Fixed Alt+Enter fullscreen in DirectX12 example. (#4346, #4348)
This also removes unnecessary recreation of backend-owned device objects when the window is resized. + amend original PR with a g_pSwapChain->SetFullscreenState(false, NULL); call.
1 parent b846969 commit 923bd2f

File tree

2 files changed

+5
-30
lines changed

2 files changed

+5
-30
lines changed

docs/CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ Other Changes:
9696
- Backends: OpenGL3: Use OES_vertex_array extension on Emscripten + backup/restore current state. (#4266, #4267) [@harry75369]
9797
- Backends: GLFW: Installing and exposed ImGui_ImplGlfw_MonitorCallback() for forward compatibility with docking branch.
9898
- Backends: OSX: Added a fix for shortcuts using CTRL key instead of CMD key. (#4253) [@rokups]
99+
- Examples: DX12: Fixed handling of Alt+Enter in example app (using swapchain's ResizeBuffers). (#4346) [@PathogenDavid]
100+
- Examples: DX12: Removed unecessary recreation of backend-owned device objects when window is resized. (#4347) [@PathogenDavid]
99101
- Examples: OSX+OpenGL2: Fix event forwarding (fix key remaining stuck when using shortcuts with Cmd/Super key).
100102
Other OSX examples were not affected. (#4253, #1873) [@rokups]
101103
- Examples: Updated all .vcxproj to VS2015 (toolset v140) to facilitate usage with vcpkg.

examples/example_win32_directx12/main.cpp

+3-30
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void CreateRenderTarget();
5454
void CleanupRenderTarget();
5555
void WaitForLastSubmittedFrame();
5656
FrameContext* WaitForNextFrameResources();
57-
void ResizeSwapChain(HWND hWnd, int width, int height);
5857
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
5958

6059
// Main code
@@ -352,7 +351,7 @@ bool CreateDeviceD3D(HWND hWnd)
352351
void CleanupDeviceD3D()
353352
{
354353
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; }
356355
if (g_hSwapChainWaitableObject != NULL) { CloseHandle(g_hSwapChainWaitableObject); }
357356
for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
358357
if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = NULL; }
@@ -432,31 +431,6 @@ FrameContext* WaitForNextFrameResources()
432431
return frameCtx;
433432
}
434433

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-
460434
// Forward declare message handler from imgui_impl_win32.cpp
461435
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
462436

@@ -472,11 +446,10 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
472446
if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
473447
{
474448
WaitForLastSubmittedFrame();
475-
ImGui_ImplDX12_InvalidateDeviceObjects();
476449
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.");
478452
CreateRenderTarget();
479-
ImGui_ImplDX12_CreateDeviceObjects();
480453
}
481454
return 0;
482455
case WM_SYSCOMMAND:

0 commit comments

Comments
 (0)