Backends: support for multiple imgui context (586, 1851, 2004, 3012, 3934, 4141) (barely tested)
diff --git a/backends/imgui_impl_dx10.cpp b/backends/imgui_impl_dx10.cpp
index 760f36f..41ffd51 100644
--- a/backends/imgui_impl_dx10.cpp
+++ b/backends/imgui_impl_dx10.cpp
@@ -62,11 +62,10 @@
ImGui_ImplDX10_Data() { memset(this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
};
-// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplDX10_Data* g_Data;
-static ImGui_ImplDX10_Data* ImGui_ImplDX10_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplDX10_Data); return g_Data; }
-static ImGui_ImplDX10_Data* ImGui_ImplDX10_GetBackendData() { return ImGui::GetCurrentContext() != NULL ? g_Data : NULL; }
-static void ImGui_ImplDX10_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendRendererUserData)
+static ImGui_ImplDX10_Data* ImGui_ImplDX10_CreateBackendData() { return IM_NEW(ImGui_ImplDX10_Data)(); }
+static ImGui_ImplDX10_Data* ImGui_ImplDX10_GetBackendData() { return (ImGui_ImplDX10_Data*)ImGui::GetIO().BackendRendererUserData; }
+static void ImGui_ImplDX10_DestroyBackendData() { IM_DELETE(ImGui_ImplDX10_GetBackendData()); }
struct VERTEX_CONSTANT_BUFFER
{
diff --git a/backends/imgui_impl_dx11.cpp b/backends/imgui_impl_dx11.cpp
index 867fb7a..26f824e 100644
--- a/backends/imgui_impl_dx11.cpp
+++ b/backends/imgui_impl_dx11.cpp
@@ -63,11 +63,10 @@
ImGui_ImplDX11_Data() { memset(this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
};
-// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplDX11_Data* g_Data;
-static ImGui_ImplDX11_Data* ImGui_ImplDX11_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplDX11_Data); return g_Data; }
-static ImGui_ImplDX11_Data* ImGui_ImplDX11_GetBackendData() { return ImGui::GetCurrentContext() != NULL ? g_Data : NULL; }
-static void ImGui_ImplDX11_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendRendererUserData)
+static ImGui_ImplDX11_Data* ImGui_ImplDX11_CreateBackendData() { return IM_NEW(ImGui_ImplDX11_Data)(); }
+static ImGui_ImplDX11_Data* ImGui_ImplDX11_GetBackendData() { return (ImGui_ImplDX11_Data*)ImGui::GetIO().BackendRendererUserData; }
+static void ImGui_ImplDX11_DestroyBackendData() { IM_DELETE(ImGui_ImplDX11_GetBackendData()); }
struct VERTEX_CONSTANT_BUFFER
{
diff --git a/backends/imgui_impl_dx12.cpp b/backends/imgui_impl_dx12.cpp
index c7dcca1..922a63b 100644
--- a/backends/imgui_impl_dx12.cpp
+++ b/backends/imgui_impl_dx12.cpp
@@ -74,11 +74,10 @@
ImGui_ImplDX12_Data() { memset(this, 0, sizeof(*this)); frameIndex = UINT_MAX; }
};
-// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplDX12_Data* g_Data;
-static ImGui_ImplDX12_Data* ImGui_ImplDX12_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplDX12_Data); return g_Data; }
-static ImGui_ImplDX12_Data* ImGui_ImplDX12_GetBackendData() { return ImGui::GetCurrentContext() != NULL ? g_Data : NULL; }
-static void ImGui_ImplDX12_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendRendererUserData)
+static ImGui_ImplDX12_Data* ImGui_ImplDX12_CreateBackendData() { return IM_NEW(ImGui_ImplDX12_Data)(); }
+static ImGui_ImplDX12_Data* ImGui_ImplDX12_GetBackendData() { return (ImGui_ImplDX12_Data*)ImGui::GetIO().BackendRendererUserData; }
+static void ImGui_ImplDX12_DestroyBackendData() { IM_DELETE(ImGui_ImplDX12_GetBackendData()); }
template<typename T>
static void SafeRelease(T*& res)
diff --git a/backends/imgui_impl_dx9.cpp b/backends/imgui_impl_dx9.cpp
index a2d426d..067b25e 100644
--- a/backends/imgui_impl_dx9.cpp
+++ b/backends/imgui_impl_dx9.cpp
@@ -49,11 +49,10 @@
ImGui_ImplDX9_Data() { memset(this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
};
-// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplDX9_Data* g_Data;
-static ImGui_ImplDX9_Data* ImGui_ImplDX9_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplDX9_Data); return g_Data; }
-static ImGui_ImplDX9_Data* ImGui_ImplDX9_GetBackendData() { return ImGui::GetCurrentContext() != NULL ? g_Data : NULL; }
-static void ImGui_ImplDX9_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendRendererUserData)
+static ImGui_ImplDX9_Data* ImGui_ImplDX9_CreateBackendData() { return IM_NEW(ImGui_ImplDX9_Data)(); }
+static ImGui_ImplDX9_Data* ImGui_ImplDX9_GetBackendData() { return (ImGui_ImplDX9_Data*)ImGui::GetIO().BackendRendererUserData; }
+static void ImGui_ImplDX9_DestroyBackendData() { IM_DELETE(ImGui_ImplDX9_GetBackendData()); }
struct CUSTOMVERTEX
{
diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp
index 07b61df..cbf2a31 100644
--- a/backends/imgui_impl_glfw.cpp
+++ b/backends/imgui_impl_glfw.cpp
@@ -87,10 +87,9 @@
};
// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplGlfw_Data* g_Data;
-static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplGlfw_Data); return g_Data; }
-static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData() { return ImGui::GetCurrentContext() != NULL ? g_Data : NULL; }
-static void ImGui_ImplGlfw_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_CreateBackendData() { return IM_NEW(ImGui_ImplGlfw_Data)(); }
+static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData() { return (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData; }
+static void ImGui_ImplGlfw_DestroyBackendData() { IM_DELETE(ImGui_ImplGlfw_GetBackendData()); }
// Functions
static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data)
diff --git a/backends/imgui_impl_opengl2.cpp b/backends/imgui_impl_opengl2.cpp
index e45c042..d0be3f3 100644
--- a/backends/imgui_impl_opengl2.cpp
+++ b/backends/imgui_impl_opengl2.cpp
@@ -63,11 +63,10 @@
ImGui_ImplOpenGL2_Data() { memset(this, 0, sizeof(*this)); }
};
-// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplOpenGL2_Data* g_Data;
-static ImGui_ImplOpenGL2_Data* ImGui_ImplOpenGL2_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplOpenGL2_Data); return g_Data; }
-static ImGui_ImplOpenGL2_Data* ImGui_ImplOpenGL2_GetBackendData() { return ImGui::GetCurrentContext() != NULL ? g_Data : NULL; }
-static void ImGui_ImplOpenGL2_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendRendererUserData)
+static ImGui_ImplOpenGL2_Data* ImGui_ImplOpenGL2_CreateBackendData() { return IM_NEW(ImGui_ImplOpenGL2_Data)(); }
+static ImGui_ImplOpenGL2_Data* ImGui_ImplOpenGL2_GetBackendData() { return (ImGui_ImplOpenGL2_Data*)ImGui::GetIO().BackendRendererUserData; }
+static void ImGui_ImplOpenGL2_DestroyBackendData() { IM_DELETE(ImGui_ImplOpenGL2_GetBackendData()); }
// Functions
bool ImGui_ImplOpenGL2_Init()
diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp
index ee0fd6f..7b69579 100644
--- a/backends/imgui_impl_opengl3.cpp
+++ b/backends/imgui_impl_opengl3.cpp
@@ -189,11 +189,10 @@
ImGui_ImplOpenGL3_Data() { memset(this, 0, sizeof(*this)); }
};
-// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplOpenGL3_Data* g_Data;
-static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplOpenGL3_Data); return g_Data; }
-static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData() { IM_ASSERT(ImGui::GetCurrentContext() != NULL); return g_Data; }
-static void ImGui_ImplOpenGL3_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendRendererUserData)
+static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_CreateBackendData() { return IM_NEW(ImGui_ImplOpenGL3_Data)(); }
+static ImGui_ImplOpenGL3_Data* ImGui_ImplOpenGL3_GetBackendData() { return (ImGui_ImplOpenGL3_Data*)ImGui::GetIO().BackendRendererUserData; }
+static void ImGui_ImplOpenGL3_DestroyBackendData() { IM_DELETE(ImGui_ImplOpenGL3_GetBackendData()); }
// Functions
bool ImGui_ImplOpenGL3_Init(const char* glsl_version)
diff --git a/backends/imgui_impl_sdl.cpp b/backends/imgui_impl_sdl.cpp
index 9392216..b58e49f 100644
--- a/backends/imgui_impl_sdl.cpp
+++ b/backends/imgui_impl_sdl.cpp
@@ -73,10 +73,9 @@
};
// Wrapping access to backend data data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplSDL2_Data* g_Data;
-static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplSDL2_Data); return g_Data; }
-static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData() { return ImGui::GetCurrentContext() != NULL ? g_Data : NULL; }
-static void ImGui_ImplSDL2_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_CreateBackendData() { return IM_NEW(ImGui_ImplSDL2_Data)(); }
+static ImGui_ImplSDL2_Data* ImGui_ImplSDL2_GetBackendData() { return (ImGui_ImplSDL2_Data*)ImGui::GetIO().BackendPlatformUserData; }
+static void ImGui_ImplSDL2_DestroyBackendData() { IM_DELETE(ImGui_ImplSDL2_GetBackendData()); }
// Functions
static const char* ImGui_ImplSDL2_GetClipboardText(void*)
diff --git a/backends/imgui_impl_vulkan.cpp b/backends/imgui_impl_vulkan.cpp
index f5d63b2..5f2886e 100644
--- a/backends/imgui_impl_vulkan.cpp
+++ b/backends/imgui_impl_vulkan.cpp
@@ -110,11 +110,10 @@
}
};
-// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplVulkan_Data* g_Data;
-static ImGui_ImplVulkan_Data* ImGui_ImplVulkan_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplVulkan_Data); return g_Data; }
-static ImGui_ImplVulkan_Data* ImGui_ImplVulkan_GetBackendData() { return ImGui::GetCurrentContext() ? g_Data : NULL; }
-static void ImGui_ImplVulkan_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendRendererUserData)
+static ImGui_ImplVulkan_Data* ImGui_ImplVulkan_CreateBackendData() { return IM_NEW(ImGui_ImplVulkan_Data)(); }
+static ImGui_ImplVulkan_Data* ImGui_ImplVulkan_GetBackendData() { return (ImGui_ImplVulkan_Data*)ImGui::GetIO().BackendPlatformUserData; }
+static void ImGui_ImplVulkan_DestroyBackendData() { IM_DELETE(ImGui_ImplVulkan_GetBackendData()); }
// Forward Declarations
bool ImGui_ImplVulkan_CreateDeviceObjects();
diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp
index edd6635..a284b60 100644
--- a/backends/imgui_impl_win32.cpp
+++ b/backends/imgui_impl_win32.cpp
@@ -83,10 +83,11 @@
};
// Wrapping access to backend data (to facilitate multiple-contexts stored in io.BackendPlatformUserData)
-static ImGui_ImplWin32_Data* g_Data;
-static ImGui_ImplWin32_Data* ImGui_ImplWin32_CreateBackendData() { IM_ASSERT(g_Data == NULL); g_Data = IM_NEW(ImGui_ImplWin32_Data); return g_Data; }
-static ImGui_ImplWin32_Data* ImGui_ImplWin32_GetBackendData() { return ImGui::GetCurrentContext() ? g_Data : NULL; }
-static void ImGui_ImplWin32_DestroyBackendData() { IM_DELETE(g_Data); g_Data = NULL; }
+// FIXME: mouse cursor is a shared resource.
+// FIXME: facilitate calling ImGui_ImplWin32_WndProcHandler() handler and letting us do the right dispatch
+static ImGui_ImplWin32_Data* ImGui_ImplWin32_CreateBackendData() { return IM_NEW(ImGui_ImplWin32_Data)(); }
+static ImGui_ImplWin32_Data* ImGui_ImplWin32_GetBackendData() { return (ImGui_ImplWin32_Data*)ImGui::GetIO().BackendPlatformUserData; }
+static void ImGui_ImplWin32_DestroyBackendData() { IM_DELETE(ImGui_ImplWin32_GetBackendData()); }
// Functions
bool ImGui_ImplWin32_Init(void* hwnd)