Use Vulkan drawable size for frame buffer scale when using SDL and Vulkan #3190
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When running the Vulkan SDL example I noticed that the display can be scaled incorrectly. This occurs when the example is launched on a non-retina monitor that is used with a retina Macbook. It doesn't just look incorrect - the cursor behaves as though the display has been scaled correctly, making mouse input unusable.
The first screenshot shows the expected behaviour with the SDL + OpenGL3 example, and the second shows the issue with the SDL + Vulkan example:
SDL + OpenGL3
SDL + Vulkan
In
examples/imgui_impl_sdl.cpp
The code to determine the framebuffer scale looks like this:The code always uses
SDL_GL_GetDrawableSize
but when using Vulkan,SDL_Vulkan_GetDrawableSize
[1] should be used instead.Solution
The correct
SDL_*_GetDrawableSize
function can be determined by inspecting whether the window has the Vulkan flag set. If it doesn't, the original behaviour is used:However,
SDL_GL_GetDrawableSize
comes fromSDL_Video.h
which is included by default, butSDL_Vulkan_GetDrawableSize
comes fromSDL_vulkan.h
which is not included by default. To prevent bringing a whole new include in, I propose forward declaring the function instead:Testing
Firstly, I encountered the issue mentioned in #3177 and had to apply the fix from that PR locally.
Then I used the following Makefile from the root of the
imgui
repo to build the SDL OpenGL and Vulkan examples.Before applying the fix, this resulted in the screenshots above when launching the example code on a non-retina monitor that is attached to a retina Macbook. After applying the fix, the behaviour for the Vulkan example aligned with the OpenGL one as expected.
The issue is not present when running the examples on just a retina Macbook, or with a retina display attached to a retina Macbook.
References
[1] libsdl.org/SDL_Vulkan_GetDrawableSize