add imgui function to ensure crossdll context is valid
This commit is contained in:
parent
eddcd4b906
commit
a08a9b377c
|
|
@ -84,6 +84,7 @@ int WinMain(int argc, char* argv[])
|
||||||
|
|
||||||
float deltaTime = updateClock.GetElapsedTime().AsSeconds();
|
float deltaTime = updateClock.GetElapsedTime().AsSeconds();
|
||||||
Nz::Imgui::Instance()->Update(window, deltaTime);
|
Nz::Imgui::Instance()->Update(window, deltaTime);
|
||||||
|
ImGui::EnsureContextOnThisThread();
|
||||||
|
|
||||||
ImGui::Begin("Loop Window");
|
ImGui::Begin("Loop Window");
|
||||||
ImGui::Image(logo.get());
|
ImGui::Image(logo.get());
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,9 @@ namespace Nz
|
||||||
Nz::Vector2f framebufferSize;
|
Nz::Vector2f framebufferSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static ImGuiContext* GetCurrentContext();
|
||||||
|
static void GetAllocatorFunctions(ImGuiMemAllocFunc* allocFunc, ImGuiMemFreeFunc* freeFunc, void** userData);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetupInputs(Nz::WindowEventHandler& handler);
|
void SetupInputs(Nz::WindowEventHandler& handler);
|
||||||
void Update(const Nz::Vector2i& mousePosition, const Nz::Vector2ui& displaySize, float dt);
|
void Update(const Nz::Vector2i& mousePosition, const Nz::Vector2ui& displaySize, float dt);
|
||||||
|
|
@ -66,6 +69,7 @@ namespace Nz
|
||||||
|
|
||||||
void RenderDrawLists(Nz::RenderTarget* renderTarget, Nz::RenderFrame& frame, ImDrawData* drawData);
|
void RenderDrawLists(Nz::RenderTarget* renderTarget, Nz::RenderFrame& frame, ImDrawData* drawData);
|
||||||
|
|
||||||
|
ImGuiContext* m_currentContext;
|
||||||
std::string m_clipboardText;
|
std::string m_clipboardText;
|
||||||
|
|
||||||
bool m_bWindowHasFocus;
|
bool m_bWindowHasFocus;
|
||||||
|
|
@ -112,4 +116,16 @@ namespace ImGui
|
||||||
NAZARA_IMGUI_API void DrawLine(const Nz::Vector2f& a, const Nz::Vector2f& b, const Nz::Color& col, float thickness = 1.0f);
|
NAZARA_IMGUI_API void DrawLine(const Nz::Vector2f& a, const Nz::Vector2f& b, const Nz::Color& col, float thickness = 1.0f);
|
||||||
NAZARA_IMGUI_API void DrawRect(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F, float thickness = 1.0f);
|
NAZARA_IMGUI_API void DrawRect(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F, float thickness = 1.0f);
|
||||||
NAZARA_IMGUI_API void DrawRectFilled(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F);
|
NAZARA_IMGUI_API void DrawRectFilled(const Nz::Rectf& rect, const Nz::Color& color, float rounding = 0.0f, int rounding_corners = 0x0F);
|
||||||
|
|
||||||
|
void EnsureContextOnThisThread()
|
||||||
|
{
|
||||||
|
auto* context = Nz::Imgui::GetCurrentContext();
|
||||||
|
SetCurrentContext(context);
|
||||||
|
|
||||||
|
ImGuiMemAllocFunc allocFunc = nullptr;
|
||||||
|
ImGuiMemFreeFunc freeFunc = nullptr;
|
||||||
|
void* userData = nullptr;
|
||||||
|
Nz::Imgui::GetAllocatorFunctions(&allocFunc, &freeFunc, &userData);
|
||||||
|
SetAllocatorFunctions(allocFunc, freeFunc, userData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ namespace Nz
|
||||||
: ModuleBase("Imgui", this)
|
: ModuleBase("Imgui", this)
|
||||||
, m_bMouseMoved(false)
|
, m_bMouseMoved(false)
|
||||||
, m_bWindowHasFocus(false)
|
, m_bWindowHasFocus(false)
|
||||||
|
, m_currentContext(nullptr)
|
||||||
{
|
{
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
@ -123,7 +124,7 @@ namespace Nz
|
||||||
|
|
||||||
bool Imgui::Init(Nz::Window& window, bool bLoadDefaultFont)
|
bool Imgui::Init(Nz::Window& window, bool bLoadDefaultFont)
|
||||||
{
|
{
|
||||||
ImGui::CreateContext();
|
m_currentContext = ImGui::CreateContext();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
// tell ImGui which features we support
|
// tell ImGui which features we support
|
||||||
|
|
@ -343,6 +344,16 @@ namespace Nz
|
||||||
return backend->m_clipboardText.c_str();
|
return backend->m_clipboardText.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGuiContext* Imgui::GetCurrentContext()
|
||||||
|
{
|
||||||
|
return ImGui::GetCurrentContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Imgui::GetAllocatorFunctions(ImGuiMemAllocFunc* allocFunc, ImGuiMemFreeFunc* freeFunc, void** userData)
|
||||||
|
{
|
||||||
|
ImGui::GetAllocatorFunctions(allocFunc, freeFunc, userData);
|
||||||
|
}
|
||||||
|
|
||||||
void Imgui::UpdateFontTexture()
|
void Imgui::UpdateFontTexture()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue