editor window

This commit is contained in:
ouczbs 2024-12-17 20:57:52 +08:00
parent 5c695160d3
commit 99803e7391
17 changed files with 163 additions and 39 deletions

View File

@ -1,4 +1,5 @@
add_requires("spdlog", "libsdl", "vulkansdk","shaderc","spirv","spirv-cross")
add_requires("spdlog", "vulkansdk","shaderc","spirv","spirv-cross")
add_requires("mimalloc", {configs = {shared = true, debug = true, copy = true}})
add_requires("imgui",{configs = {shared = true, debug = true, copy = true}})
add_requires("libsdl",{configs = {shared = true}})
includes("*/xmake.lua")

View File

@ -0,0 +1,8 @@
#pragma once
#include "render/editor_system.h"
namespace api {
class AssetPreviewPanel : public EditorPanel{
public:
void DrawPanel() override;
};
}

View File

@ -0,0 +1,8 @@
#pragma once
#include "render/editor_system.h"
namespace api {
class MenuBarPanel : public EditorPanel {
public:
void DrawPanel() override;
};
}

View File

@ -0,0 +1,9 @@
#pragma once
#include "render/editor_system.h"
namespace api {
class EditorMainWindow : public EditorWindow {
public:
EditorMainWindow();
void Draw() override;
};
}

View File

@ -5,3 +5,4 @@ static_component("asset","engine")
add_headerfiles("include/**.h","include/**.inl")
add_files("src/**.cpp")
add_deps("core", "zlib")
add_syslinks("Ole32",{public = true})

View File

