diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index f4c76db7..4216ba03 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -4,7 +4,7 @@ #define SHEDITOR #ifdef SHEDITOR -//#include "Editor/SHEditor.h" +#include "Editor/SHEditor.h" //#include "Scenes/SBEditorScene.h" #endif // SHEDITOR @@ -14,6 +14,7 @@ #include #include #include +#define SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN 1 #include #include "Scripting/SHScriptEngine.h" @@ -32,7 +33,7 @@ namespace Sandbox // Set working directory SHADE::SHFileUtilities::SetWorkDirToExecDir(); - SDL_Init(SDL_INIT_VIDEO); + SDL_Init(SDL_INIT_EVERYTHING); window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow); SHADE::SHSystemManager::CreateSystem(); SHADE::SHGraphicsSystem* graphicsSystem = static_cast(SHADE::SHSystemManager::GetSystem()); @@ -40,11 +41,13 @@ namespace Sandbox graphicsSystem->SetWindow(&window); - SDL_CreateWindowFrom(window.GetHWND()); + sdlWindow = SDL_CreateWindowFrom(window.GetHWND()); + //auto [w, h] = window.GetWindowSize(); + //SDL_SetWindowSize(sdlWindow, w, h); SHADE::SHSystemManager::Init(); #ifdef SHEDITOR - //SHADE::SHEditor::Initialize(window.GetHWND()); + SHADE::SHEditor::Initialise(sdlWindow); #else #endif @@ -60,15 +63,18 @@ namespace Sandbox while (!window.WindowShouldClose()) { //#ifdef SHEDITOR - //SHADE::SHEditor::PreRender(); //#endif graphicsSystem->BeginRender(); - graphicsSystem->Run(1.0f); - //#ifdef SHEDITOR - //SHADE::SHEditor::PreRender(); - //SHADE::SHEditor::Update(); + + #ifdef SHEDITOR + SHADE::SHEditor::PreRender(); //SHADE::SHEditor::Render(); - //#endif + #endif + + #ifdef SHEDITOR + SHADE::SHEditor::Render(); + #endif + graphicsSystem->Run(1.0f); graphicsSystem->EndRender(); } } @@ -76,12 +82,14 @@ namespace Sandbox void SBApplication::Exit(void) { + #ifdef SHEDITOR + SHADE::SHEditor::Exit(); + #endif + SHADE::SHScriptEngine::Exit(); SHADE::SHSystemManager::Exit(); SDL_DestroyWindow(sdlWindow); - #ifdef SHEDITOR - #else - #endif + SDL_Quit(); } } diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp new file mode 100644 index 00000000..6d0f1a28 --- /dev/null +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -0,0 +1,112 @@ +#include "SHpch.h" +#include "SHEditor.h" + +#include + +#include "ECS_Base/Managers/SHSystemManager.h" +#include "Graphics/Instance/SHVkInstance.h" +#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h" +#include "Graphics/Swapchain/SHVkSwapchain.h" + +//IMGUI Backend includes +#include +#include +namespace SHADE +{ + Handle SHEditor::imguiCommandPool; + Handle SHEditor::imguiCommandBuffer; + + void SHEditor::Initialise(SDL_Window* sdlWindow) + { + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + + ImGuiIO& io = ImGui::GetIO(); (void)io; + + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + + ImGui_ImplSDL2_InitForVulkan(sdlWindow); + + auto* gfxSystem = reinterpret_cast(SHSystemManager::GetSystem()); + + ImGui_ImplVulkan_InitInfo initInfo{}; + initInfo.Instance = SHVkInstance::GetVkInstance(); + initInfo.PhysicalDevice = gfxSystem->GetPhysicalDevice()->GetVkPhysicalDevice(); + initInfo.Device = gfxSystem->GetDevice()->GetVkLogicalDevice(); + initInfo.Queue = gfxSystem->GetQueue()->GetVkQueue(); + initInfo.DescriptorPool = gfxSystem->GetDescriptorPool()->GetVkHandle(); + initInfo.MinImageCount = initInfo.ImageCount = gfxSystem->GetSwapchain()->GetNumImages(); + initInfo.MSAASamples = VK_SAMPLE_COUNT_1_BIT; + + imguiCommandPool = gfxSystem->GetDevice()->CreateCommandPool(SH_QUEUE_FAMILY_ARRAY_INDEX::GRAPHICS, SH_CMD_POOL_RESET::POOL_BASED, true); + imguiCommandBuffer = imguiCommandPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY); + + auto renderPass = gfxSystem->GetRenderGraph().GetNode("ImGui Node")->GetRenderpass(); + ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass()); + + imguiCommandBuffer->BeginRecording(); + ImGui_ImplVulkan_CreateFontsTexture(imguiCommandBuffer->GetVkCommandBuffer()); + imguiCommandBuffer->EndRecording(); + gfxSystem->GetQueue()->SubmitCommandBuffer({imguiCommandBuffer}, {}, {}, vk::PipelineStageFlagBits::eNone, {}); + + ImGui_ImplVulkan_DestroyFontUploadObjects(); + + gfxSystem->GetRenderGraph().GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle& cmd) { + ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer()); + }); + + //ImGuiIO& io = ImGui::GetIO(); + //int w, h; + //SDL_GetWindowSize(sdlWindow, &w, &h); + //io.DisplaySize = { static_cast(w),static_cast(h)}; + } + + void SHEditor::PreRender() + { + NewFrame(); + + ImGui::ShowDemoWindow(); + ImGui::Begin("Your mom"); + if (ImGui::Button("OP")) + { + std::cout << "HEHEHEOHEIOHIEOH\n"; + } + ImGui::End(); + } + + void SHEditor::Render() + { + ImGui::Render(); + ImGuiIO& io = ImGui::GetIO(); + if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) + { + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + } + } + + void SHEditor::Exit() + { + ImGui_ImplVulkan_Shutdown(); + ImGui_ImplSDL2_Shutdown(); + ImGui::DestroyContext(); + } + + + void SHEditor::InitBackend() + { + } + + void SHEditor::NewFrame() + { + ImGui_ImplVulkan_NewFrame(); + ImGui_ImplSDL2_NewFrame(); + ImGui::NewFrame(); + } + + void SHEditor::EndFrame() + { + } +} diff --git a/SHADE_Engine/src/Editor/SHEditor.h b/SHADE_Engine/src/Editor/SHEditor.h new file mode 100644 index 00000000..18ce92c1 --- /dev/null +++ b/SHADE_Engine/src/Editor/SHEditor.h @@ -0,0 +1,29 @@ +#pragma once + +#include "SH_API.h" +#include + +#include "Resource/Handle.h" + + +namespace SHADE +{ + class SHVkCommandBuffer; + class SHVkCommandPool; + + class SH_API SHEditor + { + public: + static void Initialise(SDL_Window* sdlWindow); + static void PreRender(); + static void Render(); + static void Exit(); + private: + static void InitBackend(); + static void NewFrame(); + static void EndFrame(); + + static Handle imguiCommandPool; + static Handle imguiCommandBuffer; + }; +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 573e1905..bb5bfc8b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -104,15 +104,19 @@ namespace SHADE // First subpass to write to G-Buffer auto writeSubpass = node->AddSubpass("G-Buffer Write"); writeSubpass->AddColorOutput("Position"); - writeSubpass->AddColorOutput("Present"); + //writeSubpass->AddColorOutput("Present"); // Second subpass to read from G-Buffer - auto compositeSubpass = node->AddSubpass("G-Buffer Composite"); - compositeSubpass->AddColorOutput("Composite"); - compositeSubpass->AddInput("Normals"); - compositeSubpass->AddInput("Position"); + //auto compositeSubpass = node->AddSubpass("G-Buffer Composite"); + // compositeSubpass->AddColorOutput("Composite"); + // compositeSubpass->AddInput("Normals"); + // compositeSubpass->AddInput("Position"); - //auto compositeNode = renderGraph.AddNode("Bloom", { "Composite", "Downscale", "Present" }, { "G-Buffer" }); + auto imguiNode = renderGraph.AddNode("ImGui Node", { "Present" }, {}); // no predecessors + auto imguiSubpass = imguiNode->AddSubpass("ImGui Draw"); + imguiSubpass->AddColorOutput("Present"); + + //auto compositeNode = renderGraph.AddNode("Bloom", { "Composite", "Downscale", "Present" }, { "G-Buffer" }); //auto bloomSubpass = compositeNode->AddSubpass("Downsample"); //bloomSubpass->AddInput("Composite"); //bloomSubpass->AddColorOutput("Downscale"); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index d5d71450..bd1ccc9b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -147,6 +147,7 @@ namespace SHADE SHRenderContext renderContext; //std::array, NUM_FRAME_BUFFERS> frameBuffers; //std::array, NUM_FRAME_BUFFERS> commandBuffers; + // Not Owned Resources SHWindow* window; // Renderers diff --git a/SHADE_Engine/src/Graphics/Queues/SHVkQueue.cpp b/SHADE_Engine/src/Graphics/Queues/SHVkQueue.cpp index 6ed6def6..828f2974 100644 --- a/SHADE_Engine/src/Graphics/Queues/SHVkQueue.cpp +++ b/SHADE_Engine/src/Graphics/Queues/SHVkQueue.cpp @@ -124,4 +124,9 @@ namespace SHADE return result; } + vk::Queue SHVkQueue::GetVkQueue() noexcept + { + return vkQueue; + } + } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h b/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h index 042bc4bb..9d865ee9 100644 --- a/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h +++ b/SHADE_Engine/src/Graphics/Queues/SHVkQueue.h @@ -49,6 +49,7 @@ namespace SHADE void SubmitCommandBuffer (std::initializer_list> cmdBuffers, std::initializer_list> signalSems = {}, std::initializer_list> waitSems = {}, vk::PipelineStageFlags waitDstStageMask = {}, Handle const& fence = {}) noexcept; vk::Result Present (Handle const& swapchain, std::initializer_list> waitSems, uint32_t frameIndex) noexcept; + vk::Queue GetVkQueue() noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp index a2647b74..41633e55 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.cpp @@ -583,6 +583,11 @@ namespace SHADE return renderpass; } + Handle SHRenderGraphNode::GetSubpass(std::string_view subpassName) const noexcept + { + return subpasses[subpassIndexing.at(subpassName.data())]; + } + /***************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h index 719c2d46..fb843bc2 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraph.h @@ -215,7 +215,7 @@ namespace SHADE /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ Handle GetRenderpass (void) const noexcept; - + Handle GetSubpass(std::string_view subpassName) const noexcept; friend class SHRenderGraph; };