2025-05-18 17:42:48 +00:00
|
|
|
//
|
|
|
|
// Created by spenc on 5/18/2025.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Editor.h"
|
2025-05-18 18:29:55 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <imgui_impl_opengl3.h>
|
|
|
|
#include <imgui_impl_glfw.h>
|
2025-05-21 02:42:18 +00:00
|
|
|
|
2025-05-21 15:16:46 +00:00
|
|
|
#include "Windows/LoggerWindow.h"
|
|
|
|
#include "Windows/Viewport.h"
|
2025-05-21 16:49:17 +00:00
|
|
|
#include "Windows/FileBrowser.h"
|
2025-05-21 02:42:18 +00:00
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
namespace OX
|
|
|
|
{
|
|
|
|
void Editor::Init(Core &core)
|
2025-05-18 17:42:48 +00:00
|
|
|
{
|
2025-05-18 18:29:55 +00:00
|
|
|
Logger::LogInfo("%s Init", m_name.c_str());
|
|
|
|
|
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
ImGui::CreateContext();
|
2025-05-21 16:34:23 +00:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
2025-05-18 18:29:55 +00:00
|
|
|
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
|
|
|
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
2025-05-18 18:29:55 +00:00
|
|
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
|
|
|
|
style.WindowRounding = 5.0f;
|
|
|
|
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui_ImplGlfw_InitForOpenGL(core.GetWindow().GetHandle(), true);
|
|
|
|
ImGui_ImplOpenGL3_Init("#version 330 core");
|
2025-05-21 15:16:46 +00:00
|
|
|
|
2025-05-21 21:38:18 +00:00
|
|
|
primaryViewport = new Viewport(); // The first time ive ever use the new keyword...
|
|
|
|
fileBrowser = new FileBrowser();
|
2025-05-18 17:42:48 +00:00
|
|
|
}
|
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
void Editor::Update(Core &core)
|
2025-05-18 17:42:48 +00:00
|
|
|
{
|
2025-05-18 18:29:55 +00:00
|
|
|
OX_PROFILE_FUNCTION();
|
2025-05-18 17:42:48 +00:00
|
|
|
}
|
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
void Editor::Draw(Core &core)
|
2025-05-18 17:42:48 +00:00
|
|
|
{
|
2025-05-18 18:29:55 +00:00
|
|
|
OX_PROFILE_FUNCTION();
|
|
|
|
|
|
|
|
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
|
|
|
|
|
|
|
// === Main Docking Space ===
|
2025-05-21 16:34:23 +00:00
|
|
|
ImGuiWindowFlags windowFlags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking |
|
|
|
|
ImGuiWindowFlags_NoBackground;
|
2025-05-18 18:29:55 +00:00
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
const ImGuiViewport *viewport = ImGui::GetMainViewport();
|
2025-05-18 18:29:55 +00:00
|
|
|
ImGui::SetNextWindowPos(viewport->WorkPos);
|
|
|
|
ImGui::SetNextWindowSize(viewport->WorkSize);
|
|
|
|
ImGui::SetNextWindowViewport(viewport->ID);
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
2025-05-21 16:07:23 +00:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
2025-05-18 18:29:55 +00:00
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
2025-05-21 16:34:23 +00:00
|
|
|
windowFlags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
|
|
|
|
ImGuiWindowFlags_NoMove;
|
2025-05-18 18:29:55 +00:00
|
|
|
windowFlags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
|
|
|
|
|
|
|
|
ImGui::Begin("DockSpace Root", nullptr, windowFlags);
|
2025-05-21 16:07:23 +00:00
|
|
|
ImGui::PopStyleVar(3);
|
2025-05-18 18:29:55 +00:00
|
|
|
|
|
|
|
ImGuiID dockspaceID = ImGui::GetID("MyDockSpace");
|
|
|
|
ImGui::DockSpace(dockspaceID, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode);
|
|
|
|
|
|
|
|
LoggerWindow::Draw();
|
2025-05-21 21:38:18 +00:00
|
|
|
fileBrowser->Draw();
|
2025-05-21 15:16:46 +00:00
|
|
|
primaryViewport->Draw(core);
|
2025-05-18 18:29:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Profiler");
|
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
const auto &tree = Profiler::GetSavedTree();
|
2025-05-18 18:29:55 +00:00
|
|
|
if (tree.empty()) {
|
|
|
|
ImGui::Text("No samples yet.");
|
|
|
|
} else {
|
2025-05-21 16:34:23 +00:00
|
|
|
if (ImGui::BeginTable("ProfilerTable", 3,
|
|
|
|
ImGuiTableFlags_Resizable | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersInnerV)) {
|
|
|
|
ImGui::TableSetupColumn("Section");
|
|
|
|
ImGui::TableSetupColumn("Calls", ImGuiTableColumnFlags_WidthFixed, 60.0f);
|
|
|
|
ImGui::TableSetupColumn("Total Time (ms)", ImGuiTableColumnFlags_WidthFixed, 120.0f);
|
|
|
|
ImGui::TableHeadersRow();
|
|
|
|
|
|
|
|
std::function<void(const Profiler::SavedSample &)> DrawNode;
|
|
|
|
DrawNode = [&](const Profiler::SavedSample &node)
|
|
|
|
{
|
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
|
|
|
// === Section name with Tree UI ===
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
|
|
|
|
// Color based on total time
|
|
|
|
ImVec4 color;
|
|
|
|
if (node.totalTime > 10.0f) color = ImVec4(1.0f, 0.2f, 0.2f, 1.0f); // red
|
|
|
|
else if (node.totalTime > 5.0f) color = ImVec4(1.0f, 0.5f, 0.0f, 1.0f); // orange
|
|
|
|
else if (node.totalTime > 1.0f) color = ImVec4(1.0f, 1.0f, 0.0f, 1.0f); // yellow
|
|
|
|
else color = ImVec4(0.4f, 1.0f, 0.4f, 1.0f); // green
|
|
|
|
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, color);
|
|
|
|
bool open = ImGui::TreeNodeEx(node.name.c_str(),
|
|
|
|
ImGuiTreeNodeFlags_SpanAllColumns | ImGuiTreeNodeFlags_DefaultOpen);
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
|
|
|
|
// === Call count ===
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("%d", node.callCount);
|
|
|
|
|
|
|
|
// === Total time ===
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("%.2f", node.totalTime);
|
|
|
|
|
|
|
|
// === Recurse if open ===
|
|
|
|
if (open) {
|
|
|
|
for (const auto &child: node.children) {
|
|
|
|
DrawNode(child);
|
|
|
|
}
|
|
|
|
ImGui::TreePop();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &root: tree) {
|
|
|
|
DrawNode(root);
|
2025-05-18 18:29:55 +00:00
|
|
|
}
|
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
ImGui::EndTable();
|
2025-05-18 18:29:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
|
2025-05-18 18:29:55 +00:00
|
|
|
ImGui::End(); // DockSpace Root
|
|
|
|
|
|
|
|
// --- Render ImGui onto FBO 0 ---
|
|
|
|
{
|
|
|
|
OX_PROFILE_LABEL("VSYNC Wait");
|
|
|
|
|
|
|
|
ImGui::EndFrame();
|
|
|
|
ImGui::Render();
|
|
|
|
ImGui::UpdatePlatformWindows();
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
}
|
2025-05-18 17:42:48 +00:00
|
|
|
}
|
|
|
|
|
2025-05-21 16:34:23 +00:00
|
|
|
void Editor::Shutdown(Core &core)
|
2025-05-18 17:42:48 +00:00
|
|
|
{
|
2025-05-21 15:16:46 +00:00
|
|
|
delete primaryViewport;
|
|
|
|
primaryViewport = nullptr;
|
|
|
|
|
2025-05-21 21:38:18 +00:00
|
|
|
delete fileBrowser;
|
|
|
|
fileBrowser = nullptr;
|
2025-05-21 15:16:46 +00:00
|
|
|
|
2025-05-18 17:42:48 +00:00
|
|
|
Logger::LogOk("Editor::Shutdown");
|
2025-05-18 18:29:55 +00:00
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplGlfw_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
2025-05-18 17:42:48 +00:00
|
|
|
}
|
2025-05-21 16:34:23 +00:00
|
|
|
} // OX
|