Fix issues with UI renderer
This commit is contained in:
2
3rdParty/imgui/CMakeLists.txt
vendored
2
3rdParty/imgui/CMakeLists.txt
vendored
@@ -7,7 +7,7 @@ set(IMGUI_SRC_DIR ${CMAKE_BINARY_DIR}/3rdParty/imgui/imgui-src)
|
|||||||
FetchContent_Populate(imgui
|
FetchContent_Populate(imgui
|
||||||
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
GIT_TAG v1.89.8-docking
|
GIT_TAG v1.90-docking
|
||||||
SOURCE_DIR ${IMGUI_SRC_DIR}
|
SOURCE_DIR ${IMGUI_SRC_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -17,25 +17,34 @@ namespace openVulkanoCpp::Scene::UI
|
|||||||
public:
|
public:
|
||||||
std::vector<std::shared_ptr<UiElement>> children;
|
std::vector<std::shared_ptr<UiElement>> children;
|
||||||
|
|
||||||
virtual ~UiElement() override = default;
|
~UiElement() override = default;
|
||||||
|
|
||||||
virtual void Tick() override {};
|
void Tick() override {};
|
||||||
|
|
||||||
virtual void Draw() const;
|
void Render()
|
||||||
|
|
||||||
void Render() const
|
|
||||||
{
|
{
|
||||||
|
BeginDraw();
|
||||||
Draw();
|
Draw();
|
||||||
for(const auto& child : children)
|
for(const auto& child : children)
|
||||||
{
|
{
|
||||||
child->Render();
|
child->Render();
|
||||||
}
|
}
|
||||||
|
EndDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginDraw() {};
|
||||||
|
|
||||||
|
virtual void Draw() = 0;
|
||||||
|
|
||||||
|
virtual void EndDraw() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Ui : public UiElement
|
class Ui : public UiElement
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Draw() const override {}
|
virtual void Init() = 0;
|
||||||
|
|
||||||
|
void Draw() override {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
vk::ClearValue* clearValues = nullptr;
|
vk::ClearValue* clearValues = nullptr;
|
||||||
if (m_useClearColor) { size++; clearValues = m_clearValues.data(); }
|
if (m_useClearColor) { size++; clearValues = m_clearValues.data(); }
|
||||||
else if (m_useClearDepth) clearValues = &m_clearValues[1];
|
else if (m_useClearDepth) clearValues = &m_clearValues[1];
|
||||||
if (m_useClearDepth) size++;
|
if (m_useClearColor && m_useClearDepth) size++;
|
||||||
|
|
||||||
m_beginInfo.clearValueCount = size;
|
m_beginInfo.clearValueCount = size;
|
||||||
m_beginInfo.pClearValues = clearValues;
|
m_beginInfo.pClearValues = clearValues;
|
||||||
|
|||||||
@@ -62,10 +62,14 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
#ifdef GLFW_AVAILABLE
|
#ifdef GLFW_AVAILABLE
|
||||||
ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)context->window->GetNativeWindowHandle(), true);
|
ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)context->window->GetNativeWindowHandle(), true);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
uiInitialized = true;
|
||||||
|
if (ui) ui->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiRenderer::Close()
|
void UiRenderer::Close()
|
||||||
{
|
{
|
||||||
|
uiInitialized = false;
|
||||||
ImGui_ImplVulkan_Shutdown();
|
ImGui_ImplVulkan_Shutdown();
|
||||||
device.destroy(descriptorPool);
|
device.destroy(descriptorPool);
|
||||||
}
|
}
|
||||||
@@ -91,4 +95,10 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmdBuffer);
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmdBuffer);
|
||||||
uiRenderPass.End(cmdBuffer);
|
uiRenderPass.End(cmdBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiRenderer::SetActiveUi(Scene::UI::Ui* ui)
|
||||||
|
{
|
||||||
|
this->ui = ui;
|
||||||
|
if (ui && uiInitialized) ui->Init();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
RenderPass uiRenderPass;
|
RenderPass uiRenderPass;
|
||||||
vk::DescriptorPool descriptorPool;
|
vk::DescriptorPool descriptorPool;
|
||||||
Scene::UI::Ui* ui;
|
Scene::UI::Ui* ui;
|
||||||
|
bool uiInitialized = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UiRenderer() = default;
|
UiRenderer() = default;
|
||||||
@@ -36,7 +37,7 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
|
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
void SetActiveUi(Scene::UI::Ui* ui) { this->ui = ui; }
|
void SetActiveUi(Scene::UI::Ui* ui);
|
||||||
|
|
||||||
Scene::UI::Ui* GetActiveUi() { return ui; }
|
Scene::UI::Ui* GetActiveUi() { return ui; }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user