From d2c7cbcbf9bf6af935ee2b089fa772e3c6ea7d41 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 14 Aug 2023 16:23:04 +0200 Subject: [PATCH] Misc: Made multiple calls to Render() during the same frame early out faster. --- docs/CHANGELOG.txt | 1 + imgui.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 786b6c9b..5b71899a 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -54,6 +54,7 @@ Other changes: of individual ImDrawList's buffer sizes when a dimming/modal background is rendered. (#6716) - ImDrawList: Fixed OOB access in _CalcCircleAutoSegmentCount when passing excessively large radius to AddCircle(). (#6657, #5317) [@EggsyCRO, @jdpatdiscord] +- Misc: Made multiple calls to Render() during the same frame early out faster. - Debug Tools: Metrics: Fixed "Drawlists" section and per-viewport equivalent appearing empty (regression in 1.89.8). - Demo: Demonstrate out-of-order rendering using ImDrawListSplitter. diff --git a/imgui.cpp b/imgui.cpp index 2739c847..5b5e7ad8 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5077,15 +5077,15 @@ void ImGui::Render() if (g.FrameCountEnded != g.FrameCount) EndFrame(); - const bool first_render_of_frame = (g.FrameCountRendered != g.FrameCount); + if (g.FrameCountRendered == g.FrameCount) + return; g.FrameCountRendered = g.FrameCount; - g.IO.MetricsRenderWindows = 0; + g.IO.MetricsRenderWindows = 0; CallContextHooks(&g, ImGuiContextHookType_RenderPre); // Draw modal/window whitening backgrounds - if (first_render_of_frame) - RenderDimmedBackgrounds(); + RenderDimmedBackgrounds(); // Add background ImDrawList (for each active viewport) for (int n = 0; n != g.Viewports.Size; n++) @@ -5112,7 +5112,7 @@ void ImGui::Render() AddRootWindowToDrawData(windows_to_render_top_most[n]); // Draw software mouse cursor if requested by io.MouseDrawCursor flag - if (g.IO.MouseDrawCursor && first_render_of_frame && g.MouseCursor != ImGuiMouseCursor_None) + if (g.IO.MouseDrawCursor && g.MouseCursor != ImGuiMouseCursor_None) RenderMouseCursor(g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); // Setup ImDrawData structures for end-user