diff --git a/openVulkanoCpp/Base/Render/IRenderer.hpp b/openVulkanoCpp/Base/Render/IRenderer.hpp index c37ab53..6610e42 100644 --- a/openVulkanoCpp/Base/Render/IRenderer.hpp +++ b/openVulkanoCpp/Base/Render/IRenderer.hpp @@ -1,8 +1,16 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + #pragma once -#include + #include "Base/ITickable.hpp" #include "Base/ICloseable.hpp" #include "Scene/Scene.hpp" +#include "Scene/UI/UI.hpp" +#include namespace openVulkanoCpp { @@ -21,5 +29,8 @@ namespace openVulkanoCpp virtual void SetScene(Scene::Scene* scene) = 0; virtual Scene::Scene* GetScene() = 0; + + virtual void SetActiveUi(Scene::UI::Ui* ui) = 0; + virtual Scene::UI::Ui* GetActiveUi() = 0; }; } diff --git a/openVulkanoCpp/Scene/UI/UI.hpp b/openVulkanoCpp/Scene/UI/UI.hpp new file mode 100644 index 0000000..8888728 --- /dev/null +++ b/openVulkanoCpp/Scene/UI/UI.hpp @@ -0,0 +1,41 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Base/ITickable.hpp" +#include +#include + +namespace openVulkanoCpp::Scene::UI +{ + class UiElement : public ITickable + { + public: + std::vector> children; + + virtual ~UiElement() override = default; + + virtual void Tick() override {}; + + virtual void Draw() const; + + void Render() const + { + Draw(); + for(const auto& child : children) + { + child->Render(); + } + } + }; + + class Ui : public UiElement + { + public: + void Draw() const override {} + }; +} diff --git a/openVulkanoCpp/Vulkan/Renderer.hpp b/openVulkanoCpp/Vulkan/Renderer.hpp index 0bbe469..5cad618 100644 --- a/openVulkanoCpp/Vulkan/Renderer.hpp +++ b/openVulkanoCpp/Vulkan/Renderer.hpp @@ -57,6 +57,10 @@ namespace openVulkanoCpp::Vulkan Scene::Scene* GetScene() override { return scene; } + void SetActiveUi(Scene::UI::Ui* ui) override { uiRenderer.SetActiveUi(ui); } + + Scene::UI::Ui* GetActiveUi() override { return uiRenderer.GetActiveUi(); } + CommandHelper* GetCommandData(uint32_t poolId); static void RunThread(Renderer* renderer, Data::ReadOnlyAtomicArrayQueue* jobQueue, uint32_t id); diff --git a/openVulkanoCpp/Vulkan/UiRenderer.cpp b/openVulkanoCpp/Vulkan/UiRenderer.cpp index f075109..8bd8ef9 100644 --- a/openVulkanoCpp/Vulkan/UiRenderer.cpp +++ b/openVulkanoCpp/Vulkan/UiRenderer.cpp @@ -44,7 +44,7 @@ namespace openVulkanoCpp::Vulkan vkInfo.Device = context->device->device; vkInfo.QueueFamily = context->device->queueIndices.GetGraphics(); vkInfo.Queue = context->device->graphicsQueue; - //vkInfo.PipelineCache = NULL; + //vkInfo.PipelineCache = ; vkInfo.DescriptorPool = descriptorPool; vkInfo.Subpass = 0; vkInfo.MinImageCount = context->swapChain.GetImageCount(); @@ -54,12 +54,11 @@ namespace openVulkanoCpp::Vulkan ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls - io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls + io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; + io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; ImGui_ImplVulkan_Init(&vkInfo, uiRenderPass.renderPass); - //ImGui_ImplVulkan_Init(&vkInfo, context->swapChainRenderPass.renderPass); #ifdef GLFW_AVAILABLE ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)context->window->GetNativeWindowHandle(), true); #endif @@ -82,8 +81,10 @@ namespace openVulkanoCpp::Vulkan void UiRenderer::DrawUiFrame(vk::CommandBuffer& cmdBuffer) { + if (!ui) return; BeginUiFrame(); - ImGui::ShowDemoWindow(); + + ui->Render(); ImGui::Render(); uiRenderPass.Begin(cmdBuffer, true); diff --git a/openVulkanoCpp/Vulkan/UiRenderer.hpp b/openVulkanoCpp/Vulkan/UiRenderer.hpp index 2c115ea..2eee555 100644 --- a/openVulkanoCpp/Vulkan/UiRenderer.hpp +++ b/openVulkanoCpp/Vulkan/UiRenderer.hpp @@ -7,6 +7,7 @@ #pragma once #include "RenderPass.hpp" +#include "Scene/UI/UI.hpp" #include namespace openVulkanoCpp::Vulkan @@ -18,6 +19,7 @@ namespace openVulkanoCpp::Vulkan vk::Device device; RenderPass uiRenderPass; vk::DescriptorPool descriptorPool; + Scene::UI::Ui* ui; public: UiRenderer() = default; @@ -33,5 +35,9 @@ namespace openVulkanoCpp::Vulkan void DrawUiFrame(vk::CommandBuffer& cmdBuffer); void Close(); + + void SetActiveUi(Scene::UI::Ui* ui) { this->ui = ui; } + + Scene::UI::Ui* GetActiveUi() { return ui; } }; } \ No newline at end of file