Add imgui rendering ability on none glfw windows
This commit is contained in:
69
openVulkanoCpp/Host/ImGuiImplOpenVulkano.cpp
Normal file
69
openVulkanoCpp/Host/ImGuiImplOpenVulkano.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ImGuiImplOpenVulkano.hpp"
|
||||||
|
#include "Base/FrameMetadata.hpp"
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
|
namespace openVulkanoCpp
|
||||||
|
{
|
||||||
|
ImGuiImplOpenVulkano ImGuiImplOpenVulkano::INSTANCE{};
|
||||||
|
|
||||||
|
void ImGuiImplOpenVulkano::Init(openVulkanoCpp::IWindow* window)
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
|
||||||
|
|
||||||
|
m_window = window;
|
||||||
|
|
||||||
|
io.BackendPlatformUserData = this;
|
||||||
|
io.BackendPlatformName = "imgui_impl_ios";
|
||||||
|
|
||||||
|
/*io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
|
||||||
|
io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
|
||||||
|
io.ClipboardUserData = bd->Window;*/
|
||||||
|
|
||||||
|
|
||||||
|
ImGuiViewport* mainViewport = ImGui::GetMainViewport();
|
||||||
|
mainViewport->PlatformHandle = m_window;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGuiImplOpenVulkano::NewFrame()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
IM_ASSERT(m_window != nullptr && "Did you call Init?");
|
||||||
|
|
||||||
|
// Setup display size (every frame to accommodate for window resizing)
|
||||||
|
/*int w, h;
|
||||||
|
int display_w, display_h;
|
||||||
|
glfwGetWindowSize(bd->Window, &w, &h);
|
||||||
|
glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
|
||||||
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
||||||
|
if (w > 0 && h > 0)
|
||||||
|
io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);*/
|
||||||
|
io.DisplaySize = { static_cast<float>(m_window->GetWidth()), static_cast<float>(m_window->GetHeight()) };
|
||||||
|
io.DisplayFramebufferScale = { 1, 1 };
|
||||||
|
|
||||||
|
//if (bd->WantUpdateMonitors)
|
||||||
|
//ImGui_ImplGlfw_UpdateMonitors();
|
||||||
|
|
||||||
|
// Setup time step
|
||||||
|
io.DeltaTime = CURRENT_FRAME.frameTime;
|
||||||
|
|
||||||
|
//TODO handle inputs
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGuiImplOpenVulkano::Close()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
ImGui::DestroyPlatformWindows();
|
||||||
|
|
||||||
|
io.BackendPlatformName = nullptr;
|
||||||
|
io.BackendPlatformUserData = nullptr;
|
||||||
|
io.BackendFlags = ImGuiBackendFlags_None;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
openVulkanoCpp/Host/ImGuiImplOpenVulkano.hpp
Normal file
26
openVulkanoCpp/Host/ImGuiImplOpenVulkano.hpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/UI/IWindow.hpp"
|
||||||
|
|
||||||
|
namespace openVulkanoCpp
|
||||||
|
{
|
||||||
|
class ImGuiImplOpenVulkano
|
||||||
|
{
|
||||||
|
IWindow* m_window;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static ImGuiImplOpenVulkano INSTANCE;
|
||||||
|
|
||||||
|
void Init(IWindow* window);
|
||||||
|
|
||||||
|
void NewFrame();
|
||||||
|
|
||||||
|
void Close();
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -12,6 +12,8 @@
|
|||||||
#if __has_include("GLFW/glfw3.h")
|
#if __has_include("GLFW/glfw3.h")
|
||||||
#include <imgui_impl_glfw.h>
|
#include <imgui_impl_glfw.h>
|
||||||
#define GLFW_AVAILABLE
|
#define GLFW_AVAILABLE
|
||||||
|
#else
|
||||||
|
#include "Host/ImGuiImplOpenVulkano.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace openVulkanoCpp::Vulkan
|
namespace openVulkanoCpp::Vulkan
|
||||||
@@ -61,6 +63,8 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
ImGui_ImplVulkan_Init(&vkInfo, uiRenderPass.renderPass);
|
ImGui_ImplVulkan_Init(&vkInfo, uiRenderPass.renderPass);
|
||||||
#ifdef GLFW_AVAILABLE
|
#ifdef GLFW_AVAILABLE
|
||||||
ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)context->window->GetNativeWindowHandle(), true);
|
ImGui_ImplGlfw_InitForVulkan((GLFWwindow*)context->window->GetNativeWindowHandle(), true);
|
||||||
|
#else
|
||||||
|
ImGuiImplOpenVulkano::INSTANCE.Init(context->window);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uiInitialized = true;
|
uiInitialized = true;
|
||||||
@@ -70,6 +74,11 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
void UiRenderer::Close()
|
void UiRenderer::Close()
|
||||||
{
|
{
|
||||||
uiInitialized = false;
|
uiInitialized = false;
|
||||||
|
#ifdef GLFW_AVAILABLE
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
#else
|
||||||
|
ImGuiImplOpenVulkano::INSTANCE.Close();
|
||||||
|
#endif
|
||||||
ImGui_ImplVulkan_Shutdown();
|
ImGui_ImplVulkan_Shutdown();
|
||||||
device.destroy(descriptorPool);
|
device.destroy(descriptorPool);
|
||||||
}
|
}
|
||||||
@@ -79,6 +88,8 @@ namespace openVulkanoCpp::Vulkan
|
|||||||
ImGui_ImplVulkan_NewFrame();
|
ImGui_ImplVulkan_NewFrame();
|
||||||
#ifdef GLFW_AVAILABLE
|
#ifdef GLFW_AVAILABLE
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
|
#else
|
||||||
|
ImGuiImplOpenVulkano::INSTANCE.NewFrame();
|
||||||
#endif
|
#endif
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user