浏览代码

AA branch: added ImDrawData::DeIndexAllBuffers() helper (#254)

ocornut 10 年之前
父节点
当前提交
0676efd37f
共有 2 个文件被更改,包括 26 次插入0 次删除
  1. 23 0
      imgui.cpp
  2. 3 0
      imgui.h

+ 23 - 0
imgui.cpp

@@ -9503,6 +9503,29 @@ void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& a, const Im
         PopTextureID();
         PopTextureID();
 }
 }
 
 
+//-----------------------------------------------------------------------------
+// ImDrawData
+//-----------------------------------------------------------------------------
+
+// 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()
+{
+    ImVector<ImDrawVert> new_vtx_buffer;
+    total_vtx_count = total_idx_count = 0;
+    for (int i = 0; i < cmd_lists_count; i++)
+    {
+        ImDrawList* cmd_list = cmd_lists[i];
+        if (cmd_list->idx_buffer.empty())
+            continue;
+        new_vtx_buffer.resize(cmd_list->idx_buffer.size());
+        for (size_t i = 0; i < cmd_list->idx_buffer.size(); i++)
+            new_vtx_buffer[i] = cmd_list->vtx_buffer[cmd_list->idx_buffer[i]];
+        cmd_list->vtx_buffer.swap(new_vtx_buffer);
+        cmd_list->idx_buffer.resize(0);
+        total_vtx_count += (int)cmd_list->vtx_buffer.size();
+    }
+}
+
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // ImFontAtlias
 // ImFontAtlias
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 3 - 0
imgui.h

@@ -1095,6 +1095,9 @@ struct ImDrawData
     int             cmd_lists_count;
     int             cmd_lists_count;
     int             total_vtx_count;        // For convenience, sum of all cmd_lists vtx_buffer.size()
     int             total_vtx_count;        // For convenience, sum of all cmd_lists vtx_buffer.size()
     int             total_idx_count;        // For convenience, sum of all cmd_lists idx_buffer.size()
     int             total_idx_count;        // For convenience, sum of all cmd_lists idx_buffer.size()
+
+    // Functions
+    void DeIndexAllBuffers();               // 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!
 };
 };
 
 
 // Load and rasterize multiple TTF fonts into a same texture.
 // Load and rasterize multiple TTF fonts into a same texture.