Skip to content

Commit 7524362

Browse files
committed
Metrics: Made Tools section more prominent, added options, made mesh viewer more accessible.
1 parent cc0d4e3 commit 7524362

File tree

2 files changed

+79
-55
lines changed

2 files changed

+79
-55
lines changed

docs/CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Other Changes:
7575
tampered with between NewFrame() and EndFrame().
7676
- Misc, Freetype: Fixed support for IMGUI_STB_RECT_PACK_FILENAME compile time directive
7777
in imgui_freetype.cpp (matching support in the regular code path). (#3062) [@DonKult]
78+
- Metrics: Made Tools section more prominent. Showing wire-frame mesh directly hovering the ImDrawCmd
79+
instead of requiring to open it. Added options to disable bounding box and mesh display.
80+
Added notes on inactive/gc-ed windows.
7881
- Demo: Added black and white and color gradients to Demo>Examples>Custom Rendering.
7982
- CI: Added more tests on the continuous-integration server: extra warnings for Clang/GCC, building
8083
SDL+Metal example, building imgui_freetype.cpp, more compile-time imconfig.h settings: disabling

imgui.cpp

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9990,7 +9990,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
99909990
static bool show_windows_begin_order = false;
99919991
static bool show_tables_rects = false;
99929992
static int show_tables_rect_type = TRT_WorkRect;
9993-
static bool show_drawcmd_details = true;
9993+
static bool show_drawcmd_mesh = true;
9994+
static bool show_drawcmd_aabb = true;
99949995

99959996
// Basic info
99969997
ImGuiContext& g = *GImGui;
@@ -10024,6 +10025,38 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1002410025
return ImRect();
1002510026
}
1002610027

10028+
static void NodeDrawCmdShowMeshAndBoundingBox(ImGuiWindow* window, const ImDrawList* draw_list, const ImDrawCmd* draw_cmd, int elem_offset, bool show_mesh, bool show_aabb)
10029+
{
10030+
IM_ASSERT(show_mesh || show_aabb);
10031+
ImDrawList* fg_draw_list = GetForegroundDrawList(window); // Render additional visuals into the top-most draw list
10032+
ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL;
10033+
10034+
// Draw wire-frame version of all triangles
10035+
ImRect clip_rect = draw_cmd->ClipRect;
10036+
ImRect vtxs_rect(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
10037+
ImDrawListFlags backup_flags = fg_draw_list->Flags;
10038+
fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines is more readable for very large and thin triangles.
10039+
for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + draw_cmd->ElemCount); base_idx += 3)
10040+
{
10041+
ImVec2 triangle[3];
10042+
for (int n = 0; n < 3; n++)
10043+
{
10044+
ImVec2 p = draw_list->VtxBuffer[idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n)].pos;
10045+
triangle[n] = p;
10046+
vtxs_rect.Add(p);
10047+
}
10048+
if (show_mesh)
10049+
fg_draw_list->AddPolyline(triangle, 3, IM_COL32(255, 255, 0, 255), true, 1.0f); // In yellow: mesh triangles
10050+
}
10051+
// Draw bounding boxes
10052+
if (show_aabb)
10053+
{
10054+
fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255, 0, 255, 255)); // In pink: clipping rectangle submitted to GPU
10055+
fg_draw_list->AddRect(ImFloor(vtxs_rect.Min), ImFloor(vtxs_rect.Max), IM_COL32(0, 255, 255, 255)); // In cyan: bounding box of triangles
10056+
}
10057+
fg_draw_list->Flags = backup_flags;
10058+
}
10059+
1002710060
static void NodeDrawList(ImGuiWindow* window, ImDrawList* draw_list, const char* label)
1002810061
{
1002910062
bool node_open = ImGui::TreeNode(draw_list, "%s: '%s' %d vtx, %d indices, %d cmds", label, draw_list->_OwnerName ? draw_list->_OwnerName : "", draw_list->VtxBuffer.Size, draw_list->IdxBuffer.Size, draw_list->CmdBuffer.Size);
@@ -10061,15 +10094,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1006110094
pcmd->ElemCount/3, (void*)(intptr_t)pcmd->TextureId,
1006210095
pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w);
1006310096
bool pcmd_node_open = ImGui::TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "%s", buf);
10064-
if (show_drawcmd_details && fg_draw_list && ImGui::IsItemHovered())
10065-
{
10066-
ImRect clip_rect = pcmd->ClipRect;
10067-
ImRect vtxs_rect(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
10068-
for (unsigned int i = elem_offset; i < elem_offset + (int)pcmd->ElemCount; i++)
10069-
vtxs_rect.Add(draw_list->VtxBuffer[idx_buffer ? idx_buffer[i] : i].pos);
10070-
fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255,0,255,255));
10071-
fg_draw_list->AddRect(ImFloor(vtxs_rect.Min), ImFloor(vtxs_rect.Max), IM_COL32(255,255,0,255));
10072-
}
10097+
if (ImGui::IsItemHovered() && (show_drawcmd_mesh || show_drawcmd_aabb) && fg_draw_list)
10098+
NodeDrawCmdShowMeshAndBoundingBox(window, draw_list, pcmd, elem_offset, show_drawcmd_mesh, show_drawcmd_aabb);
1007310099
if (!pcmd_node_open)
1007410100
continue;
1007510101

