From 1a9ddd239622fd7aad874cdda690c89a98187b88 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 12 Jul 2023 16:57:38 +0200 Subject: [PATCH] ImDrawData: added AddDrawList() helper function. (#6406, #4879, #1878) --- docs/CHANGELOG.txt | 2 +- imgui.cpp | 2 +- imgui.h | 1 + imgui_draw.cpp | 11 +++++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b8a435f1..d02c15b8 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -49,7 +49,7 @@ Other changes: - ImDrawData: CmdLists[] array is now an ImVector<> owned by ImDrawData rather than a pointer to internal state. - This makes it easier for user to create their own or append to an existing draw data. - (#6406, #4879, #1878) + Added a ImDrawData::AddDrawList() helper function to do that. (#6406, #4879, #1878) - This makes it easier to perform a deep-swap instead of a deep-copy, as array ownership is now clear. (#6597, #6475, #6167, #5776, #5109, #4763, #3515, #1860) - Syntax and allocation count are otherwise identical. diff --git a/imgui.cpp b/imgui.cpp index a4cc8b6d..8645b84b 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -4873,7 +4873,7 @@ static void SetupViewportDrawData(ImGuiViewportP* viewport) draw_data->DisplaySize = viewport->Size; draw_data->FramebufferScale = io.DisplayFramebufferScale; draw_data->OwnerViewport = viewport; - for (int n = 0; n < draw_data->CmdLists.Size; n++) + for (int n = 0; n < draw_data->CmdLists.Size; n++) // Similar to AddDrawList() but we are already added in the array { ImDrawList* draw_list = draw_data->CmdLists[n]; draw_list->_PopUnusedDrawCmd(); diff --git a/imgui.h b/imgui.h index 9dcfc364..27451dd6 100644 --- a/imgui.h +++ b/imgui.h @@ -2756,6 +2756,7 @@ struct ImDrawData // Functions ImDrawData() { Clear(); } IMGUI_API void Clear(); + IMGUI_API void AddDrawList(ImDrawList* draw_list); // Helper to add an external draw list into an existing ImDrawData. IMGUI_API void DeIndexAllBuffers(); // Helper to convert all buffers from indexed to non-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& fb_scale); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than Dear ImGui expects, or if there is a difference between your window resolution and framebuffer resolution. }; diff --git a/imgui_draw.cpp b/imgui_draw.cpp index d218ddf3..bdf539db 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1817,6 +1817,17 @@ void ImDrawData::Clear() OwnerViewport = NULL; } +void ImDrawData::AddDrawList(ImDrawList* draw_list) +{ + IM_ASSERT(Valid); + IM_ASSERT(CmdLists.Size == CmdListsCount); + draw_list->_PopUnusedDrawCmd(); + CmdLists.push_back(draw_list); + CmdListsCount++; + TotalVtxCount += draw_list->VtxBuffer.Size; + TotalIdxCount += draw_list->IdxBuffer.Size; +} + // For backward compatibility: 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! void ImDrawData::DeIndexAllBuffers() {