From e443ea139ddcee75fea326375198dda1e85ce8ff Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 6 Oct 2021 13:41:29 +0200 Subject: [PATCH] Backends: SDL_Renderer: Backup and restore modified ClipRect/Viewport. (#3926, #4582) --- backends/imgui_impl_sdlrenderer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backends/imgui_impl_sdlrenderer.cpp b/backends/imgui_impl_sdlrenderer.cpp index 4f564f47d..ff1631133 100644 --- a/backends/imgui_impl_sdlrenderer.cpp +++ b/backends/imgui_impl_sdlrenderer.cpp @@ -15,6 +15,7 @@ // Read online: https://github.com/ocornut/imgui/tree/master/docs // CHANGELOG +// 2021-10-06: Backup and restore modified ClipRect/Viewport. // 2021-09-21: Initial version. #include "imgui.h" @@ -115,6 +116,16 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) if (fb_width == 0 || fb_height == 0) return; + // Backup SDL_Renderer state that will be modified to restore it afterwards + struct BackupSDLRendererState + { + SDL_Rect Viewport; + SDL_Rect ClipRect; + }; + BackupSDLRendererState old = {}; + SDL_RenderGetViewport(bd->SDLRenderer, &old.Viewport); + SDL_RenderGetClipRect(bd->SDLRenderer, &old.ClipRect); + // Will project scissor/clipping rectangles into framebuffer space ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports ImVec2 clip_scale = render_scale; @@ -169,6 +180,10 @@ void ImGui_ImplSDLRenderer_RenderDrawData(ImDrawData* draw_data) } } } + + // Restore modified SDL_Renderer state + SDL_RenderSetViewport(bd->SDLRenderer, &old.Viewport); + SDL_RenderSetClipRect(bd->SDLRenderer, &old.ClipRect); } // Called by Init/NewFrame/Shutdown