@ -1,10 +1,10 @@
#include "render/renderapi.h"
#include "render/module.h"
#ifdef WITH_EDITOR
#include "render/imgui_system.h"
#include "render/editor_system.h"
namespace api {
SINGLETON_DEFINE(ImguiSystem)
ImguiSystem::ImguiSystem()
SINGLETON_DEFINE(EditorSystem)
EditorSystem::EditorSystem()
{
SINGLETON_PTR();
}

View File

@ -0,0 +1,40 @@
#pragma once
#ifdef WITH_EDITOR
#include "module/module_manager.h"
namespace api {
class EditorPanel {
public:
EditorPanel() = default;
~EditorPanel() = default;
virtual void DrawPanel() = 0;
};
class EditorWindow {
protected:
std::vector<EditorPanel*> mPanels;
public:
EditorWindow() = default;
~EditorWindow() = default;
virtual void Draw() = 0;
template<typename T, typename ... Args>
T* AddPanel(Args&&... args) {
T* ptr = new (GlobalPool()) T(std::forward<Args>(args)...);
mPanels.push_back(ptr);
return ptr;
}
};
class RENDER_API EditorSystem : public ISystem
{
SINGLETON_IMPL(EditorSystem)
protected:
std::vector<EditorWindow*> mWindows;
public:
EditorSystem();
template<typename T, typename ... Args>
T* AddWindow(Args&&... args) {
T* ptr = new (GlobalPool()) T(std::forward<Args>(args)...);
mWindows.push_back(ptr);
return ptr;
}
};
}
#endif // WITH_EDITOR

View File

@ -1,12 +0,0 @@
#pragma once
#ifdef WITH_EDITOR
#include "module/module_manager.h"
namespace api {
class RENDER_API ImguiSystem : public ISystem
{
SINGLETON_IMPL(ImguiSystem)
public:
ImguiSystem();
};
}
#endif // WITH_EDITOR

View File

@ -1,14 +1,18 @@
#pragma once
#include "render/imgui_system.h"
#include "render/editor_system.h"
#include "render/graph/frame_graph.h"
namespace vkn {
using api::FrameGraph;
using api::RenderPassContext;
class VulkanImguiSystem : public api::ImguiSystem {
class VulkanImguiEditor : public api::EditorSystem {
public:
void Initialize() override;
void Finalize() override;
void Render();
void OnBeginRenderFrame();
static VulkanImguiEditor* Ptr() {
return (VulkanImguiEditor*)api::EditorSystem::Ptr();
};
static void Setup(FrameGraph& graph, FrameGraph::RenderPassBuilder& builder);
static void Execute(FrameGraph&, RenderPassContext&);
};

View File

@ -1,6 +1,6 @@
#include "xmalloc_new_delete.h"
#include "vkn/module.h"
#include "vkn/vulkan_imgui.h"
#include "vkn/vulkan_imgui_editor.h"
#include "vkn/loader/vulkan_glsl_loader.h"
#include "pmr/frame_allocator.h"
using namespace vkn;
@ -8,7 +8,7 @@ void VulkanModule::OnLoad(int argc, char** argv)
{
VulkanGlslLoader::Init();
#ifdef WITH_EDITOR
AddSystem<VulkanImguiSystem>();
AddSystem<VulkanImguiEditor>();
#endif // WITH_EDITOR
}

View File

@ -1,4 +1,4 @@
#include "vkn/vulkan_imgui.h"
#include "vkn/vulkan_imgui_editor.h"
#include "vkn/vulkan_window.h"
#include "vkn/vulkan_api.h"
#include "vkn/vulkan_api_help.h"
@ -14,6 +14,7 @@ namespace vkn {
using namespace api;
static Name ImguiPassName{"ImguiPass"};
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
// Vulkan的ImGui接入比较麻烦参考教程: https://frguthmann.github.io/posts/vulkan_imgui/
VkDescriptorPool CreateDescriptorPool(VkDevice device) {
VkDescriptorPoolSize pool_sizes[] =
{
@ -80,7 +81,7 @@ namespace vkn {
throw std::runtime_error("Could not create Dear ImGui's render pass");
return renderPass;
}
void VulkanImguiSystem::Initialize()
void VulkanImguiEditor::Initialize()
{
VulkanAPI* API = VulkanAPI::Ptr();
VulkanWindow* window = VulkanWindow::Ptr();
@ -105,18 +106,24 @@ namespace vkn {
init_info.Allocator = VK_NULL_HANDLE;
ImGui_ImplVulkan_Init(&init_info);
API->SetRenderPassInfo(ImguiPassName, renderPass);
EventSystem::Ptr()->BeginRenderFrame.Subscribe(&VulkanImguiSystem::Render, this);
EventSystem::Ptr()->BeginRenderFrame.Subscribe(&VulkanImguiEditor::OnBeginRenderFrame, this);
}
void VulkanImguiSystem::Finalize()
void VulkanImguiEditor::Finalize()
{
}
void VulkanImguiSystem::Render()
void VulkanImguiEditor::Render()
{
VulkanAPI::Ptr()->graph.AddRenderPass<VulkanImguiSystem>();
for (auto win : mWindows)
{
win->Draw();
}
void VulkanImguiSystem::Setup(FrameGraph& graph, FrameGraph::RenderPassBuilder& builder)
}
void VulkanImguiEditor::OnBeginRenderFrame()
{
VulkanAPI::Ptr()->graph.AddRenderPass<VulkanImguiEditor>();
}
void VulkanImguiEditor::Setup(FrameGraph& graph, FrameGraph::RenderPassBuilder& builder)
{
AttachmentDesc surface{};
surface.FromTexture(graph.mSurface);
@ -127,17 +134,14 @@ namespace vkn {
.Type(RenderPassNodeType::Imgui, RenderPassNodeFlag::Output)
.Write(edge, ResourceState::COLOR_ATTACHMENT);
}
void VulkanImguiSystem::Execute(FrameGraph& graph, RenderPassContext& context)
void VulkanImguiEditor::Execute(FrameGraph& graph, RenderPassContext& context)
{
graph.mSurface.state = ResourceState::PRESENT;
ImGui_ImplVulkan_NewFrame();
ImGui_ImplSDL2_NewFrame();
ImGui::NewFrame();
static float my_float = 0.5f;
ImGui::Begin("Hello, ImGui!");
ImGui::Text("This is some useful text.");
ImGui::SliderFloat("float", &my_float, 0.0f, 1.0f);
ImGui::End();
VulkanImguiEditor::Ptr()->Render();
ImGui::Render();
VulkanContext& ctx = *(VulkanContext*)context.parent;

View File

@ -2,6 +2,7 @@
#include "data/global.h"
#include "render/window.h"
#include "render/renderapi.h"
#include "editor/window/editor_main_window.h"
#include "imgui.h"
namespace api {
void EditorModule::OnLoad(int argc, char** argv)
@ -20,6 +21,7 @@ namespace api {
}
void EditorModule::Initialize(void)
{
EditorSystem* Editor = EditorSystem::Ptr();
Editor->AddWindow<EditorMainWindow>();
}
}

View File

@ -0,0 +1,9 @@
#include "editor/panel/asset_preview_panel.h"
#include <imgui.h>
namespace api {
void AssetPreviewPanel::DrawPanel() {
static float my_float = 0.5f;
ImGui::Text("This is some useful text.");
ImGui::SliderFloat("float", &my_float, 0.0f, 1.0f);
}
}

View File

@ -0,0 +1,25 @@
#include "editor/panel/menu_bar_panel.h"
#include <imgui.h>
namespace api {
void MenuBarPanel::DrawPanel()
{
// 面板大小和位置
if (ImGui::BeginMenu("Tools")) {
if (ImGui::MenuItem("Performance Analyzer")) {
// 显示性能分析工具
}
if (ImGui::MenuItem("Debug Console")) {
// 显示调试控制台
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help")) {
if (ImGui::MenuItem("About")) {
// 显示关于信息
}
ImGui::EndMenu();
}
}
}

View File

@ -0,0 +1,19 @@
#include "editor/window/editor_main_window.h"
#include "editor/panel/asset_preview_panel.h"
#include "editor/panel/menu_bar_panel.h"
#include <imgui.h>
namespace api {
EditorMainWindow::EditorMainWindow()
{
AddPanel<MenuBarPanel>();
AddPanel<AssetPreviewPanel>();
}
void EditorMainWindow::Draw()
{
ImGui::Begin("MainWindow");
for (auto panel : mPanels) {
panel->DrawPanel();
}
ImGui::End();
}
}

View File

@ -6,14 +6,14 @@ target("engine")
set_kind("shared")
set_group("Engine")
add_rules("engine.api")
add_files("src/engine/*.cpp")
add_files("src/engine/**.cpp")
target("editor")
set_kind("shared")
set_group("Engine")
add_rules("engine.api")
add_headerfiles("include/editor/*.h")
add_headerfiles("include/editor/**.h")
add_includedirs("include")
add_files("src/editor/*.cpp")
add_files("src/editor/**.cpp")
add_deps("engine",{public = true})
includes("xmake/xmake.lua")
includes("3rdparty/xmake.lua")

View File

@ -10,5 +10,11 @@ ViewportId=0x41ACA57A
Size=191,71
Collapsed=0
[Window][MainWindow]
ViewportPos=480,240
ViewportId=0x72FC8CA3
Size=191,105
Collapsed=0
[Docking][Data]