@@ -10087,22 +10113,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1008710113
// Display vertex information summary. Hover to get all triangles drawn in wire-frame
1008810114
ImFormatString(buf, IM_ARRAYSIZE(buf), "Mesh: ElemCount: %d, VtxOffset: +%d, IdxOffset: +%d, Area: ~%0.f px", pcmd->ElemCount, pcmd->VtxOffset, pcmd->IdxOffset, total_area);
1008910115
ImGui::Selectable(buf);
10090-
if (fg_draw_list && ImGui::IsItemHovered() && show_drawcmd_details)
10091-
{
10092-
// Draw wire-frame version of everything
10093-
ImDrawListFlags backup_flags = fg_draw_list->Flags;
10094-
fg_draw_list->Flags &= ~ImDrawListFlags_AntiAliasedLines; // Disable AA on triangle outlines is more readable for very large and thin triangles.
10095-
ImRect clip_rect = pcmd->ClipRect;
10096-
fg_draw_list->AddRect(ImFloor(clip_rect.Min), ImFloor(clip_rect.Max), IM_COL32(255, 0, 255, 255));
10097-
for (unsigned int base_idx = elem_offset; base_idx < (elem_offset + pcmd->ElemCount); base_idx += 3)
10098-
{
10099-
ImVec2 triangle[3];
10100-
for (int n = 0; n < 3; n++)
10101-
triangle[n] = draw_list->VtxBuffer[idx_buffer ? idx_buffer[base_idx + n] : (base_idx + n)].pos;
10102-
fg_draw_list->AddPolyline(triangle, 3, IM_COL32(255, 255, 0, 255), true, 1.0f);
10103-
}
10104-
fg_draw_list->Flags = backup_flags;
10105-
}
10116+
if (ImGui::IsItemHovered() && fg_draw_list)
10117+
NodeDrawCmdShowMeshAndBoundingBox(window, draw_list, pcmd, elem_offset, true, false);
1010610118

1010710119
// Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted.
1010810120
ImGuiListClipper clipper(pcmd->ElemCount/3); // Manually coarse clip our print out of individual vertices to save CPU, only items that may be visible.
@@ -10168,6 +10180,12 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1016810180
ImGui::GetForegroundDrawList()->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255));
1016910181
if (!open)
1017010182
return;
10183+
10184+
if (!window->WasActive)
10185+
ImGui::TextDisabled("Note: window is not currently visible.");
10186+
if (window->MemoryCompacted)
10187+
ImGui::TextDisabled("Note: some memory buffers have been compacted/freed.");
10188+
1017110189
ImGuiWindowFlags flags = window->Flags;
1017210190
NodeDrawList(window, window->DrawList, "DrawList");
1017310191
ImGui::BulletText("Pos: (%.1f,%.1f), Size: (%.1f,%.1f), ContentSize (%.1f,%.1f)", window->Pos.x, window->Pos.y, window->Size.x, window->Size.y, window->ContentSize.x, window->ContentSize.y);
@@ -10232,6 +10250,38 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1023210250
}
1023310251
};
1023410252

