How to handle framebuffer scaling?
Version/Branch of Dear ImGui:
Version 1.91.5, Branch: master (master/docking/etc.)
Back-ends:
imgui_impl_win32.cpp + imgui_impl_dx12.cpp
Compiler, OS:
Win 10 + MSVC
Full config/build information:
No response
Details:
How to properly scale ImGui when the swap chain size != window size? So far seems like window size is the driver for mouse positions, viewports, etc. Currently when my framebuffer and window size mismatch the mouse positions are wrong and imgui viewport goes outside the frame buffer. For example, on my monitor having a native window (2560x1600) with swap chain (1280x720) results in me having to click way off to the top-left of everything for the mouse to be registered. Testing with the "ImGui::ShowDemoWindow()" currently.
I've tried playing the following properties, either before or after the XYZ_NewFrame calls
ImGui::GetIO().DisplaySize = ImVec2(F32(GetDisplayOptions().Resolution[0]), F32(GetDisplayOptions().Resolution[1]));
ImGui::GetIO().DisplayFramebufferScale = ImVec2(frameBufferScale[0], frameBufferScale[1]);
But did not seem to affect anything at all. Settings the main viewport manually also does not affect the mouse position issue.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
// Here's some code anyone can copy and paste to reproduce your issue
ImGui::Begin("Example Bug");
MoreCodeToExplainMyIssue();
ImGui::End();
A very quick repro would be to use the example_win32_directx12 and on WM_SIZE hardcode e.g 1280x720 on the swapchain. This would allow to detach window size from swap chain size to showcase the issue.
Support for FramebufferScale in directx backends was added very recently #8412 but it's a dumb multiply and by current design we don't expect non-integer value in this field as it is designed for Retina framebuffer density, and may be not adequate for this purpose yet.
There are lots of open issues related to decorrelating window coordinates from imgui coordinates, and it would make sense to apply a similar system to the renderer.
Grabbed #8412 locally, works much better. Now the viewport is correctly calculated, the resolution changes, as opposed to shift and stretch in imgui. Also mouse coordinates seem to be working properly again. Thanks!