init vulkan for imgui
This commit is contained in:
parent
470e1f07f0
commit
eb8cbaeebb
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#define SHEDITOR
|
#define SHEDITOR
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
//#include "Editor/SHEditor.h"
|
#include "Editor/SHEditor.h"
|
||||||
//#include "Scenes/SBEditorScene.h"
|
//#include "Scenes/SBEditorScene.h"
|
||||||
#endif // SHEDITOR
|
#endif // SHEDITOR
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ratio>
|
#include <ratio>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#define SDL_HINT_VIDEO_FOREIGN_WINDOW_VULKAN 1
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "Scripting/SHScriptEngine.h"
|
#include "Scripting/SHScriptEngine.h"
|
||||||
|
@ -40,11 +41,13 @@ namespace Sandbox
|
||||||
|
|
||||||
|
|
||||||
graphicsSystem->SetWindow(&window);
|
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();
|
SHADE::SHSystemManager::Init();
|
||||||
#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
//SHADE::SHEditor::Initialize(window.GetHWND());
|
SHADE::SHEditor::Initialise(sdlWindow);
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -60,15 +63,18 @@ namespace Sandbox
|
||||||
while (!window.WindowShouldClose())
|
while (!window.WindowShouldClose())
|
||||||
{
|
{
|
||||||
//#ifdef SHEDITOR
|
//#ifdef SHEDITOR
|
||||||
//SHADE::SHEditor::PreRender();
|
|
||||||
//#endif
|
//#endif
|
||||||
graphicsSystem->BeginRender();
|
graphicsSystem->BeginRender();
|
||||||
graphicsSystem->Run(1.0f);
|
|
||||||
//#ifdef SHEDITOR
|
#ifdef SHEDITOR
|
||||||
//SHADE::SHEditor::PreRender();
|
SHADE::SHEditor::PreRender();
|
||||||
//SHADE::SHEditor::Update();
|
|
||||||
//SHADE::SHEditor::Render();
|
//SHADE::SHEditor::Render();
|
||||||
//#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SHEDITOR
|
||||||
|
SHADE::SHEditor::Render();
|
||||||
|
#endif
|
||||||
|
graphicsSystem->Run(1.0f);
|
||||||
graphicsSystem->EndRender();
|
graphicsSystem->EndRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,13 +82,14 @@ namespace Sandbox
|
||||||
|
|
||||||
void SBApplication::Exit(void)
|
void SBApplication::Exit(void)
|
||||||
{
|
{
|
||||||
|
#ifdef SHEDITOR
|
||||||
|
SHADE::SHEditor::Exit();
|
||||||
|
#endif
|
||||||
|
|
||||||
SHADE::SHScriptEngine::Exit();
|
SHADE::SHScriptEngine::Exit();
|
||||||
SHADE::SHSystemManager::Exit();
|
SHADE::SHSystemManager::Exit();
|
||||||
SDL_DestroyWindow(sdlWindow);
|
SDL_DestroyWindow(sdlWindow);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
#ifdef SHEDITOR
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,31 +3,63 @@
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
|
#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
|
//IMGUI Backend includes
|
||||||
#include <backends/imgui_impl_sdl.h>
|
#include <backends/imgui_impl_sdl.h>
|
||||||
#include <backends/imgui_impl_vulkan.h>
|
#include <backends/imgui_impl_vulkan.h>
|
||||||
|
|
||||||
#include "ECS_Base/System/SHSystemManager.h"
|
|
||||||
#include "Graphics/Instance/SHVkInstance.h"
|
|
||||||
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
Handle<SHVkCommandPool> SHEditor::imguiCommandPool;
|
||||||
|
Handle<SHVkCommandBuffer> SHEditor::imguiCommandBuffer;
|
||||||
|
|
||||||
void SHEditor::Initialise(SDL_Window* sdlWindow)
|
void SHEditor::Initialise(SDL_Window* sdlWindow)
|
||||||
{
|
{
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
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);
|
ImGui_ImplSDL2_InitForVulkan(sdlWindow);
|
||||||
|
|
||||||
auto* gfxSystem = reinterpret_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem("Graphics System"));
|
auto* gfxSystem = reinterpret_cast<SHGraphicsSystem*>(SHSystemManager::GetSystem<SHGraphicsSystem>());
|
||||||
|
|
||||||
ImGui_ImplVulkan_InitInfo initInfo{};
|
ImGui_ImplVulkan_InitInfo initInfo{};
|
||||||
initInfo.Instance = SHVkInstance::GetVkInstance();
|
initInfo.Instance = SHVkInstance::GetVkInstance();
|
||||||
initInfo.PhysicalDevice =
|
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();
|
||||||
|
|
||||||
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
||||||
|
|
||||||
|
gfxSystem->GetRenderGraph().GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle<SHVkCommandBuffer>& cmd) {
|
||||||
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer());
|
||||||
|
});
|
||||||
|
|
||||||
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
|
//int w, h;
|
||||||
|
//SDL_GetWindowSize(sdlWindow, &w, &h);
|
||||||
|
//io.DisplaySize = { static_cast<float>(w),static_cast<float>(h)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHEditor::PreRender()
|
void SHEditor::PreRender()
|
||||||
|
@ -40,6 +72,12 @@ namespace SHADE
|
||||||
void SHEditor::Render()
|
void SHEditor::Render()
|
||||||
{
|
{
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
|
{
|
||||||
|
ImGui::UpdatePlatformWindows();
|
||||||
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHEditor::Exit()
|
void SHEditor::Exit()
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "SH_API.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
|
#include "Resource/Handle.h"
|
||||||
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
class SHEditor
|
class SHVkCommandBuffer;
|
||||||
|
class SHVkCommandPool;
|
||||||
|
|
||||||
|
class SH_API SHEditor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Initialise(SDL_Window* sdlWindow);
|
static void Initialise(SDL_Window* sdlWindow);
|
||||||
|
@ -15,5 +22,8 @@ namespace SHADE
|
||||||
static void InitBackend();
|
static void InitBackend();
|
||||||
static void NewFrame();
|
static void NewFrame();
|
||||||
static void EndFrame();
|
static void EndFrame();
|
||||||
|
|
||||||
|
static Handle<SHVkCommandPool> imguiCommandPool;
|
||||||
|
static Handle<SHVkCommandBuffer> imguiCommandBuffer;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -104,15 +104,19 @@ namespace SHADE
|
||||||
// First subpass to write to G-Buffer
|
// First subpass to write to G-Buffer
|
||||||
auto writeSubpass = node->AddSubpass("G-Buffer Write");
|
auto writeSubpass = node->AddSubpass("G-Buffer Write");
|
||||||
writeSubpass->AddColorOutput("Position");
|
writeSubpass->AddColorOutput("Position");
|
||||||
writeSubpass->AddColorOutput("Present");
|
//writeSubpass->AddColorOutput("Present");
|
||||||
|
|
||||||
// Second subpass to read from G-Buffer
|
// Second subpass to read from G-Buffer
|
||||||
auto compositeSubpass = node->AddSubpass("G-Buffer Composite");
|
//auto compositeSubpass = node->AddSubpass("G-Buffer Composite");
|
||||||
compositeSubpass->AddColorOutput("Composite");
|
// compositeSubpass->AddColorOutput("Composite");
|
||||||
compositeSubpass->AddInput("Normals");
|
// compositeSubpass->AddInput("Normals");
|
||||||
compositeSubpass->AddInput("Position");
|
// 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");
|
//auto bloomSubpass = compositeNode->AddSubpass("Downsample");
|
||||||
//bloomSubpass->AddInput("Composite");
|
//bloomSubpass->AddInput("Composite");
|
||||||
//bloomSubpass->AddColorOutput("Downscale");
|
//bloomSubpass->AddColorOutput("Downscale");
|
||||||
|
|
|
@ -147,6 +147,7 @@ namespace SHADE
|
||||||
SHRenderContext renderContext;
|
SHRenderContext renderContext;
|
||||||
//std::array<Handle<SHVkFramebuffer>, NUM_FRAME_BUFFERS> frameBuffers;
|
//std::array<Handle<SHVkFramebuffer>, NUM_FRAME_BUFFERS> frameBuffers;
|
||||||
//std::array<Handle<SHVkCommandBuffer>, NUM_FRAME_BUFFERS> commandBuffers;
|
//std::array<Handle<SHVkCommandBuffer>, NUM_FRAME_BUFFERS> commandBuffers;
|
||||||
|
|
||||||
// Not Owned Resources
|
// Not Owned Resources
|
||||||
SHWindow* window;
|
SHWindow* window;
|
||||||
// Renderers
|
// Renderers
|
||||||
|
|
|
@ -124,4 +124,9 @@ namespace SHADE
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vk::Queue SHVkQueue::GetVkQueue() noexcept
|
||||||
|
{
|
||||||
|
return vkQueue;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -49,6 +49,7 @@ namespace SHADE
|
||||||
|
|
||||||
void SubmitCommandBuffer (std::initializer_list<Handle<SHVkCommandBuffer>> cmdBuffers, std::initializer_list<Handle<SHVkSemaphore>> signalSems = {}, std::initializer_list<Handle<SHVkSemaphore>> waitSems = {}, vk::PipelineStageFlags waitDstStageMask = {}, Handle<SHVkFence> const& fence = {}) noexcept;
|
void SubmitCommandBuffer (std::initializer_list<Handle<SHVkCommandBuffer>> cmdBuffers, std::initializer_list<Handle<SHVkSemaphore>> signalSems = {}, std::initializer_list<Handle<SHVkSemaphore>> waitSems = {}, vk::PipelineStageFlags waitDstStageMask = {}, Handle<SHVkFence> const& fence = {}) noexcept;
|
||||||
vk::Result Present (Handle<SHVkSwapchain> const& swapchain, std::initializer_list<Handle<SHVkSemaphore>> waitSems, uint32_t frameIndex) noexcept;
|
vk::Result Present (Handle<SHVkSwapchain> const& swapchain, std::initializer_list<Handle<SHVkSemaphore>> waitSems, uint32_t frameIndex) noexcept;
|
||||||
|
vk::Queue GetVkQueue() noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -583,6 +583,11 @@ namespace SHADE
|
||||||
return renderpass;
|
return renderpass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle<SHRenderGraphNode::SHSubpass> SHRenderGraphNode::GetSubpass(std::string_view subpassName) const noexcept
|
||||||
|
{
|
||||||
|
return subpasses[subpassIndexing.at(subpassName.data())];
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ namespace SHADE
|
||||||
/* SETTERS AND GETTERS */
|
/* SETTERS AND GETTERS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
Handle<SHVkRenderpass> GetRenderpass (void) const noexcept;
|
Handle<SHVkRenderpass> GetRenderpass (void) const noexcept;
|
||||||
|
Handle<SHSubpass> GetSubpass(std::string_view subpassName) const noexcept;
|
||||||
friend class SHRenderGraph;
|
friend class SHRenderGraph;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue