Add ui logic for renderer

This commit is contained in:
2021-07-31 01:59:11 +02:00
parent 7813920951
commit f96de2123f
5 changed files with 69 additions and 6 deletions

View File

@@ -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 <string>
#include "Base/ITickable.hpp"
#include "Base/ICloseable.hpp"
#include "Scene/Scene.hpp"
#include "Scene/UI/UI.hpp"
#include <string>
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;
};
}

View File

@@ -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 <memory>
#include <vector>
namespace openVulkanoCpp::Scene::UI
{
class UiElement : public ITickable
{
public:
std::vector<std::shared_ptr<UiElement>> 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 {}
};
}

View File

@@ -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<Scene::Drawable*>* jobQueue, uint32_t id);

View File

@@ -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);

View File

@@ -7,6 +7,7 @@
#pragma once
#include "RenderPass.hpp"
#include "Scene/UI/UI.hpp"
#include <vulkan/vulkan.hpp>
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; }
};
}