From 70d7d66d0c9c3cf7a37c6cf1d1e603dd036fdd85 Mon Sep 17 00:00:00 2001 From: David Chavez Date: Wed, 24 Aug 2022 02:12:40 +0200 Subject: [PATCH] Add multiviewport support for SDL (#1275) --- libultraship/libultraship/ImGuiImpl.cpp | 18 ++++++++++++++++-- .../libultraship/Lib/Fast3D/gfx_sdl2.cpp | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index 284fb8489..9f033b002 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -41,8 +41,10 @@ #if __APPLE__ #include +#include #else #include +#include #endif #ifdef __SWITCH__ @@ -337,6 +339,8 @@ namespace SohImGui { switch (impl.backend) { case Backend::DX11: return true; + case Backend::SDL: + return true; default: return false; } @@ -2398,8 +2402,18 @@ namespace SohImGui { ImGui::Render(); ImGuiRenderDrawData(ImGui::GetDrawData()); if (UseViewports()) { - ImGui::UpdatePlatformWindows(); - ImGui::RenderPlatformWindowsDefault(); + if (impl.backend == Backend::SDL) { + SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow(); + SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext(); + + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + + SDL_GL_MakeCurrent(backup_current_window, backup_current_context); + } else { + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + } } } diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp index 76573c084..fa657e40c 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_sdl2.cpp @@ -189,6 +189,7 @@ static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen, uint32 } #endif + SDL_GL_MakeCurrent(wnd, ctx); SDL_GL_SetSwapInterval(1); SohImGui::WindowImpl window_impl;