Fix issues with ui rendering

This commit is contained in:
2023-09-08 18:17:16 +02:00
parent 2bcea0d7fd
commit 703f5c0d12
12 changed files with 43 additions and 50 deletions

View File

@@ -20,6 +20,8 @@ namespace openVulkanoCpp::Vulkan
frameBuffer->RegisterRenderPass(this);
m_beginInfo.renderPass = renderPass;
m_beginInfo.renderArea = vk::Rect2D(vk::Offset2D(), m_frameBuffer->GetSize2D());
m_beginInfo.clearValueCount = 2;
m_beginInfo.pClearValues = m_clearValues.data();
if (clearColor) SetClearColor(EngineConfiguration::GetEngineConfiguration()->GetFrameBufferClearColor());
if (clearDepth) SetClearDepth();
}
@@ -30,18 +32,6 @@ namespace openVulkanoCpp::Vulkan
m_frameBuffer = nullptr;
}
void RenderPass::UpdateBeginInfo()
{
uint32_t size = 0;
vk::ClearValue* clearValues = nullptr;
if (m_useClearColor) { size++; clearValues = m_clearValues.data(); }
else if (m_useClearDepth) clearValues = &m_clearValues[1];
if (m_useClearColor && m_useClearDepth) size++;
m_beginInfo.clearValueCount = size;
m_beginInfo.pClearValues = clearValues;
}
void RenderPass::Begin(vk::CommandBuffer& commandBuffer, bool primaryBuffer)
{
m_beginInfo.framebuffer = m_frameBuffer->GetCurrentFrameBuffer();

View File

@@ -39,43 +39,23 @@ namespace openVulkanoCpp::Vulkan
void SetClearColor(vk::ClearColorValue clearColor = vk::ClearColorValue(std::array<float, 4>{ 0.39f, 0.58f, 0.93f, 1.0f }))
{
m_clearValues[0] = clearColor;
if (!m_useClearColor)
{
m_useClearColor = true;
//TODO recreate
}
UpdateBeginInfo();
if (!m_useClearColor) m_useClearColor = true;
}
void DisableClearColor()
{
if (m_useClearColor)
{
m_useClearColor = false;
//TODO recreate
UpdateBeginInfo();
}
if (m_useClearColor) m_useClearColor = false;
}
void SetClearDepth(vk::ClearDepthStencilValue clearDepth = vk::ClearDepthStencilValue(1, 0))
{
m_clearValues[1] = clearDepth;
if (!m_useClearDepth)
{
m_useClearDepth = true;
//TODO recreate
}
UpdateBeginInfo();
if (!m_useClearDepth) m_useClearDepth = true;
}
void DisableClearDepth()
{
if (m_useClearDepth)
{
m_useClearDepth = false;
//TODO recreate
UpdateBeginInfo();
}
if (m_useClearDepth) m_useClearDepth = false;
}
void Resize(vk::Extent3D size)
@@ -84,8 +64,6 @@ namespace openVulkanoCpp::Vulkan
m_beginInfo.renderArea.extent.height = size.height;
}
virtual void UpdateBeginInfo();
virtual void Begin(vk::CommandBuffer& commandBuffer, bool primaryBuffer = false);
virtual void End(vk::CommandBuffer& commandBuffer);

View File

@@ -74,6 +74,7 @@ namespace openVulkanoCpp::Vulkan
{
resourceManager.Close();
context.Close();
uiRenderer.Close();
}
std::string Renderer::GetMainRenderDeviceName()

View File

@@ -61,10 +61,11 @@ namespace openVulkanoCpp::Vulkan
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
ImGui_ImplVulkan_Init(&vkInfo, uiRenderPass.renderPass);
window = context->window;
#ifdef GLFW_AVAILABLE
ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)context->window->GetNativeWindowHandle(), true);
ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)window->GetNativeWindowHandle(), true);
#else
ImGuiImplOpenVulkano::INSTANCE.Init(context->window);
ImGuiImplOpenVulkano::INSTANCE.Init(window);
#endif
uiInitialized = true;
@@ -75,7 +76,10 @@ namespace openVulkanoCpp::Vulkan
{
uiInitialized = false;
#ifdef GLFW_AVAILABLE
ImGui_ImplGlfw_Shutdown();
if (!window->WindowHasBeenDestroyed())
{
ImGui_ImplGlfw_Shutdown();
}
#else
ImGuiImplOpenVulkano::INSTANCE.Close();
#endif

View File

@@ -7,6 +7,7 @@
#pragma once
#include "RenderPass.hpp"
#include "Base/UI/IWindow.hpp"
#include "Scene/UI/UI.hpp"
#include <vulkan/vulkan.hpp>
@@ -20,6 +21,7 @@ namespace openVulkanoCpp::Vulkan
RenderPass uiRenderPass;
vk::DescriptorPool descriptorPool;
Scene::UI::Ui* ui;
IWindow* window = nullptr;
bool uiInitialized = false;
public:
@@ -27,7 +29,7 @@ namespace openVulkanoCpp::Vulkan
UiRenderer(Context* context) { Init(context); }
~UiRenderer() { if (descriptorPool) Close(); }
~UiRenderer() { if (uiInitialized) Close(); }
void Init(Context* context);