Start imgui integration

This commit is contained in:
2021-07-31 01:02:03 +02:00
parent f34f7a659d
commit 7813920951
10 changed files with 200 additions and 2 deletions

View File

@@ -32,6 +32,7 @@ namespace openVulkanoCpp::Vulkan
waitSemaphores[i].renderReady.resize(2);
}
resourceManager.Init(&context, context.swapChain.GetImageCount());
uiRenderer.Init(&context);
threadPool.resize(EngineConfiguration::GetEngineConfiguration()->GetNumThreads() - 1);
//Setup cmd pools and buffers
@@ -116,6 +117,7 @@ namespace openVulkanoCpp::Vulkan
CommandHelper* cmdHelper = GetCommandData(commands.size() - 1);
cmdHelper->cmdBuffer.executeCommands(submitBuffers[currentImageId].size(), submitBuffers[currentImageId].data());
context.swapChainRenderPass.End(cmdHelper->cmdBuffer);
uiRenderer.DrawUiFrame(cmdHelper->cmdBuffer);
cmdHelper->cmdBuffer.end();
std::array<vk::PipelineStageFlags, 2> stateFlags = { vk::PipelineStageFlags(vk::PipelineStageFlagBits::eColorAttachmentOutput), vk::PipelineStageFlags(vk::PipelineStageFlagBits::eColorAttachmentOutput) };
waitSemaphores[currentImageId].renderReady[0] = resourceManager.EndFrame();

View File

@@ -10,6 +10,7 @@
#include "Base/UI/IWindow.hpp"
#include "Base/Logger.hpp"
#include "Context.hpp"
#include "UiRenderer.hpp"
#include "Resources/ResourceManager.hpp"
#include "Data/ReadOnlyAtomicArrayQueue.hpp"
#include "CommandHelper.hpp"
@@ -35,11 +36,12 @@ namespace openVulkanoCpp::Vulkan
std::vector<std::thread> threadPool;
std::vector<std::vector<CommandHelper>> commands;
std::vector<std::vector<vk::CommandBuffer>> submitBuffers;
UiRenderer uiRenderer;
VulkanShader* shader;
public:
Renderer() = default;
virtual ~Renderer() = default;
~Renderer() override = default;
void Init(IGraphicsAppManager* graphicsAppManager, IWindow* window) override;

View File

@@ -0,0 +1,93 @@
/*
* 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/.
*/
#include "UiRenderer.hpp"
#include "Context.hpp"
#include "Base/UI/IVulkanWindow.hpp"
#include <array>
#include <imgui_impl_vulkan.h>
#if __has_include("GLFW/glfw3.h")
#include <imgui_impl_glfw.h>
#define GLFW_AVAILABLE
#endif
namespace openVulkanoCpp::Vulkan
{
void UiRenderer::Init(Context* context)
{
device = context->device->device;
uiRenderPass.Init(context->device.get(), &context->swapChain, false, true);
constexpr vk::DescriptorPoolSize sizeInfo[] = {
{ vk::DescriptorType::eSampler, 1000 },
{ vk::DescriptorType::eCombinedImageSampler, 1000 },
{ vk::DescriptorType::eSampledImage, 1000 },
{ vk::DescriptorType::eStorageImage, 1000 },
{ vk::DescriptorType::eUniformTexelBuffer, 1000 },
{ vk::DescriptorType::eStorageTexelBuffer, 1000 },
{ vk::DescriptorType::eUniformBuffer, 1000 },
{ vk::DescriptorType::eStorageBuffer, 1000 },
{ vk::DescriptorType::eUniformBufferDynamic, 1000 },
{ vk::DescriptorType::eStorageBufferDynamic, 1000 },
{ vk::DescriptorType::eInputAttachment, 1000 }
};
vk::DescriptorPoolCreateInfo poolCreateInfo(vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet, 1000, std::size(sizeInfo), sizeInfo);
descriptorPool = context->device->device.createDescriptorPool(poolCreateInfo);
ImGui_ImplVulkan_InitInfo vkInfo{};
vkInfo.Instance = context->instance;
vkInfo.PhysicalDevice = context->device->physicalDevice;
vkInfo.Device = context->device->device;
vkInfo.QueueFamily = context->device->queueIndices.GetGraphics();
vkInfo.Queue = context->device->graphicsQueue;
//vkInfo.PipelineCache = NULL;
vkInfo.DescriptorPool = descriptorPool;
vkInfo.Subpass = 0;
vkInfo.MinImageCount = context->swapChain.GetImageCount();
vkInfo.ImageCount = context->swapChain.GetImageCount();
vkInfo.MSAASamples = VK_SAMPLE_COUNT_1_BIT;
vkInfo.UseDynamicRendering = false;
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_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
}
void UiRenderer::Close()
{
ImGui_ImplVulkan_Shutdown();
device.destroy(descriptorPool);
}
void UiRenderer::BeginUiFrame() const
{
ImGui_ImplVulkan_NewFrame();
#ifdef GLFW_AVAILABLE
ImGui_ImplGlfw_NewFrame();
#endif
ImGui::NewFrame();
}
void UiRenderer::DrawUiFrame(vk::CommandBuffer& cmdBuffer)
{
BeginUiFrame();
ImGui::ShowDemoWindow();
ImGui::Render();
uiRenderPass.Begin(cmdBuffer, true);
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmdBuffer);
uiRenderPass.End(cmdBuffer);
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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 "RenderPass.hpp"
#include <vulkan/vulkan.hpp>
namespace openVulkanoCpp::Vulkan
{
class Context;
class UiRenderer
{
vk::Device device;
RenderPass uiRenderPass;
vk::DescriptorPool descriptorPool;
public:
UiRenderer() = default;
UiRenderer(Context* context) { Init(context); }
~UiRenderer() { if (descriptorPool) Close(); }
void Init(Context* context);
void BeginUiFrame() const;
void DrawUiFrame(vk::CommandBuffer& cmdBuffer);
void Close();
};
}