10253+
10254+
// Tools
10255+
if (ImGui::TreeNode("Tools"))
10256+
{
10257+
// The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
10258+
if (ImGui::Button("Item Picker.."))
10259+
ImGui::DebugStartItemPicker();
10260+
ImGui::SameLine();
10261+
MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash.");
10262+
10263+
ImGui::Checkbox("Show windows begin order", &show_windows_begin_order);
10264+
ImGui::Checkbox("Show windows rectangles", &show_windows_rects);
10265+
ImGui::SameLine();
10266+
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12);
10267+
show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count, WRT_Count);
10268+
if (show_windows_rects && g.NavWindow)
10269+
{
10270+
ImGui::BulletText("'%s':", g.NavWindow->Name);
10271+
ImGui::Indent();
10272+
for (int rect_n = 0; rect_n < WRT_Count; rect_n++)
10273+
{
10274+
ImRect r = Funcs::GetWindowRect(g.NavWindow, rect_n);
10275+
ImGui::Text("(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) %s", r.Min.x, r.Min.y, r.Max.x, r.Max.y, r.GetWidth(), r.GetHeight(), wrt_rects_names[rect_n]);
10276+
}
10277+
ImGui::Unindent();
10278+
}
10279+
ImGui::Checkbox("Show mesh when hovering ImDrawCmd", &show_drawcmd_mesh);
10280+
ImGui::Checkbox("Show bounding boxes when hovering ImDrawCmd", &show_drawcmd_aabb);
10281+
ImGui::TreePop();
10282+
}
10283+
10284+
// Contents
1023510285
Funcs::NodeWindows(g.Windows, "Windows");
1023610286
//Funcs::NodeWindows(g.WindowsFocusOrder, "WindowsFocusOrder");
1023710287
if (ImGui::TreeNode("DrawLists", "Active DrawLists (%d)", g.DrawDataBuilder.Layers[0].Size))
@@ -10302,35 +10352,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
1030210352
ImGui::TreePop();
1030310353
}
1030410354

10305-
// Tools
10306-
if (ImGui::TreeNode("Tools"))
10307-
{
10308-
// The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
10309-
if (ImGui::Button("Item Picker.."))
10310-
ImGui::DebugStartItemPicker();
10311-
ImGui::SameLine();
10312-
MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash.");
10313-
10314-
ImGui::Checkbox("Show windows begin order", &show_windows_begin_order);
10315-
ImGui::Checkbox("Show windows rectangles", &show_windows_rects);
10316-
ImGui::SameLine();
10317-
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 12);
10318-
show_windows_rects |= ImGui::Combo("##show_windows_rect_type", &show_windows_rect_type, wrt_rects_names, WRT_Count, WRT_Count);
10319-
if (show_windows_rects && g.NavWindow)
10320-
{
10321-
ImGui::BulletText("'%s':", g.NavWindow->Name);
10322-
ImGui::Indent();
10323-
for (int rect_n = 0; rect_n < WRT_Count; rect_n++)
10324-
{
10325-
ImRect r = Funcs::GetWindowRect(g.NavWindow, rect_n);
10326-
ImGui::Text("(%6.1f,%6.1f) (%6.1f,%6.1f) Size (%6.1f,%6.1f) %s", r.Min.x, r.Min.y, r.Max.x, r.Max.y, r.GetWidth(), r.GetHeight(), wrt_rects_names[rect_n]);
10327-
}
10328-
ImGui::Unindent();
10329-
}
10330-
ImGui::Checkbox("Show details when hovering ImDrawCmd node", &show_drawcmd_details);
10331-
ImGui::TreePop();
10332-
}
10333-
1033410355
// Overlay: Display windows Rectangles and Begin Order
1033510356
if (show_windows_rects || show_windows_begin_order)
1033610357
{

0 commit comments

Comments
 (0)