Skip to content

Commit 724c69b

Browse files
committed
Backends: SDL2: fixed querying framebuffer scale/density when using Metal. (#5592)
1 parent 6a6d7bc commit 724c69b

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

backends/imgui_impl_sdl2.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
// CHANGELOG
2323
// (minor and older changes stripped away, please see git history for details)
24+
// 2026-08-06: Fixed querying framebuffer scale when using Metal. (#5592)
2425
// 2026-07-15: Inputs: restore SDL_StartTextInput()/SDL_StopTextInput() in IME handler for on-screen keyboard support on Android/mobile. (#7636, #9474)
2526
// 2026-04-16: Made ImGui_ImplSDL2_GetContentScaleForWindow(), ImGui_ImplSDL2_GetContentScaleForDisplay() helpers return a minimum of 1.0f, as some Linux setup seems to report <1.0f value and this breaks scaling border size. (#9369)
2627
// 2026-02-13: Inputs: systems other than X11 are back to starting mouse capture on mouse down (reverts 2025-02-26 change). Only X11 requires waiting for a drag by default (not ideal, but a better default for X11 users). Added ImGui_ImplSDL2_SetMouseCaptureMode() for X11 debugger users. (#3650, #6410, #9235)
@@ -135,10 +136,18 @@
135136
#endif
136137
#define SDL_HAS_PER_MONITOR_DPI SDL_VERSION_ATLEAST(2,0,4)
137138
#define SDL_HAS_VULKAN SDL_VERSION_ATLEAST(2,0,6)
139+
#if defined(__APPLE__)
140+
#define SDL_HAS_METAL SDL_VERSION_ATLEAST(2,0,14)
141+
#else
142+
#define SDL_HAS_METAL 0
143+
#endif
138144
#define SDL_HAS_OPEN_URL SDL_VERSION_ATLEAST(2,0,14)
139145
#if SDL_HAS_VULKAN
140146
#include <SDL_vulkan.h>
141147
#endif
148+
#if SDL_HAS_METAL
149+
#include <SDL_metal.h>
150+
#endif
142151

143152
// SDL Data
144153
struct ImGui_ImplSDL2_Data
@@ -899,6 +908,10 @@ static void ImGui_ImplSDL2_GetWindowSizeAndFramebufferScale(SDL_Window* window,
899908
#if SDL_HAS_VULKAN
900909
else if (SDL_GetWindowFlags(window) & SDL_WINDOW_VULKAN)
901910
SDL_Vulkan_GetDrawableSize(window, &display_w, &display_h);
911+
#endif
912+
#if SDL_HAS_METAL
913+
else if (SDL_GetWindowFlags(window) & SDL_WINDOW_METAL)
914+
SDL_Metal_GetDrawableSize(window, &display_w, &display_h);
902915
#endif
903916
else
904917
SDL_GL_GetDrawableSize(window, &display_w, &display_h);

docs/CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Other Changes:
6262
- Circle and Curves tessellation error are scaled accordingly.
6363
- Backends:
6464
- QNX: added QNX Screen backend. (#9492) [@mgorchak-blackberry]
65+
- SDL2: fixed querying framebuffer scale/density when using Metal. (#5592) [@lailoken]
6566
- Examples:
6667
- QNX+OpenGL3, QNX+Vulkan: added QNX Screen examples. (#9492) [@mgorchak-blackberry]
6768

examples/example_sdl2_metal/main.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ int main(int, char**)
5656
return 1;
5757
}
5858

59-
// Inform SDL that we will be using metal for rendering. Without this hint initialization of metal renderer may fail.
59+
// Inform SDL that we will be using metal for rendering. Without this hint initialization of Metal renderer may fail.
6060
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "metal");
6161

62-
// Enable native IME.
62+
// From 2.0.18: Enable native IME.
63+
#ifdef SDL_HINT_IME_SHOW_UI
6364
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
65+
#endif
6466

65-
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL+Metal example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 800, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
67+
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Metal example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 800, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
6668
if (window == nullptr)
6769
{
6870
printf("Error creating window: %s\n", SDL_GetError());

0 commit comments

Comments
 (0)