Skip to content

Commit

Permalink
ImDrawData: added AddDrawList() helper function. (#6406, #4879, #1878)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Jul 12, 2023
1 parent c649aca commit 1a9ddd2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
};
Expand Down
11 changes: 11 additions & 0 deletions imgui_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 1a9ddd2

Please sign in to comment.