Преглед на файлове

ImDrawData: added AddDrawList() helper function. (#6406, #4879, #1878)

ocornut преди 2 години
родител
ревизия
1a9ddd2396
променени са 4 файла, в които са добавени 14 реда и са изтрити 2 реда
  1. 1 1
      docs/CHANGELOG.txt
  2. 1 1
      imgui.cpp
  3. 1 0
      imgui.h
  4. 11 0
      imgui_draw.cpp

+ 1 - 1
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.

+ 1 - 1
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();

+ 1 - 0
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.
 };

+ 11 - 0
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()
 {