remove imgui
This commit is contained in:
parent
fcf226ff3f
commit
fdfc42ed8c
3
engine/3rdparty/xmake.lua
vendored
3
engine/3rdparty/xmake.lua
vendored
@ -1,5 +1,6 @@
|
||||
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("imgui",{configs = {shared = true, debug = true, copy = true}})
|
||||
add_requires("noesis",{configs = {shared = true, copy = true}})
|
||||
add_requires("libsdl",{configs = {shared = true}})
|
||||
includes("*/xmake.lua")
|
||||
@ -1,8 +1,4 @@
|
||||
#pragma once
|
||||
#include "render/editor_system.h"
|
||||
namespace api {
|
||||
class AssetPreviewPanel : public EditorPanel{
|
||||
public:
|
||||
void DrawPanel(FrameGraph& graph, RenderEditorContext& context) override;
|
||||
};
|
||||
|
||||
}
|
||||
@ -1,9 +1,4 @@
|
||||
#pragma once
|
||||
#include "render/editor_system.h"
|
||||
namespace api {
|
||||
class EditorMainWindow : public EditorWindow {
|
||||
public:
|
||||
EditorMainWindow();
|
||||
void Draw(FrameGraph& graph, RenderEditorContext& context) override;
|
||||
};
|
||||
|
||||
}
|
||||
@ -1,2 +1 @@
|
||||
#include "asset/module.h"
|
||||
#include "module/module_manager.h"
|
||||
@ -1,4 +1,4 @@
|
||||
#include "asset/module.h"
|
||||
#include "asset/asset_module.h"
|
||||
#include "asset/resource_system.h"
|
||||
#include "os/file_manager.h"
|
||||
#include "os/file_handle.h"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "asset/module.h"
|
||||
#include "asset/asset_module.h"
|
||||
#include "asset/resource_system.h"
|
||||
#include "asset/asset_loader.h"
|
||||
#include "archive/pch.h"
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,50 +0,0 @@
|
||||
// dear imgui: Platform Backend for SDL2
|
||||
// This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
|
||||
// (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.)
|
||||
|
||||
// Implemented features:
|
||||
// [X] Platform: Clipboard support.
|
||||
// [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen.
|
||||
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values are obsolete since 1.87 and not supported since 1.91.5]
|
||||
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
|
||||
// [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
|
||||
// [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
||||
// Issues:
|
||||
// [ ] Platform: Multi-viewport: Minimized windows seems to break mouse wheel events (at least under Windows).
|
||||
// [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor).
|
||||
// [x] Platform: Basic IME support. App needs to call 'SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");' before SDL_CreateWindow()!.
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
#pragma once
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
#ifndef IMGUI_DISABLE
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_Renderer;
|
||||
struct _SDL_GameController;
|
||||
typedef union SDL_Event SDL_Event;
|
||||
|
||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer);
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOther(SDL_Window* window);
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
|
||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
|
||||
|
||||
// Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. You may override this.
|
||||
// When using manual mode, caller is responsible for opening/closing gamepad.
|
||||
enum ImGui_ImplSDL2_GamepadMode { ImGui_ImplSDL2_GamepadMode_AutoFirst, ImGui_ImplSDL2_GamepadMode_AutoAll, ImGui_ImplSDL2_GamepadMode_Manual };
|
||||
IMGUI_IMPL_API void ImGui_ImplSDL2_SetGamepadMode(ImGui_ImplSDL2_GamepadMode mode, struct _SDL_GameController** manual_gamepads_array = NULL, int manual_gamepads_count = -1);
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
@ -1,14 +0,0 @@
|
||||
#include "render/editor_system.h"
|
||||
namespace api {
|
||||
SINGLETON_DEFINE(EditorSystem)
|
||||
EditorSystem::EditorSystem()
|
||||
{
|
||||
SINGLETON_PTR();
|
||||
}
|
||||
ImTextureID EditorSystem::AddTexture(FrameGraph& graph, TextureDesc& desc, TextureSampler key)
|
||||
{
|
||||
ImageViewPtr imageview = graph.ResolveTextureView(desc);
|
||||
SamplerPtr sampler = graph.ResolveTextureSampler(key);
|
||||
return AddTexture(imageview, sampler, desc.state);
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
#include "render/renderapi.h"
|
||||
#include "render/module.h"
|
||||
#include "render/render_module.h"
|
||||
namespace api {
|
||||
SINGLETON_DEFINE(RenderAPI)
|
||||
IMPLEMENT_STATIC_MODULE(RENDER_API, RenderModule, render);
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
#include "render/window.h"
|
||||
namespace api {
|
||||
SINGLETON_DEFINE(Window)
|
||||
inline Window::Window(CreatePFN createPFN, const Args& args, int width, int height) noexcept : mHeight(height), mWidth(width)
|
||||
inline Window::Window(const Args& args, int width, int height) noexcept : mHeight(height), mWidth(width)
|
||||
{
|
||||
SINGLETON_PTR();
|
||||
uint32_t windowFlags = args.windowFlags | SDL_WINDOW_SHOWN;
|
||||
windowFlags |= args.resizeable ? SDL_WINDOW_RESIZABLE : 0;
|
||||
windowFlags |= args.headless ? SDL_WINDOW_HIDDEN : 0;
|
||||
// Even if we're in headless mode, we still need to create a window, otherwise SDL will not poll events.
|
||||
mPtr = createPFN(args.title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, windowFlags);
|
||||
mPtr = SDL_CreateWindow(args.title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, windowFlags);
|
||||
}
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
#pragma once
|
||||
#ifdef WITH_EDITOR
|
||||
#include "graph/frame_graph.h"
|
||||
#include "module/module_manager.h"
|
||||
#include <imgui.h>
|
||||
namespace api {
|
||||
class EditorSystem;
|
||||
struct RenderEditorContext {
|
||||
EditorSystem* editor;
|
||||
uint32_t frame;
|
||||
uint32_t frameCount;
|
||||
EditorSystem* operator->() {
|
||||
return editor;
|
||||
}
|
||||
};
|
||||
class EditorPanel {
|
||||
public:
|
||||
EditorPanel() = default;
|
||||
~EditorPanel() = default;
|
||||
virtual void DrawPanel(FrameGraph& graph, RenderEditorContext& ctx) = 0;
|
||||
};
|
||||
class EditorWindow {
|
||||
protected:
|
||||
std::vector<EditorPanel*> mPanels;
|
||||
public:
|
||||
EditorWindow() = default;
|
||||
~EditorWindow() = default;
|
||||
virtual void Draw(FrameGraph& graph, RenderEditorContext& ctx) = 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;
|
||||
}
|
||||
ImTextureID AddTexture(FrameGraph& graph, TextureDesc& desc, TextureSampler sampler);
|
||||
virtual ImTextureID AddTexture(ImageViewPtr imageview, SamplerPtr sampler, ResourceState state) = 0;
|
||||
};
|
||||
}
|
||||
#endif // WITH_EDITOR
|
||||
@ -21,7 +21,7 @@ namespace api {
|
||||
}
|
||||
void operator delete(void* p) {}
|
||||
public:
|
||||
Window(CreatePFN func, const Args& args, int width, int height) noexcept;
|
||||
Window(const Args& args, int width, int height) noexcept;
|
||||
SDL_Window* GetPtr() { return mPtr; }
|
||||
};
|
||||
};
|
||||
@ -159,8 +159,10 @@ namespace api {
|
||||
if (surface.state == ResourceState::PRESENT) {
|
||||
return;
|
||||
}
|
||||
ResourceState srcState = surface.state;
|
||||
surface.state = ResourceState::PRESENT;
|
||||
TextureBarrier barrier{};
|
||||
barrier.mSrcState = surface.state;
|
||||
barrier.mSrcState = srcState;
|
||||
barrier.mDstState = ResourceState::PRESENT;
|
||||
barrier.mTexture = surface;
|
||||
ResourceBarrierDesc desc{};
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#include "render/module.h"
|
||||
#include "render/render_module.h"
|
||||
#include "render/asset/ubo.h"
|
||||
#include "zlog.h"
|
||||
namespace api {
|
||||
@ -3,12 +3,11 @@ static_component("render","engine")
|
||||
files = {"include/render/asset/*.h"}
|
||||
})
|
||||
add_includedirs("3rdparty", {public = true})
|
||||
add_headerfiles("include/**.h", "include/**.inl", "3rdparty/imgui/*.h")
|
||||
add_files("src/**.cpp", "3rdparty/imgui/*.cpp")
|
||||
add_headerfiles("include/**.h")
|
||||
add_files("src/**.cpp")
|
||||
add_deps("asset", "zlib", "core")
|
||||
add_syslinks("user32", {public = true})
|
||||
add_packages("libsdl","shaderc","spirv-cross", {public = true})
|
||||
if WITH_EDITOR then
|
||||
add_defines("WITH_EDITOR", {public = true})
|
||||
add_packages("imgui",{public = true})
|
||||
end
|
||||
11
engine/modules/engine/ui/include/ui/ui_module.h
Normal file
11
engine/modules/engine/ui/include/ui/ui_module.h
Normal file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include "module/module.h"
|
||||
namespace api {
|
||||
class UI_API UIModule : public IStaticModule
|
||||
{
|
||||
public:
|
||||
void OnLoad(int argc, char** argv) override;
|
||||
void OnUnload() override;
|
||||
void InitMetaData(void) override {};
|
||||
};
|
||||
}
|
||||
34
engine/modules/engine/ui/src/ui_module.cpp
Normal file
34
engine/modules/engine/ui/src/ui_module.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "zlog.h"
|
||||
#include "ui/ui_module.h"
|
||||
#include "NoesisPCH.h"
|
||||
namespace api {
|
||||
void UIModule::OnLoad(int argc, char** argv)
|
||||
{
|
||||
Noesis::SetLogHandler([](const char*, uint32_t, uint32_t level, const char*, const char* msg)
|
||||
{
|
||||
switch (level) {
|
||||
case 0:
|
||||
case 1:
|
||||
zlog::debug("[NOESIS] {}\n", msg);
|
||||
break;
|
||||
case 2:
|
||||
zlog::info("[NOESIS] {}\n", msg);
|
||||
break;
|
||||
case 3:
|
||||
zlog::warn("[NOESIS] {}\n", msg);
|
||||
break;
|
||||
default:
|
||||
zlog::error("[NOESIS] {}\n", msg);
|
||||
break;
|
||||
}
|
||||
});
|
||||
// Sets the active license
|
||||
Noesis::GUI::SetLicense(NS_LICENSE_NAME, NS_LICENSE_KEY);
|
||||
// Noesis initialization. This must be the first step before using any NoesisGUI functionality
|
||||
Noesis::GUI::Init();
|
||||
}
|
||||
void UIModule::OnUnload()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
5
engine/modules/engine/ui/xmake.lua
Normal file
5
engine/modules/engine/ui/xmake.lua
Normal file
@ -0,0 +1,5 @@
|
||||
static_component("ui","engine")
|
||||
add_headerfiles("include/**.h")
|
||||
add_files("src/**.cpp")
|
||||
add_deps("core", "asset", "zlib", "render")
|
||||
add_packages("noesis", {public = true})
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,211 +0,0 @@
|
||||
// dear imgui: Renderer Backend for Vulkan
|
||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||
|
||||
// Implemented features:
|
||||
// [x] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions.
|
||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||
// [x] Renderer: Multi-viewport / platform windows. With issues (flickering when creating a new viewport).
|
||||
|
||||
// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
|
||||
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
// - FAQ https://dearimgui.com/faq
|
||||
// - Getting Started https://dearimgui.com/getting-started
|
||||
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||
// - Introduction, links and more at the top of imgui.cpp
|
||||
|
||||
// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
|
||||
// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
|
||||
// You will use those if you want to use this rendering backend in your engine/app.
|
||||
// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
|
||||
// the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
|
||||
// Read comments in imgui_impl_vulkan.h.
|
||||
|
||||
#pragma once
|
||||
#ifndef IMGUI_DISABLE
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
|
||||
// [Configuration] in order to use a custom Vulkan function loader:
|
||||
// (1) You'll need to disable default Vulkan function prototypes.
|
||||
// We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag.
|
||||
// In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit:
|
||||
// - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file
|
||||
// - Or as a compilation flag in your build system
|
||||
// - Or uncomment here (not recommended because you'd be modifying imgui sources!)
|
||||
// - Do not simply add it in a .cpp file!
|
||||
// (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function.
|
||||
// If you have no idea what this is, leave it alone!
|
||||
//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES
|
||||
|
||||
// Convenience support for Volk
|
||||
// (you can also technically use IMGUI_IMPL_VULKAN_NO_PROTOTYPES + wrap Volk via ImGui_ImplVulkan_LoadFunctions().)
|
||||
//#define IMGUI_IMPL_VULKAN_USE_VOLK
|
||||
|
||||
#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
|
||||
#define VK_NO_PROTOTYPES
|
||||
#endif
|
||||
#if defined(VK_USE_PLATFORM_WIN32_KHR) && !defined(NOMINMAX)
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
// Vulkan includes
|
||||
#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
|
||||
#include <volk.h>
|
||||
#else
|
||||
#include <vulkan/vulkan.h>
|
||||
#endif
|
||||
#if defined(VK_VERSION_1_3) || defined(VK_KHR_dynamic_rendering)
|
||||
#define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
||||
#endif
|
||||
|
||||
// Initialization data, for ImGui_ImplVulkan_Init()
|
||||
// [Please zero-clear before use!]
|
||||
// - About descriptor pool:
|
||||
// - A VkDescriptorPool should be created with VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
|
||||
// and must contain a pool size large enough to hold a small number of VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptors.
|
||||
// - As an convenience, by setting DescriptorPoolSize > 0 the backend will create one for you.
|
||||
// - Current version of the backend use 1 descriptor for the font atlas + as many as additional calls done to ImGui_ImplVulkan_AddTexture().
|
||||
// - It is expected that as early as Q1 2025 the backend will use a few more descriptors, so aim at 10 + number of desierd calls to ImGui_ImplVulkan_AddTexture().
|
||||
// - About dynamic rendering:
|
||||
// - When using dynamic rendering, set UseDynamicRendering=true and fill PipelineRenderingCreateInfo structure.
|
||||
struct ImGui_ImplVulkan_InitInfo
|
||||
{
|
||||
VkInstance Instance;
|
||||
VkPhysicalDevice PhysicalDevice;
|
||||
VkDevice Device;
|
||||
uint32_t QueueFamily;
|
||||
VkQueue Queue;
|
||||
VkDescriptorPool DescriptorPool; // See requirements in note above; ignored if using DescriptorPoolSize > 0
|
||||
VkRenderPass RenderPass; // Ignored if using dynamic rendering
|
||||
uint32_t MinImageCount; // >= 2
|
||||
uint32_t ImageCount; // >= MinImageCount
|
||||
VkSampleCountFlagBits MSAASamples; // 0 defaults to VK_SAMPLE_COUNT_1_BIT
|
||||
|
||||
// (Optional)
|
||||
VkPipelineCache PipelineCache;
|
||||
uint32_t Subpass;
|
||||
|
||||
// (Optional) Set to create internal descriptor pool instead of using DescriptorPool
|
||||
uint32_t DescriptorPoolSize;
|
||||
|
||||
// (Optional) Dynamic Rendering
|
||||
// Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3.
|
||||
bool UseDynamicRendering;
|
||||
#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
|
||||
VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo;
|
||||
#endif
|
||||
|
||||
// (Optional) Allocation, Debugging
|
||||
const VkAllocationCallbacks* Allocator;
|
||||
void (*CheckVkResultFn)(VkResult err);
|
||||
VkDeviceSize MinAllocationSize; // Minimum allocation size. Set to 1024*1024 to satisfy zealous best practices validation layer and waste a little memory.
|
||||
};
|
||||
|
||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info);
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE);
|
||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture();
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontsTexture();
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
|
||||
|
||||
// Register a texture (VkDescriptorSet == ImTextureID)
|
||||
// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem
|
||||
// Please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions.
|
||||
IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout);
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set);
|
||||
|
||||
// Optional: load Vulkan functions with a custom function loader
|
||||
// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES
|
||||
IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr);
|
||||
|
||||
// [BETA] Selected render state data shared with callbacks.
|
||||
// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplVulkan_RenderDrawData() call.
|
||||
// (Please open an issue if you feel you need access to more data)
|
||||
struct ImGui_ImplVulkan_RenderState
|
||||
{
|
||||
VkCommandBuffer CommandBuffer;
|
||||
VkPipeline Pipeline;
|
||||
VkPipelineLayout PipelineLayout;
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// Internal / Miscellaneous Vulkan Helpers
|
||||
// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.)
|
||||
//-------------------------------------------------------------------------
|
||||
// You probably do NOT need to use or care about those functions.
|
||||
// Those functions only exist because:
|
||||
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
||||
// 2) the multi-viewport / platform window implementation needs them internally.
|
||||
// Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
|
||||
// but it is too much code to duplicate everywhere so we exceptionally expose them.
|
||||
//
|
||||
// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
|
||||
// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
|
||||
// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
struct ImGui_ImplVulkanH_Frame;
|
||||
struct ImGui_ImplVulkanH_Window;
|
||||
|
||||
// Helpers
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
|
||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator);
|
||||
IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
|
||||
IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
|
||||
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
||||
|
||||
// Helper structure to hold the data needed by one rendering frame
|
||||
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||
// [Please zero-clear before use!]
|
||||
struct ImGui_ImplVulkanH_Frame
|
||||
{
|
||||
VkCommandPool CommandPool;
|
||||
VkCommandBuffer CommandBuffer;
|
||||
VkFence Fence;
|
||||
VkImage Backbuffer;
|
||||
VkImageView BackbufferView;
|
||||
VkFramebuffer Framebuffer;
|
||||
};
|
||||
|
||||
struct ImGui_ImplVulkanH_FrameSemaphores
|
||||
{
|
||||
VkSemaphore ImageAcquiredSemaphore;
|
||||
VkSemaphore RenderCompleteSemaphore;
|
||||
};
|
||||
|
||||
// Helper structure to hold the data needed by one rendering context into one OS window
|
||||
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
|
||||
struct ImGui_ImplVulkanH_Window
|
||||
{
|
||||
int Width;
|
||||
int Height;
|
||||
VkSwapchainKHR Swapchain;
|
||||
VkSurfaceKHR Surface;
|
||||
VkSurfaceFormatKHR SurfaceFormat;
|
||||
VkPresentModeKHR PresentMode;
|
||||
VkRenderPass RenderPass;
|
||||
bool UseDynamicRendering;
|
||||
bool ClearEnable;
|
||||
VkClearValue ClearValue;
|
||||
uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
|
||||
uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
|
||||
uint32_t SemaphoreCount; // Number of simultaneous in-flight frames + 1, to be able to use it in vkAcquireNextImageKHR
|
||||
uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
|
||||
ImGui_ImplVulkanH_Frame* Frames;
|
||||
ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores;
|
||||
|
||||
ImGui_ImplVulkanH_Window()
|
||||
{
|
||||
memset((void*)this, 0, sizeof(*this));
|
||||
PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this.
|
||||
ClearEnable = true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // #ifndef IMGUI_DISABLE
|
||||
@ -27,7 +27,7 @@ namespace vkn {
|
||||
table<Name, RenderPassInfo> RenderPassNameCache;
|
||||
table<FramebufferKey, VkFramebuffer> FramebufferCache;
|
||||
public:
|
||||
VulkanAPI();
|
||||
VulkanAPI(VulkanWindow* pWindow);
|
||||
void Init() override;
|
||||
void Shutdown() override;
|
||||
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
#include "render/editor_system.h"
|
||||
#include "render/graph/frame_graph.h"
|
||||
#include "vkn/vulkan_api.h"
|
||||
namespace vkn {
|
||||
using api::FrameGraph;
|
||||
using api::RenderPassContext;
|
||||
using api::RenderPassBuilder;
|
||||
using api::RenderEditorContext;
|
||||
class VulkanImguiEditor : public api::EditorSystem {
|
||||
public:
|
||||
void Initialize() override;
|
||||
void Finalize() override;
|
||||
|
||||
ImTextureID AddTexture(ImageViewPtr imageview, SamplerPtr sampler, ResourceState state) override;
|
||||
|
||||
void Render(FrameGraph& graph, RenderEditorContext& ctx);
|
||||
void OnBeginRenderFrame(FrameGraph& graph, uint32_t frame);
|
||||
static VulkanImguiEditor* Ptr() {
|
||||
return (VulkanImguiEditor*)api::EditorSystem::Ptr();
|
||||
};
|
||||
static void Setup(FrameGraph& graph, RenderPassBuilder& builder);
|
||||
static void Execute(FrameGraph&, RenderPassContext&);
|
||||
};
|
||||
}
|
||||
@ -8,4 +8,3 @@ public:
|
||||
void InitMetaData(void) override;
|
||||
};
|
||||
IMPLEMENT_DYNAMIC_MODULE(VULKAN_API, VulkanModule, vulkan)
|
||||
#include ".vulkan/vulkan.plugin.inl"
|
||||
@ -16,7 +16,7 @@ namespace vkn {
|
||||
VkImageUsageFlags imageUsage;
|
||||
uint32_t maxFrameInFlightCount;
|
||||
VkExtent2D EnableImageExtent2D(VkSurfaceCapabilitiesKHR& capabilities);
|
||||
static VulkanWindowArgs Default();
|
||||
static VulkanWindowArgs Default(uint32_t frames);
|
||||
};
|
||||
class VulkanSwapchain {
|
||||
private:
|
||||
@ -43,8 +43,7 @@ namespace vkn {
|
||||
void operator delete(void* p) {}
|
||||
public:
|
||||
using api::Window::Window;
|
||||
using CreatePFN = decltype(&SDL_Vulkan_CreateSurface);
|
||||
bool CreateRender(CreatePFN createPFN, VulkanWindowArgs& args);
|
||||
bool CreateRender(VulkanWindowArgs& args);
|
||||
static VulkanWindow* Ptr() {
|
||||
return (VulkanWindow*)api::Window::Ptr();
|
||||
}
|
||||
|
||||
@ -11,8 +11,8 @@
|
||||
#include "zlog.h"
|
||||
namespace vkn {
|
||||
using api::EventSystem;
|
||||
VulkanAPI::VulkanAPI() : RenderAPI(new VulkanContext())
|
||||
, window(*VulkanWindow::Ptr())
|
||||
VulkanAPI::VulkanAPI(VulkanWindow* pWindow) : RenderAPI(new VulkanContext())
|
||||
, window(*pWindow)
|
||||
, backend(VulkanEngineName)
|
||||
{
|
||||
|
||||
|
||||
@ -1,185 +0,0 @@
|
||||
#include "vkn/vulkan_imgui_editor.h"
|
||||
#include "vkn/vulkan_window.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 "imgui/imgui_impl_vulkan.h"
|
||||
#include "imgui/imgui_impl_sdl2.h"
|
||||
#include "data/global.h"
|
||||
#include "event/event_system.h"
|
||||
#include "tinyimageformat/tinyimageformat_apis.h"
|
||||
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[] =
|
||||
{
|
||||
{ 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;
|
||||
VkDescriptorPool descriptorPool;
|
||||
vkCreateDescriptorPool(device, &pool_info, VK_NULL_HANDLE, &descriptorPool);
|
||||
return descriptorPool;
|
||||
}
|
||||
VkRenderPass CreateRenderPass(TinyImageFormat format, VkDevice device) {
|
||||
VkAttachmentDescription colorAttachment = {};
|
||||
colorAttachment.format = (VkFormat)TinyImageFormat_ToVkFormat(format);
|
||||
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
|
||||
VkAttachmentReference colorAttachmentRef = {};
|
||||
colorAttachmentRef.attachment = 0;
|
||||
colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
|
||||
VkSubpassDescription subpass = {};
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.colorAttachmentCount = 1;
|
||||
subpass.pColorAttachments = &colorAttachmentRef;
|
||||
|
||||
VkSubpassDependency dependency = {};
|
||||
dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||
dependency.dstSubpass = 0;
|
||||
dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
dependency.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
|
||||
VkRenderPassCreateInfo info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
info.attachmentCount = 1;
|
||||
info.pAttachments = &colorAttachment;
|
||||
info.subpassCount = 1;
|
||||
info.pSubpasses = &subpass;
|
||||
info.dependencyCount = 1;
|
||||
info.pDependencies = &dependency;
|
||||
VkRenderPass renderPass;
|
||||
if (vkCreateRenderPass(device, &info, VK_NULL_HANDLE, &renderPass) != VK_SUCCESS)
|
||||
throw std::runtime_error("Could not create Dear ImGui's render pass");
|
||||
return renderPass;
|
||||
}
|
||||
void VulkanImguiEditor::Initialize()
|
||||
{
|
||||
VulkanAPI* API = VulkanAPI::Ptr();
|
||||
VulkanWindow* window = VulkanWindow::Ptr();
|
||||
Backend& backend = API->GetBackend();
|
||||
Queue* pQueue = backend.GetDevice().GetQueue(Queue::RenderQueue);
|
||||
VkDescriptorPool descriptorPool = CreateDescriptorPool(backend.GetDevice().Ptr());
|
||||
TextureDesc surface = API->context.surface;
|
||||
VkRenderPass renderPass = CreateRenderPass(surface.format, backend.GetDevice().Ptr());
|
||||
|
||||
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 = descriptorPool;
|
||||
init_info.MinImageCount = 2;
|
||||
init_info.ImageCount = API->context.frameCount;
|
||||
init_info.RenderPass = renderPass;
|
||||
init_info.PipelineCache = VK_NULL_HANDLE;
|
||||
init_info.Subpass = 0;
|
||||
init_info.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
|
||||
init_info.Allocator = VK_NULL_HANDLE;
|
||||
ImGui_ImplVulkan_Init(&init_info);
|
||||
API->SetRenderPassInfo(ImguiPassName, renderPass);
|
||||
//gEngineConfig.IsRenderEditorSurface = true;
|
||||
if (gEngineConfig.IsRenderEditorSurface) {
|
||||
TextureDesc desc{};
|
||||
desc.width = 512;
|
||||
desc.height = 512;
|
||||
desc.format = TinyImageFormat_FromVkFormat((TinyImageFormat_VkFormat)VK_FORMAT_B8G8R8A8_SRGB);
|
||||
desc.state = ResourceState::UNDEFINED;
|
||||
desc.sampleCount = SampleCount::SAMPLE_COUNT_1;
|
||||
desc.arraySize = 1;
|
||||
desc.mipLevel = 1;
|
||||
desc.depth = 1;
|
||||
desc.dimension = TextureDimension::TEX_2D;
|
||||
desc.usage = TextureUsage::COLOR_ATTACHMENT | TextureUsage::SAMPLEABLE;
|
||||
for (uint32_t i = 0; i < API->context.frameCount; i++) {
|
||||
API->graph.SetResourceTexture(desc, FrameGraph::NameEditorSurface, i);
|
||||
}
|
||||
}
|
||||
EventSystem::Ptr()->BeginRenderFrame.Subscribe(&VulkanImguiEditor::OnBeginRenderFrame, this);
|
||||
}
|
||||
void VulkanImguiEditor::Finalize()
|
||||
{
|
||||
|
||||
}
|
||||
ImTextureID VulkanImguiEditor::AddTexture(ImageViewPtr imageview, SamplerPtr sampler, ResourceState state)
|
||||
{
|
||||
VkDescriptorSet descriptorSet = ImGui_ImplVulkan_AddTexture((VkSampler)sampler, (VkImageView)imageview, vkApiGetImageLayout(state));
|
||||
return reinterpret_cast<ImTextureID>(descriptorSet);
|
||||
}
|
||||
void VulkanImguiEditor::Render(FrameGraph& graph, RenderEditorContext& ctx)
|
||||
{
|
||||
for (auto win : mWindows)
|
||||
{
|
||||
win->Draw(graph, ctx);
|
||||
}
|
||||
}
|
||||
void VulkanImguiEditor::OnBeginRenderFrame(FrameGraph& graph, uint32_t frame)
|
||||
{
|
||||
graph.mIsRenderEditorSurface = gEngineConfig.IsRenderEditorSurface;
|
||||
if (gEngineConfig.IsRenderEditorSurface) {
|
||||
graph.mEditorSurfaceID = graph.mSurfaceID;
|
||||
graph.mSurfaceID = graph.GetTextureID(FrameGraph::NameEditorSurface, frame);
|
||||
}
|
||||
graph.AddRenderPass<VulkanImguiEditor>();
|
||||
}
|
||||
void VulkanImguiEditor::Setup(FrameGraph& graph, RenderPassBuilder& builder)
|
||||
{
|
||||
builder.Name(ImguiPassName)
|
||||
.Type(RenderPassNodeType::Imgui, RenderPassNodeFlag::Output)
|
||||
.Write(graph.GetRenderSurface(), ResourceState::COLOR_ATTACHMENT);
|
||||
if (gEngineConfig.IsRenderEditorSurface) {
|
||||
builder.Read(graph.GetSurface(), ResourceState::READ_ONLY);
|
||||
}
|
||||
}
|
||||
void VulkanImguiEditor::Execute(FrameGraph& graph, RenderPassContext& context)
|
||||
{
|
||||
graph.GetRenderSurface().state = ResourceState::PRESENT;
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
VulkanImguiEditor* editor = VulkanImguiEditor::Ptr();
|
||||
RenderEditorContext editorContext{.editor = editor, .frame = context->frame, .frameCount = context->frameCount };
|
||||
editor->Render(graph, editorContext);
|
||||
|
||||
ImGui::Render();
|
||||
VulkanContext& ctx = *(VulkanContext*)context.parent;
|
||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), ctx.command);
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
// 更新并渲染平台窗口
|
||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||
{
|
||||
ImGui::UpdatePlatformWindows();
|
||||
ImGui::RenderPlatformWindowsDefault(nullptr, ctx.command);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,18 +1,20 @@
|
||||
#include "xmalloc_new_delete.h"
|
||||
#include "vkn/module.h"
|
||||
#include "vkn/vulkan_imgui_editor.h"
|
||||
#include "vkn/vulkan_module.h"
|
||||
#include "vkn/loader/vulkan_glsl_loader.h"
|
||||
#include "pmr/frame_allocator.h"
|
||||
using namespace vkn;
|
||||
void VulkanModule::OnLoad(int argc, char** argv)
|
||||
{
|
||||
VulkanGlslLoader::Init();
|
||||
#ifdef WITH_EDITOR
|
||||
AddSystem<VulkanImguiEditor>();
|
||||
#endif // WITH_EDITOR
|
||||
|
||||
}
|
||||
|
||||
void VulkanModule::OnUnload()
|
||||
{
|
||||
}
|
||||
void VulkanModule::InitMetaData()
|
||||
{
|
||||
mInfo.name = "vulkan";
|
||||
mInfo.dependencies = {
|
||||
{"engine", "1.0.1", "shared" }
|
||||
};
|
||||
}
|
||||
@ -10,13 +10,13 @@
|
||||
#include <algorithm>
|
||||
#include <tinyimageformat/tinyimageformat_apis.h>
|
||||
namespace vkn {
|
||||
bool VulkanWindow::CreateRender(CreatePFN createPFN, VulkanWindowArgs& args)
|
||||
bool VulkanWindow::CreateRender(VulkanWindowArgs& args)
|
||||
{
|
||||
VulkanAPI* api = VulkanAPI::Ptr();
|
||||
Backend& backend = api->GetBackend();
|
||||
VkInstance instance = backend.GetInstance().Ptr();
|
||||
VkSurfaceKHR surface;
|
||||
if (!createPFN(mPtr, instance, &surface)) {
|
||||
if (!SDL_Vulkan_CreateSurface(mPtr, instance, &surface)) {
|
||||
return false;
|
||||
}
|
||||
args.width = mWidth;
|
||||
@ -134,9 +134,10 @@ namespace vkn {
|
||||
}
|
||||
return image_extent;
|
||||
}
|
||||
VulkanWindowArgs VulkanWindowArgs::Default()
|
||||
VulkanWindowArgs VulkanWindowArgs::Default(uint32_t frames)
|
||||
{
|
||||
return {
|
||||
.frames = frames,
|
||||
.imageFormat = VK_FORMAT_B8G8R8A8_SRGB,
|
||||
.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR,
|
||||
.presentMode = VK_PRESENT_MODE_MAILBOX_KHR,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
shared_module("vulkan","engine")
|
||||
add_headerfiles("include/**.h")
|
||||
add_files("src/**.cpp", "include/volk/volk.c", "include/imgui/*.cpp")
|
||||
add_files("src/**.cpp", "include/volk/volk.c")
|
||||
add_packages("vulkansdk", {public = true})
|
||||
add_dependency("engine", {public = true})
|
||||
on_load(function (target)
|
||||
|
||||
@ -29,7 +29,7 @@ function shared_module(name, owner, opt)
|
||||
set_group("Engine/"..owner.."__dyn")
|
||||
add_rules("engine.api")
|
||||
add_includedirs("include", {public = true})
|
||||
add_rules("engine.plugin", {file = opt and opt.file or "include/" .. name .. "/module.h"})
|
||||
--add_rules("engine.plugin", {file = opt and opt.file or "include/" .. name .. "/module.h"})
|
||||
end
|
||||
function add_dependency(...)
|
||||
add_deps(...)
|
||||
@ -50,7 +50,7 @@ function game_instance(name, opt)
|
||||
set_kind("binary")
|
||||
set_group("Games")
|
||||
add_rules("engine.api")
|
||||
add_rules("engine.plugin", {file = opt and opt.file or "src/" .. name .. ".h"})
|
||||
--add_rules("engine.plugin", {file = opt and opt.file or "src/" .. name .. ".h"})
|
||||
add_defines("SDL_MAIN_HANDLED")
|
||||
target(name .. "-editor")
|
||||
set_kind("binary")
|
||||
|
||||
@ -1,19 +1,8 @@
|
||||
#include "editor/editor.h"
|
||||
#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)
|
||||
{
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // 可选:启用键盘导航
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // 可选:启用Docking
|
||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // 可选:启用多视口
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
}
|
||||
|
||||
void EditorModule::OnUnload()
|
||||
@ -21,7 +10,6 @@ namespace api {
|
||||
}
|
||||
void EditorModule::Initialize(void)
|
||||
{
|
||||
EditorSystem* Editor = EditorSystem::Ptr();
|
||||
Editor->AddWindow<EditorMainWindow>();
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
#include "editor/panel/asset_preview_panel.h"
|
||||
#include "data/global.h"
|
||||
#include <imgui.h>
|
||||
namespace api {
|
||||
TextureSampler sampler{
|
||||
.filterMag = SamplerMagFilter::LINEAR,
|
||||
.filterMin = SamplerMinFilter::LINEAR,
|
||||
.wrapS = SamplerWrapMode::CLAMP_TO_EDGE,
|
||||
.wrapT = SamplerWrapMode::CLAMP_TO_EDGE,
|
||||
.wrapR = SamplerWrapMode::CLAMP_TO_EDGE,
|
||||
.compareMode = SamplerCompareMode::COMPARE_TO_TEXTURE,
|
||||
.compareFunc = SamplerCompareFunc::GE,
|
||||
};
|
||||
ImTextureID TextureIDList[10] = {};
|
||||
void AssetPreviewPanel::DrawPanel(FrameGraph& graph, RenderEditorContext& context) {
|
||||
static float my_float = 0.5f;
|
||||
ImGui::Text("This is some useful text.");
|
||||
ImGui::SliderFloat("float", &my_float, 0.0f, 1.0f);
|
||||
if (gEngineConfig.IsRenderEditorSurface) {
|
||||
TextureDesc surface = graph.GetSurface();
|
||||
if (!TextureIDList[context.frame]) {
|
||||
TextureIDList[context.frame] = context->AddTexture(graph, surface, sampler);
|
||||
}
|
||||
// 每帧渲染时都可以通过 ImTextureID 使用
|
||||
ImGui::Image(TextureIDList[context.frame], ImVec2(surface.width, surface.height));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
#include "editor/panel/menu_bar_panel.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace api {
|
||||
void MenuBarPanel::DrawPanel(FrameGraph& graph, RenderEditorContext& context)
|
||||
{
|
||||
// 面板大小和位置
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
#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(FrameGraph& graph, RenderEditorContext& context)
|
||||
{
|
||||
ImGui::Begin("MainWindow");
|
||||
for (auto panel : mPanels) {
|
||||
panel->DrawPanel(graph, context);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@ public:
|
||||
{"core", "1.0.1", "static" },
|
||||
{"asset", "1.0.1", "static" },
|
||||
{"render", "1.0.1", "static" },
|
||||
{"ui", "1.0.1", "static" },
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -21,9 +21,6 @@
|
||||
#define RENDER_API_VAL 1
|
||||
#include "renderapi_impl.inl"
|
||||
#include "window_impl.inl"
|
||||
#ifdef WITH_EDITOR
|
||||
#include "editor_system_impl.inl"
|
||||
#endif
|
||||
#endif // !RENDER_API_VAL
|
||||
|
||||
#ifndef APP_API_VAL
|
||||
@ -31,3 +28,6 @@
|
||||
#include "app_impl.inl"
|
||||
#include "event_system_impl.inl"
|
||||
#endif // !APP_API_VAL
|
||||
|
||||
#include "ui/ui_module.h"
|
||||
IMPLEMENT_STATIC_MODULE(UI_API, api::UIModule, ui)
|
||||
@ -1,12 +1,13 @@
|
||||
WITH_EDITOR = true
|
||||
target("engine")
|
||||
add_defines("ENGINE_ROOT="..os.curdir():gsub("\\", "\\\\"),{public = false})
|
||||
add_headerfiles("include/*.natvis")
|
||||
add_headerfiles("include/*.natvis","include/engine/**.h")
|
||||
add_includedirs("include", {public = true})
|
||||
set_kind("shared")
|
||||
set_group("Engine")
|
||||
add_rules("engine.api")
|
||||
add_files("src/engine/**.cpp")
|
||||
add_packages("noesis")
|
||||
target("editor")
|
||||
set_kind("shared")
|
||||
set_group("Engine")
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
rule("engine.plugin")
|
||||
set_extensions(".h")
|
||||
on_config(function (target)
|
||||
import("make_plugin")
|
||||
local file = target:extraconf("rules", "engine.plugin", "file")
|
||||
make_plugin(target, file or "module.h")
|
||||
end)
|
||||
-- rule("engine.plugin")
|
||||
-- set_extensions(".h")
|
||||
-- on_config(function (target)
|
||||
-- --import("make_plugin")
|
||||
-- --local file = target:extraconf("rules", "engine.plugin", "file")
|
||||
-- --make_plugin(target, file or "module.h")
|
||||
-- end)
|
||||
|
||||
@ -4,33 +4,35 @@
|
||||
#include "event/event_system.h"
|
||||
#include "vkn/vulkan_window.h"
|
||||
#include "vkn/vulkan_api.h"
|
||||
#ifdef WITH_EDITOR
|
||||
#include "imgui/imgui_impl_sdl2.h"
|
||||
#endif
|
||||
#include "render/pass/demo_pass.h"
|
||||
#include <iostream>
|
||||
using namespace api;
|
||||
RenderAPI* API;
|
||||
void ZWorldModule::OnLoad(int argc, char** argv)
|
||||
{
|
||||
using vkn::VulkanWindow;
|
||||
using vkn::VulkanAPI;
|
||||
// 创建窗口
|
||||
gEngineConfig.API = GraphicsAPI::Vulkan;
|
||||
auto window = new vkn::VulkanWindow(&SDL_CreateWindow, { "zengine" , SDL_WINDOW_VULKAN }, 1080, 720);
|
||||
API = new vkn::VulkanAPI();
|
||||
auto args = vkn::VulkanWindowArgs::Default();
|
||||
args.frames = 3;
|
||||
if (!window->CreateRender(&SDL_Vulkan_CreateSurface, args)) {
|
||||
zlog::errorf("SDL_Vulkan_CreateSurface failed {}", SDL_GetError());
|
||||
}
|
||||
VulkanWindow* window = new VulkanWindow({ "zengine" , SDL_WINDOW_VULKAN }, 1080, 720);
|
||||
API = new vkn::VulkanAPI(window);
|
||||
auto args = vkn::VulkanWindowArgs::Default(3);
|
||||
window->CreateRender(args);
|
||||
API->Init();
|
||||
API->context.views.push_back({});
|
||||
#ifdef WITH_EDITOR //绑定窗口交互
|
||||
ImGui_ImplSDL2_InitForVulkan(window->GetPtr());
|
||||
#endif
|
||||
EventSystem::Ptr()->BeginRenderFrame.Subscribe(mInfo.name, [](FrameGraph& graph, uint32_t frame) {
|
||||
graph.AddRenderPass<DemoPass>();
|
||||
});
|
||||
}
|
||||
void ZWorldModule::InitMetaData()
|
||||
{
|
||||
mInfo.name = "zworld";
|
||||
mInfo.dependencies = {
|
||||
{"engine", "1.0.1", "shared" },
|
||||
{"editor", "1.0.1", "shared" },
|
||||
{"vulkan", "1.0.1", "shared" }
|
||||
};
|
||||
}
|
||||
void ZWorldModule::Initialize()
|
||||
{
|
||||
}
|
||||
@ -45,9 +47,6 @@ void ZWorldModule::MainLoop()
|
||||
while (running) {
|
||||
// 处理事件
|
||||
while (SDL_PollEvent(&event_)) {
|
||||
#ifdef WITH_EDITOR
|
||||
ImGui_ImplSDL2_ProcessEvent(&event_);
|
||||
#endif // WITH_EDITOR
|
||||
if (event_.type == SDL_QUIT) {
|
||||
running = false;
|
||||
}
|
||||
@ -58,4 +57,3 @@ void ZWorldModule::MainLoop()
|
||||
FramePool()->reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -11,4 +11,3 @@ public:
|
||||
void MainLoop()override;
|
||||
};
|
||||
IMPLEMENT_DYNAMIC_MODULE(ZWORLD_API, ZWorldModule, zworld)
|
||||
#include ".zworld/zworld.plugin.inl"
|
||||
Loading…
Reference in New Issue
Block a user