MCPcopy Create free account
hub / github.com/Raais/ImStudio / DebugNodeDrawList

Method DebugNodeDrawList

src/third-party/imgui/imgui.cpp:12519–12610  ·  view source on GitHub ↗

[DEBUG] Display contents of ImDrawList

Source from the content-addressed store, hash-verified

12517
12518// [DEBUG] Display contents of ImDrawList
12519void ImGui::DebugNodeDrawList(ImGuiWindow* window, const ImDrawList* draw_list, const char* label)
12520{
12521 ImGuiContext& g = *GImGui;
12522 ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
12523 int cmd_count = draw_list->CmdBuffer.Size;
12524 if (cmd_count > 0 && draw_list->CmdBuffer.back().ElemCount == 0 && draw_list->CmdBuffer.back().UserCallback == NULL)
12525 cmd_count--;
12526 bool node_open = 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, cmd_count);
12527 if (draw_list == GetWindowDrawList())
12528 {
12529 SameLine();
12530 TextColored(ImVec4(1.0f, 0.4f, 0.4f, 1.0f), "CURRENTLY APPENDING"); // Can't display stats for active draw list! (we don't have the data double-buffered)
12531 if (node_open)
12532 TreePop();
12533 return;
12534 }
12535
12536 ImDrawList* fg_draw_list = GetForegroundDrawList(window); // Render additional visuals into the top-most draw list
12537 if (window && IsItemHovered() && fg_draw_list)
12538 fg_draw_list->AddRect(window->Pos, window->Pos + window->Size, IM_COL32(255, 255, 0, 255));
12539 if (!node_open)
12540 return;
12541
12542 if (window && !window->WasActive)
12543 TextDisabled("Warning: owning Window is inactive. This DrawList is not being rendered!");
12544
12545 for (const ImDrawCmd* pcmd = draw_list->CmdBuffer.Data; pcmd < draw_list->CmdBuffer.Data + cmd_count; pcmd++)
12546 {
12547 if (pcmd->UserCallback)
12548 {
12549 BulletText("Callback %p, user_data %p", pcmd->UserCallback, pcmd->UserCallbackData);
12550 continue;
12551 }
12552
12553 char buf[300];
12554 ImFormatString(buf, IM_ARRAYSIZE(buf), "DrawCmd:%5d tris, Tex 0x%p, ClipRect (%4.0f,%4.0f)-(%4.0f,%4.0f)",
12555 pcmd->ElemCount / 3, (void*)(intptr_t)pcmd->TextureId,
12556 pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w);
12557 bool pcmd_node_open = TreeNode((void*)(pcmd - draw_list->CmdBuffer.begin()), "%s", buf);
12558 if (IsItemHovered() && (cfg->ShowDrawCmdMesh || cfg->ShowDrawCmdBoundingBoxes) && fg_draw_list)
12559 DebugNodeDrawCmdShowMeshAndBoundingBox(fg_draw_list, draw_list, pcmd, cfg->ShowDrawCmdMesh, cfg->ShowDrawCmdBoundingBoxes);
12560 if (!pcmd_node_open)
12561 continue;
12562
12563 // Calculate approximate coverage area (touched pixel count)
12564 // This will be in pixels squared as long there's no post-scaling happening to the renderer output.
12565 const ImDrawIdx* idx_buffer = (draw_list->IdxBuffer.Size > 0) ? draw_list->IdxBuffer.Data : NULL;
12566 const ImDrawVert* vtx_buffer = draw_list->VtxBuffer.Data + pcmd->VtxOffset;
12567 float total_area = 0.0f;
12568 for (unsigned int idx_n = pcmd->IdxOffset; idx_n < pcmd->IdxOffset + pcmd->ElemCount; )
12569 {
12570 ImVec2 triangle[3];
12571 for (int n = 0; n < 3; n++, idx_n++)
12572 triangle[n] = vtx_buffer[idx_buffer ? idx_buffer[idx_n] : idx_n].pos;
12573 total_area += ImTriangleArea(triangle[0], triangle[1], triangle[2]);
12574 }
12575
12576 // Display vertex information summary. Hover to get all triangles drawn in wire-frame

Callers

nothing calls this directly

Calls 9

ImVec4Class · 0.85
GetForegroundDrawListFunction · 0.85
ImFormatStringFunction · 0.85
ImTriangleAreaFunction · 0.85
AddRectMethod · 0.80
BeginMethod · 0.80
AddPolylineMethod · 0.80
beginMethod · 0.45
StepMethod · 0.45

Tested by

no test coverage detected