Support for #define-ing GImGui and IMGUI_SET_CURRENT_CONTEXT_FUNC to enable custom thread-based hackery (#586)
This commit is contained in:
parent
e0aef0018f
commit
98e1d500d4
19
imgui.cpp
19
imgui.cpp
@ -720,14 +720,19 @@ static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
|
|||||||
// Context
|
// Context
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Default context, default font atlas.
|
// Default font atlas storage .
|
||||||
// New contexts always point by default to this font atlas. It can be changed by reassigning the GetIO().Fonts variable.
|
// New contexts always point by default to this font atlas. It can be changed by reassigning the GetIO().Fonts variable.
|
||||||
static ImGuiContext GImDefaultContext;
|
|
||||||
static ImFontAtlas GImDefaultFontAtlas;
|
static ImFontAtlas GImDefaultFontAtlas;
|
||||||
|
|
||||||
// Current context pointer. Implicitely used by all ImGui functions. Always assumed to be != NULL. Change to a different context by calling ImGui::SetCurrentContext()
|
// Default context storage + current context pointer.
|
||||||
// ImGui is currently not thread-safe because of this variable. If you want thread-safety to allow N threads to access N different contexts, you might work around it by (A) having two instances of the ImGui code under different namespaces or (B) change this variable to be TLS. Further development aim to make this context pointer explicit to all calls. Also read https://github.com/ocornut/imgui/issues/586
|
// Implicitely used by all ImGui functions. Always assumed to be != NULL. Change to a different context by calling ImGui::SetCurrentContext()
|
||||||
|
// ImGui is currently not thread-safe because of this variable. If you want thread-safety to allow N threads to access N different contexts, you might work around it by:
|
||||||
|
// - Having multiple instances of the ImGui code compiled inside different namespace (easiest/safest, if you have a finite number of contexts)
|
||||||
|
// - or: Changing this variable to be TLS. You may #define GImGui in imconfig.h for further custom hackery. Future development aim to make this context pointer explicit to all calls. Also read https://github.com/ocornut/imgui/issues/586
|
||||||
|
#ifndef GImGui
|
||||||
|
static ImGuiContext GImDefaultContext;
|
||||||
ImGuiContext* GImGui = &GImDefaultContext;
|
ImGuiContext* GImGui = &GImDefaultContext;
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// User facing structures
|
// User facing structures
|
||||||
@ -2044,7 +2049,11 @@ ImGuiContext* ImGui::GetCurrentContext()
|
|||||||
|
|
||||||
void ImGui::SetCurrentContext(ImGuiContext* ctx)
|
void ImGui::SetCurrentContext(ImGuiContext* ctx)
|
||||||
{
|
{
|
||||||
|
#ifdef IMGUI_SET_CURRENT_CONTEXT_FUNC
|
||||||
|
IMGUI_SET_CURRENT_CONTEXT_FUNC(ctx); // For custom thread-based hackery you may want to have control over this.
|
||||||
|
#else
|
||||||
GImGui = ctx;
|
GImGui = ctx;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiContext* ImGui::CreateContext(void* (*malloc_fn)(size_t), void (*free_fn)(void*))
|
ImGuiContext* ImGui::CreateContext(void* (*malloc_fn)(size_t), void (*free_fn)(void*))
|
||||||
@ -2063,7 +2072,7 @@ void ImGui::DestroyContext(ImGuiContext* ctx)
|
|||||||
ctx->~ImGuiContext();
|
ctx->~ImGuiContext();
|
||||||
free_fn(ctx);
|
free_fn(ctx);
|
||||||
if (GImGui == ctx)
|
if (GImGui == ctx)
|
||||||
GImGui = NULL;
|
SetCurrentContext(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiIO& ImGui::GetIO()
|
ImGuiIO& ImGui::GetIO()
|
||||||
|
@ -67,7 +67,9 @@ namespace ImGuiStb
|
|||||||
// Context
|
// Context
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern IMGUI_API ImGuiContext* GImGui; // current implicit ImGui context pointer
|
#ifndef GImGui
|
||||||
|
extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointer
|
||||||
|
#endif
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Helpers
|
// Helpers
|
||||||
|
Loading…
Reference in New Issue
Block a user