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
|
||||
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_TAG v1.89.8-docking
|
||||
GIT_TAG v1.90-docking
|
||||
SOURCE_DIR ${IMGUI_SRC_DIR}
|
||||
)
|
||||
|
||||
|
||||
@@ -17,25 +17,34 @@ namespace openVulkanoCpp::Scene::UI
|
||||
public:
|
||||
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() const
|
||||
void Render()
|
||||
{
|
||||
BeginDraw();
|
||||
Draw();
|
||||
for(const auto& child : children)
|
||||
{
|
||||
child->Render();
|
||||
}
|
||||
EndDraw();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void BeginDraw() {};
|
||||
|
||||
virtual void Draw() = 0;
|
||||
|
||||
virtual void EndDraw() {};
|
||||
};
|
||||
|
||||
class Ui : public UiElement
|
||||
{
|
||||
public:
|
||||
void Draw() const override {}
|
||||
virtual void Init() = 0;
|
||||
|
||||
void Draw() override {}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
vk::ClearValue* clearValues = nullptr;
|
||||
if (m_useClearColor) { size++; clearValues = m_clearValues.data(); }
|
||||
else if (m_useClearDepth) clearValues = &m_clearValues[1];
|
||||
if (m_useClearDepth) size++;
|
||||
if (m_useClearColor && m_useClearDepth) size++;
|
||||
|
||||
m_beginInfo.clearValueCount = size;
|
||||
m_beginInfo.pClearValues = clearValues;
|
||||
|
||||
@@ -62,10 +62,14 @@ namespace openVulkanoCpp::Vulkan
|
||||
#ifdef GLFW_AVAILABLE
|
||||
ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)context->window->GetNativeWindowHandle(), true);
|
||||
#endif
|
||||
|
||||
uiInitialized = true;
|
||||
if (ui) ui->Init();
|
||||
}
|
||||
|
||||
void UiRenderer::Close()
|
||||
{
|
||||
uiInitialized = false;
|
||||
ImGui_ImplVulkan_Shutdown();
|
||||
device.destroy(descriptorPool);
|
||||
}
|
||||
@@ -91,4 +95,10 @@ namespace openVulkanoCpp::Vulkan
|
||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), 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;
|
||||
vk::DescriptorPool descriptorPool;
|
||||
Scene::UI::Ui* ui;
|
||||
bool uiInitialized = false;
|
||||
|
||||
public:
|
||||
UiRenderer() = default;
|
||||
@@ -36,7 +37,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
void Close();
|
||||
|
||||
void SetActiveUi(Scene::UI::Ui* ui) { this->ui = ui; }
|
||||
void SetActiveUi(Scene::UI::Ui* ui);
|
||||
|
||||
Scene::UI::Ui* GetActiveUi() { return ui; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user