diff --git a/examples/testbed/framework/main.cpp b/examples/testbed/framework/main.cpp index 4c68c4e..03dcebd 100644 --- a/examples/testbed/framework/main.cpp +++ b/examples/testbed/framework/main.cpp @@ -124,6 +124,11 @@ static void Run() g_profiler->EndScope(); + if (g_settings->drawProfileTree) + { + g_view->InterfaceProfileTree(); + } + g_profilerRecorder->BuildRecords(); if (g_settings->drawProfile) diff --git a/examples/testbed/framework/profiler.h b/examples/testbed/framework/profiler.h index d87ed3e..7c27dac 100644 --- a/examples/testbed/framework/profiler.h +++ b/examples/testbed/framework/profiler.h @@ -58,6 +58,9 @@ public: // End the top scope. void EndScope(); + + // Get the root profiler node. + ProfilerNode* GetRoot() { return m_root; } private: friend class ProfilerRecorder; diff --git a/examples/testbed/framework/view.cpp b/examples/testbed/framework/view.cpp index d2d68dc..adaea83 100644 --- a/examples/testbed/framework/view.cpp +++ b/examples/testbed/framework/view.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #if defined (U_OPENGL_2) @@ -218,6 +219,7 @@ void View::Interface() if (ImGui::BeginMenu("View")) { ImGui::MenuItem("Profile", "", &settings.drawProfile); + ImGui::MenuItem("Profile Tree", "", &settings.drawProfileTree); ImGui::MenuItem("Statistics", "", &settings.drawStats); ImGui::Separator(); @@ -400,6 +402,53 @@ void View::Interface() ImGui::End(); } +static void TreeNode(ProfilerNode* node, u32& index) +{ + ImGui::PushID(index); + ++index; + + if (ImGui::TreeNode(node->name)) + { + float64 elapsedTime = node->t1 - node->t0; + ImGui::Text("%.4f [ms]", elapsedTime); + + for (u32 i = 0; i < node->children.Count(); ++i) + { + TreeNode(node->children[i], index); + } + ImGui::TreePop(); + } + + ImGui::PopID(); +} + +void View::InterfaceProfileTree() +{ + ImGui::Begin("Overlay", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar); + ImVec2 ws = ImGui::GetWindowSize(); + ImVec2 wp = ImGui::GetWindowPos(); + ImGui::End(); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + + ImGui::SetNextWindowBgAlpha(0.0f); + ImGui::SetNextWindowPos(ImVec2(0.0f, wp.y + ws.y)); + ImGui::SetNextWindowSize(ImVec2(g_camera->m_width - 250.0f, 0.0f)); + + ImGui::Begin("##ProfileTree", NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize); + + ProfilerNode* root = g_profiler->GetRoot(); + if (root) + { + u32 index = 0; + TreeNode(root, index); + } + + ImGui::End(); + + ImGui::PopStyleVar(); +} + void View::EndInterface() { ImGui::PopStyleVar(); diff --git a/examples/testbed/framework/view.h b/examples/testbed/framework/view.h index edb0be1..2650e81 100644 --- a/examples/testbed/framework/view.h +++ b/examples/testbed/framework/view.h @@ -41,6 +41,7 @@ public: void BeginInterface(); void Interface(); + void InterfaceProfileTree(); void EndInterface(); private: friend class ViewModel; diff --git a/examples/testbed/framework/view_model.h b/examples/testbed/framework/view_model.h index 8b10a0c..2d133ef 100644 --- a/examples/testbed/framework/view_model.h +++ b/examples/testbed/framework/view_model.h @@ -33,6 +33,7 @@ struct Settings drawTriangles = true; drawGrid = true; drawProfile = false; + drawProfileTree = false; drawStats = false; } @@ -43,6 +44,7 @@ struct Settings bool drawTriangles; bool drawGrid; bool drawProfile; + bool drawProfileTree; bool drawStats; };