editor
This commit is contained in:
parent
c62b63d0b9
commit
a362258a03
12
engine/modules/engine/render/include/render/imgui_system.h
Normal file
12
engine/modules/engine/render/include/render/imgui_system.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifdef WITH_EDITOR
|
||||||
|
#include "module/module_manager.h"
|
||||||
|
namespace api {
|
||||||
|
class RENDER_API ImguiSystem : public ISystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// 渲染开始和结束
|
||||||
|
// virtual void BeginFrame() = 0;
|
||||||
|
// virtual void EndFrame(void* command_buffer) = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // WITH_EDITOR
|
||||||
@ -7,4 +7,8 @@ static_component("render","engine")
|
|||||||
add_files("src/**.cpp")
|
add_files("src/**.cpp")
|
||||||
add_deps("asset", "zlib", "core")
|
add_deps("asset", "zlib", "core")
|
||||||
add_syslinks("user32", {public = true})
|
add_syslinks("user32", {public = true})
|
||||||
add_packages("lemon", "libsdl","shaderc","spirv-cross", {public = true})
|
add_packages("lemon", "libsdl","shaderc","spirv-cross", {public = true})
|
||||||
|
if WITH_EDITOR then
|
||||||
|
add_defines("WITH_EDITOR", {public = true})
|
||||||
|
add_packages("imgui",{public = true})
|
||||||
|
end
|
||||||
9
engine/modules/render/vulkan/include/vkn/vulkan_imgui.h
Normal file
9
engine/modules/render/vulkan/include/vkn/vulkan_imgui.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "render/imgui_system.h"
|
||||||
|
namespace vkn {
|
||||||
|
class VulkanImguiSystem : public api::ImguiSystem {
|
||||||
|
void Initialize() override;
|
||||||
|
void Finalize() override;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
74
engine/modules/render/vulkan/src/vulkan_imgui.cpp
Normal file
74
engine/modules/render/vulkan/src/vulkan_imgui.cpp
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include "vkn/vulkan_imgui.h"
|
||||||
|
#include "vkn/vulkan_api.h"
|
||||||
|
#include "vkn/vulkan_api_help.h"
|
||||||
|
#include "vkn/backend.h"
|
||||||
|
#include "vkn/wrapper/device.h"
|
||||||
|
#include "vkn/wrapper/instance.h"
|
||||||
|
#include "vkn/wrapper/queue.h"
|
||||||
|
#include "render/window.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
#include "backends/imgui_impl_sdl2.h"
|
||||||
|
#include "backends/imgui_impl_vulkan.h"
|
||||||
|
#include "tinyimageformat/tinyimageformat_apis.h"
|
||||||
|
namespace vkn {
|
||||||
|
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
||||||
|
void CreateDescriptorPool(VkDevice device, VkDescriptorPool& descriptorPool) {
|
||||||
|
VkDescriptorPoolSize pool_sizes[] =
|
||||||
|
{
|
||||||
|
{ VK_DESCRIPTOR_TYPE_SAMPLER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000 },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000 }
|
||||||
|
};
|
||||||
|
VkDescriptorPoolCreateInfo pool_info = {};
|
||||||
|
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
|
pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||||
|
pool_info.maxSets = 1000 * IM_ARRAYSIZE(pool_sizes);
|
||||||
|
pool_info.poolSizeCount = (uint32_t)IM_ARRAYSIZE(pool_sizes);
|
||||||
|
pool_info.pPoolSizes = pool_sizes;
|
||||||
|
VkResult err = vkCreateDescriptorPool(device, &pool_info, VK_NULL_HANDLE, &descriptorPool);
|
||||||
|
}
|
||||||
|
void CreateRenderPass(VulkanAPI* API) {
|
||||||
|
RenderPassKey config{};
|
||||||
|
config.colorFormat[0] = (VkFormat)TinyImageFormat_ToVkFormat(API->context.surface.format);
|
||||||
|
config.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
|
}
|
||||||
|
void VulkanImguiSystem::Initialize()
|
||||||
|
{
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // 可选:启用键盘导航
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // 可选:启用Docking
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // 可选:启用多视口
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
|
ImGui_ImplSDL2_InitForVulkan(api::Window::Ptr()->GetPtr());
|
||||||
|
Backend& backend = VulkanAPI::Ptr()->GetBackend();
|
||||||
|
Queue* pQueue = backend.GetDevice().GetQueue(Queue::RenderQueue);
|
||||||
|
CreateDescriptorPool(backend.GetDevice().Ptr(), g_DescriptorPool);
|
||||||
|
ImGui_ImplVulkan_InitInfo init_info = {};
|
||||||
|
init_info.Instance = backend.GetInstance().Ptr();
|
||||||
|
init_info.PhysicalDevice = backend.GetDevice().GetPhysical();
|
||||||
|
init_info.Device = backend.GetDevice().Ptr();
|
||||||
|
init_info.QueueFamily = pQueue->QueueFamilyIndex();
|
||||||
|
init_info.Queue = pQueue->Ptr();
|
||||||
|
init_info.DescriptorPool = g_DescriptorPool;
|
||||||
|
init_info.MinImageCount = 2;
|
||||||
|
init_info.ImageCount = swapchainImageCount;
|
||||||
|
|
||||||
|
ImGui_ImplVulkan_Init(&init_info, renderPass);
|
||||||
|
}
|
||||||
|
void VulkanImguiSystem::Finalize()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
#include "editor/editor.h"
|
#include "editor/editor.h"
|
||||||
#include "data/global.h"
|
#include "data/global.h"
|
||||||
#include "imgui.h"
|
#include "render/window.h"
|
||||||
|
#include "render/renderapi.h"
|
||||||
namespace api {
|
namespace api {
|
||||||
void EditorModule::OnLoad(int argc, char** argv)
|
void EditorModule::OnLoad(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@ -12,15 +13,6 @@ namespace api {
|
|||||||
}
|
}
|
||||||
void EditorModule::Initialize(void)
|
void EditorModule::Initialize(void)
|
||||||
{
|
{
|
||||||
IDynamicModule::Initialize();
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
ImGui::CreateContext();
|
|
||||||
ImGui::StyleColorsDark();
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // 可选:启用键盘导航
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // 可选:启用Docking
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // 可选:启用多视口
|
|
||||||
if (gEngineConfig.API == GraphicsAPI::Vulkan) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
WITH_EDITOR = true
|
||||||
target("engine")
|
target("engine")
|
||||||
add_defines("ENGINE_ROOT="..os.curdir():gsub("\\", "\\\\"),{public = false})
|
add_defines("ENGINE_ROOT="..os.curdir():gsub("\\", "\\\\"),{public = false})
|
||||||
add_headerfiles("include/*.natvis")
|
add_headerfiles("include/*.natvis")
|
||||||
@ -13,8 +14,6 @@ target("editor")
|
|||||||
add_headerfiles("include/editor/*.h")
|
add_headerfiles("include/editor/*.h")
|
||||||
add_includedirs("include")
|
add_includedirs("include")
|
||||||
add_files("src/editor/*.cpp")
|
add_files("src/editor/*.cpp")
|
||||||
add_defines("WITH_EDITOR", {public = true})
|
|
||||||
add_packages("imgui",{public = true})
|
|
||||||
add_deps("engine",{public = true})
|
add_deps("engine",{public = true})
|
||||||
includes("xmake/xmake.lua")
|
includes("xmake/xmake.lua")
|
||||||
includes("3rdparty/xmake.lua")
|
includes("3rdparty/xmake.lua")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user