diff --git a/imgui.cpp b/imgui.cpp index 98855dc9..300dc7a3 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -685,8 +685,8 @@ static ImGuiWindow* CreateNewWindow(const char* name, ImVec2 size, ImGuiWind static void CheckStacksSize(ImGuiWindow* window, bool write); static ImVec2 CalcNextScrollFromScrollTargetAndClamp(ImGuiWindow* window); -static void AddDrawListToRenderList(ImVector* out_render_list, ImDrawList* draw_list); -static void AddWindowToRenderList(ImVector* out_render_list, ImGuiWindow* window); +static void AddDrawListToDrawData(ImVector* out_render_list, ImDrawList* draw_list); +static void AddWindowToDrawData(ImVector* out_render_list, ImGuiWindow* window); static void AddWindowToSortedBuffer(ImVector* out_sorted_windows, ImGuiWindow* window); static ImGuiWindowSettings* AddWindowSettings(const char* name); @@ -3087,9 +3087,7 @@ void ImGui::NewFrame() g.OverlayDrawList.Flags = (g.Style.AntiAliasedLines ? ImDrawListFlags_AntiAliasedLines : 0) | (g.Style.AntiAliasedFill ? ImDrawListFlags_AntiAliasedFill : 0); // Mark rendering data as invalid to prevent user who may have a handle on it to use it - g.DrawData.Valid = false; - g.DrawData.CmdLists = NULL; - g.DrawData.CmdListsCount = g.DrawData.TotalVtxCount = g.DrawData.TotalIdxCount = 0; + g.DrawData.Clear(); // Clear reference to active widget if the widget isn't alive anymore if (!g.HoveredIdPreviousFrame) @@ -3647,7 +3645,7 @@ static void AddWindowToSortedBuffer(ImVector& out_sorted_windows, } } -static void AddDrawListToRenderList(ImVector* out_render_list, ImDrawList* draw_list) +static void AddDrawListToDrawData(ImVector* out_render_list, ImDrawList* draw_list) { if (draw_list->CmdBuffer.empty()) return; @@ -3680,25 +3678,25 @@ static void AddDrawListToRenderList(ImVector* out_render_list, ImDr out_render_list->push_back(draw_list); } -static void AddWindowToRenderList(ImVector* out_render_list, ImGuiWindow* window) +static void AddWindowToDrawData(ImVector* out_render_list, ImGuiWindow* window) { - AddDrawListToRenderList(out_render_list, window->DrawList); + AddDrawListToDrawData(out_render_list, window->DrawList); for (int i = 0; i < window->DC.ChildWindows.Size; i++) { ImGuiWindow* child = window->DC.ChildWindows[i]; if (child->Active && child->HiddenFrames <= 0) // clipped children may have been marked not active - AddWindowToRenderList(out_render_list, child); + AddWindowToDrawData(out_render_list, child); } } -static void AddWindowToDrawDataSelectLayer(ImDrawDataBuilder* builder, ImGuiWindow* window) +static void AddWindowToDrawDataSelectLayer(ImGuiWindow* window) { ImGuiContext& g = *GImGui; g.IO.MetricsActiveWindows++; if (window->Flags & ImGuiWindowFlags_Tooltip) - AddWindowToRenderList(&builder->Layers[1], window); + AddWindowToDrawData(&g.DrawDataBuilder.Layers[1], window); else - AddWindowToRenderList(&builder->Layers[0], window); + AddWindowToDrawData(&g.DrawDataBuilder.Layers[0], window); } void ImDrawDataBuilder::FlattenIntoSingleLayer() @@ -3719,16 +3717,16 @@ void ImDrawDataBuilder::FlattenIntoSingleLayer() } } -void ImDrawDataBuilder::SetupDrawData(ImDrawData* out_draw_data) +static void SetupDrawData(ImVector* draw_lists, ImDrawData* out_draw_data) { out_draw_data->Valid = true; - out_draw_data->CmdLists = (Layers[0].Size > 0) ? Layers[0].Data : NULL; - out_draw_data->CmdListsCount = Layers[0].Size; + out_draw_data->CmdLists = (draw_lists->Size > 0) ? draw_lists->Data : NULL; + out_draw_data->CmdListsCount = draw_lists->Size; out_draw_data->TotalVtxCount = out_draw_data->TotalIdxCount = 0; - for (int n = 0; n < Layers[0].Size; n++) + for (int n = 0; n < draw_lists->Size; n++) { - out_draw_data->TotalVtxCount += Layers[0][n]->VtxBuffer.Size; - out_draw_data->TotalIdxCount += Layers[0][n]->IdxBuffer.Size; + out_draw_data->TotalVtxCount += draw_lists->Data[n]->VtxBuffer.Size; + out_draw_data->TotalIdxCount += draw_lists->Data[n]->IdxBuffer.Size; } } @@ -3864,11 +3862,11 @@ void ImGui::Render() // Gather windows to render g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = g.IO.MetricsActiveWindows = 0; g.DrawDataBuilder.Clear(); - for (int i = 0; i != g.Windows.Size; i++) + for (int n = 0; n != g.Windows.Size; n++) { - ImGuiWindow* window = g.Windows[i]; + ImGuiWindow* window = g.Windows[n]; if (window->Active && window->HiddenFrames <= 0 && (window->Flags & (ImGuiWindowFlags_ChildWindow)) == 0 && window != g.NavWindowingTarget) - AddWindowToDrawDataSelectLayer(&g.DrawDataBuilder, window); + AddWindowToDrawDataSelectLayer(window); } if (g.NavWindowingTarget && g.NavWindowingTarget->Active && g.NavWindowingTarget->HiddenFrames <= 0) // NavWindowingTarget is always temporarily displayed as the front-most window AddWindowToDrawDataSelectLayer(&g.DrawDataBuilder, g.NavWindowingTarget); @@ -3889,10 +3887,10 @@ void ImGui::Render() g.OverlayDrawList.PopTextureID(); } if (!g.OverlayDrawList.VtxBuffer.empty()) - AddDrawListToRenderList(&g.DrawDataBuilder.Layers[0], &g.OverlayDrawList); + AddDrawListToDrawData(&g.DrawDataBuilder.Layers[0], &g.OverlayDrawList); // Setup ImDrawData structure for end-user - g.DrawDataBuilder.SetupDrawData(&g.DrawData); + SetupDrawData(&g.DrawDataBuilder.Layers[0], &g.DrawData); g.IO.MetricsRenderVertices = g.DrawData.TotalVtxCount; g.IO.MetricsRenderIndices = g.DrawData.TotalIdxCount; diff --git a/imgui.h b/imgui.h index e73a5445..6b121437 100644 --- a/imgui.h +++ b/imgui.h @@ -1536,7 +1536,8 @@ struct ImDrawData int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size // Functions - ImDrawData() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; } + ImDrawData() { Clear(); } + void Clear() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; } // Draw lists are owned by the ImGuiContext and only pointed to here. IMGUI_API void DeIndexAllBuffers(); // For backward compatibility or convenience: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering! IMGUI_API void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution. }; diff --git a/imgui_internal.h b/imgui_internal.h index a323afe3..1f39a662 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -488,7 +488,6 @@ struct ImDrawDataBuilder void Clear() { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].resize(0); } void ClearFreeMemory() { for (int n = 0; n < IM_ARRAYSIZE(Layers); n++) Layers[n].clear(); } IMGUI_API void FlattenIntoSingleLayer(); - IMGUI_API void SetupDrawData(ImDrawData* out_draw_data); }; // Storage for SetNexWindow** functions