From 2b319400ed1ecb27e8e007dc45f052612d3b7680 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Thu, 1 Feb 2024 16:43:59 +0100 Subject: [PATCH] dx11 backend: add check / does not support window resizing --- .../internal/backend_impls/abstract_runner.cpp | 6 +++++- .../internal/backend_impls/rendering_dx11.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp index ec4e3897..b96acd49 100644 --- a/src/hello_imgui/internal/backend_impls/abstract_runner.cpp +++ b/src/hello_imgui/internal/backend_impls/abstract_runner.cpp @@ -199,7 +199,11 @@ float AbstractRunner::ImGuiDefaultFontGlobalScale() float AbstractRunner::DpiWindowSizeFactor() { - return mBackendWindowHelper->GetWindowSizeDpiScaleFactor(mWindow); +#ifdef HELLOIMGUI_HAS_DIRECTX11 + return 1.f; // The current implementation of Dx11 backend does not support changing the window size +#endif + float r = mBackendWindowHelper->GetWindowSizeDpiScaleFactor(mWindow); + return 1.f; } diff --git a/src/hello_imgui/internal/backend_impls/rendering_dx11.cpp b/src/hello_imgui/internal/backend_impls/rendering_dx11.cpp index e7c812f9..acb19dbe 100644 --- a/src/hello_imgui/internal/backend_impls/rendering_dx11.cpp +++ b/src/hello_imgui/internal/backend_impls/rendering_dx11.cpp @@ -2,6 +2,7 @@ #include "rendering_dx11.h" #include "hello_imgui/hello_imgui.h" +#include #include #include @@ -83,6 +84,16 @@ namespace HelloImGui // Impl of RenderingCallbacks_Impl_SwapBuffers void SwapDx11Buffers() { + static ImVec2 viewportInitialSize = ImGui::GetMainViewport()->Size; + ImVec2 currentViewportSize = ImGui::GetMainViewport()->Size; + if ((currentViewportSize.x != viewportInitialSize.x) || (currentViewportSize.y != viewportInitialSize.y)) + { + // Help appreciated! + IM_ASSERT(false && "rendering_dx11.cpp::SwapDx11Buffers() The current implementation of Dx11 backend does " + "not support changing the window size!"); + // Once solved, AbstractRunner::DpiWindowSizeFactor() can be corrected by removing the ifdef + } + auto& gDx11Globals = GetDx11Globals(); gDx11Globals.pSwapChain->Present(1, 0); // Present with vsync }