@@ -9990,7 +9990,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
9990
9990
static bool show_windows_begin_order = false ;
9991
9991
static bool show_tables_rects = false ;
9992
9992
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 ;
9994
9995
9995
9996
// Basic info
9996
9997
ImGuiContext& g = *GImGui;
@@ -10024,6 +10025,38 @@ void ImGui::ShowMetricsWindow(bool* p_open)
10024
10025
return ImRect ();
10025
10026
}
10026
10027
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
+
10027
10060
static void NodeDrawList (ImGuiWindow* window, ImDrawList* draw_list, const char * label)
10028
10061
{
10029
10062
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)
10061
10094
pcmd->ElemCount /3 , (void *)(intptr_t )pcmd->TextureId ,
10062
10095
pcmd->ClipRect .x , pcmd->ClipRect .y , pcmd->ClipRect .z , pcmd->ClipRect .w );
10063
10096
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);
10073
10099
if (!pcmd_node_open)
10074
10100
continue ;
10075
10101
@@ -10087,22 +10113,8 @@ void ImGui::ShowMetricsWindow(bool* p_open)
10087
10113
// Display vertex information summary. Hover to get all triangles drawn in wire-frame
10088
10114
ImFormatString (buf, IM_ARRAYSIZE (buf), " Mesh: ElemCount: %d, VtxOffset: +%d, IdxOffset: +%d, Area: ~%0.f px" , pcmd->ElemCount , pcmd->VtxOffset , pcmd->IdxOffset , total_area);
10089
10115
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 );
10106
10118
10107
10119
// Display individual triangles/vertices. Hover on to get the corresponding triangle highlighted.
10108
10120
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)
10168
10180
ImGui::GetForegroundDrawList ()->AddRect (window->Pos , window->Pos + window->Size , IM_COL32 (255 , 255 , 0 , 255 ));
10169
10181
if (!open)
10170
10182
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
+
10171
10189
ImGuiWindowFlags flags = window->Flags ;
10172
10190
NodeDrawList (window, window->DrawList , " DrawList" );
10173
10191
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)
10232
10250
}
10233
10251
};
10234
10252
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.\n Warning: 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
10235
10285
Funcs::NodeWindows (g.Windows , " Windows" );
10236
10286
// Funcs::NodeWindows(g.WindowsFocusOrder, "WindowsFocusOrder");
10237
10287
if (ImGui::TreeNode (" DrawLists" , " Active DrawLists (%d)" , g.DrawDataBuilder .Layers [0 ].Size ))
@@ -10302,35 +10352,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
10302
10352
ImGui::TreePop ();
10303
10353
}
10304
10354
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.\n Warning: 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
-
10334
10355
// Overlay: Display windows Rectangles and Begin Order
10335
10356
if (show_windows_rects || show_windows_begin_order)
10336
10357
{
0 commit comments