light/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2022-03-08 21:19:19 +03:30
#include "dxUserInterface.hpp"
2021-06-02 17:20:15 +04:30
2022-03-08 21:19:19 +03:30
#include "Input/KeyCodes.hpp"
#include "dxSharedContext.hpp"
2021-06-02 17:20:15 +04:30
#define GLFW_EXPOSE_NATIVE_WIN32
2022-03-07 21:57:00 +03:30
#include <backends/imgui_impl_dx11.h>
#include <backends/imgui_impl_win32.h>
2021-06-02 17:20:15 +04:30
#include <glfw/glfw3.h>
#include <glfw/glfw3native.h>
2021-07-29 17:12:13 +04:30
#include <imgui.h>
2021-06-02 17:20:15 +04:30
namespace Light {
2022-03-07 21:57:00 +03:30
void dxUserInterface::PlatformImplementation(GLFWwindow* windowHandle, Ref<SharedContext> sharedContext)
{
ImGuiIO& io = ImGui::GetIO();
Ref<dxSharedContext> context = std::dynamic_pointer_cast<dxSharedContext>(sharedContext);
2022-03-07 21:57:00 +03:30
ImGui_ImplWin32_Init(glfwGetWin32Window(windowHandle));
ImGui_ImplDX11_Init(context->GetDevice().Get(), context->GetDeviceContext().Get());
}
2021-06-02 17:20:15 +04:30
2022-03-07 21:57:00 +03:30
dxUserInterface::~dxUserInterface()
{
// #todo: handle this in a better way
ImGuiIO& io = ImGui::GetIO();
2022-03-07 21:57:00 +03:30
if (io.IniFilename == "default_gui_layout.ini")
io.IniFilename = "user_gui_layout.ini";
2022-03-07 21:57:00 +03:30
ImGui_ImplDX11_Shutdown();
ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext();
}
2021-06-02 17:20:15 +04:30
2022-03-07 21:57:00 +03:30
void dxUserInterface::Begin()
{
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
}
2021-06-02 17:20:15 +04:30
2022-03-07 21:57:00 +03:30
void dxUserInterface::End()
{
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
2022-03-07 21:57:00 +03:30
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
2021-06-02 17:20:15 +04:30
2022-03-07 21:57:00 +03:30
void dxUserInterface::LogDebugData()
{
// #todo: improve
LOG(info, "________________________________________");
LOG(info, "UserInterface::");
LOG(info, " API : ImGui");
LOG(info, " Version: {}", ImGui::GetVersion());
LOG(info, " GraphicsAPI : DirectX");
LOG(info, "________________________________________");
}
2021-06-02 17:20:15 +04:30
2022-03-07 21:57:00 +03:30
} // namespace Light