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

@@ -15,6 +15,7 @@ namespace openVulkanoCpp
protected:
const uint32_t windowId;
WindowConfiguration windowConfig;
bool destroyed = false;
public:
BaseWindow() : windowId(CreateWindowId()) {}
@@ -63,5 +64,15 @@ namespace openVulkanoCpp
{
return windowId;
}
bool WindowHasBeenDestroyed() const final
{
return destroyed;
}
void SetWindowHasBeenDestroyed() final
{
destroyed = true;
}
};
}

View File

@@ -41,6 +41,9 @@ namespace openVulkanoCpp
virtual void Init(RenderAPI::RenderApi renderApi) = 0;
virtual bool WindowHasBeenDestroyed() const = 0;
virtual void SetWindowHasBeenDestroyed() = 0;
virtual bool HasTitle() = 0;
virtual const std::string& GetTitle() = 0;
virtual void SetTitle(const std::string& title) = 0;

View File

@@ -57,14 +57,14 @@ public:
shader.AddShaderProgram(openVulkanoCpp::ShaderProgramType::FRAGMENT, "Shader/basic");
shader.AddVertexInputDescription(openVulkanoCpp::Vertex::GetVertexInputDescription());
drawablesPool.resize(GEOS);
for(int i = 0; i < GEOS; i++)
for(uint32_t i = 0; i < GEOS; i++)
{
Geometry* geo = new Geometry();
geo->InitCube(std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, std::rand() % 1000 / 1000.0f + 0.01f, Vector4f((std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, (std::rand() % 255) / 255.0f, 1));
drawablesPool[i].Init(&shader, geo, &mat);
}
nodesPool.resize(OBJECTS);
for(int i = 0; i < OBJECTS; i++)
for(uint32_t i = 0; i < OBJECTS; i++)
{
nodesPool[i].Init();
scene.GetRoot()->AddChild(&nodesPool[i]);
@@ -81,7 +81,7 @@ public:
void Tick() override
{
for(int i = 0; i < DYNAMIC; i++)
for(uint32_t i = 0; i < DYNAMIC; i++)
{
nodesPool[i].SetMatrix(glm::translate(glm::mat4x4(1), glm::vec3((std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5, (std::rand() % 10000) / 1000.0f - 5)));
}

View File

@@ -46,9 +46,9 @@ namespace openVulkanoCpp::GLFW
void PlatformGLFW::Close()
{
windows.clear();
inputProvider.Close();
glfwTerminate();
windows.clear();
}
IWindow* PlatformGLFW::MakeWindow()

View File

@@ -141,8 +141,8 @@ namespace openVulkanoCpp
Logger::MANAGER->info("Shutting down ...");
renderer->Close();
window->Close();
platform->Close();
app->Close();
platform->Close();
windowTitleFormat = "";
Logger::MANAGER->info("Shutdown complete");
}
@@ -196,6 +196,7 @@ namespace openVulkanoCpp
void GraphicsAppManager::OnWindowClose(openVulkanoCpp::IWindow* window)
{
window->SetWindowHasBeenDestroyed();
if (window != this->window) return;
Stop();
}

View File

@@ -106,7 +106,7 @@ namespace openVulkanoCpp::Scene
{
CheckShaderInitState();
if (bindingId < 0) bindingId = static_cast<int>(vertexInputDescriptions.size());
while (bindingId > vertexInputDescriptions.size())
while (bindingId > static_cast<int>(vertexInputDescriptions.size()))
{
vertexInputDescriptions.emplace_back(0, 0);
}
@@ -127,7 +127,7 @@ namespace openVulkanoCpp::Scene
if (setId < 0) setId = static_cast<int>(descriptorSets.size() + 2);
if (setId < 2) throw std::runtime_error("Cant bind set id 0 or 1!");
setId -= 2;
while (setId >= descriptorSets.size())
while (setId >= static_cast<int>(descriptorSets.size()))
{
descriptorSets.emplace_back();
}

View File

@@ -27,7 +27,8 @@ namespace openVulkanoCpp::Scene::UI
Draw();
for(const auto& child : children)
{
child->Render();
if (child->ShouldDraw())
child->Render();
}
EndDraw();
}
@@ -38,6 +39,8 @@ namespace openVulkanoCpp::Scene::UI
virtual void Draw() = 0;
virtual void EndDraw() {};
virtual bool ShouldDraw() { return true; }
};
class Ui : public UiElement

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