Fix issues with ui rendering
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ namespace openVulkanoCpp::GLFW
|
||||
|
||||
void PlatformGLFW::Close()
|
||||
{
|
||||
windows.clear();
|
||||
inputProvider.Close();
|
||||
glfwTerminate();
|
||||
windows.clear();
|
||||
}
|
||||
|
||||
IWindow* PlatformGLFW::MakeWindow()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
resourceManager.Close();
|
||||
context.Close();
|
||||
uiRenderer.Close();
|
||||
}
|
||||
|
||||
std::string Renderer::GetMainRenderDeviceName()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user