mirror of https://github.com/ocornut/imgui
Comments to clarify default shared ImFontAtlas and current context pointer thread-safety (#586, #591)
This commit is contained in:
parent
8a0d3b9628
commit
aa11934efa
12
imgui.cpp
12
imgui.cpp
|
@ -696,15 +696,15 @@ static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y);
|
|||
// Context
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// We access everything through this pointer (always assumed to be != NULL)
|
||||
// You can swap the pointer to a different context by calling ImGui::SetCurrentContext()
|
||||
// Default context, default font atlas.
|
||||
// New contexts always point by default to this font atlas. It can be changed by reassigning the GetIO().Fonts variable.
|
||||
static ImGuiContext GImDefaultContext;
|
||||
ImGuiContext* GImGui = &GImDefaultContext;
|
||||
|
||||
// Statically allocated default font atlas. This is merely a maneuver to keep ImFontAtlas definition at the bottom of the .h file (otherwise it'd be inside ImGuiIO)
|
||||
// Also we wouldn't be able to new() one at this point, before users have a chance to setup their allocator.
|
||||
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()
|
||||
// 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
|
||||
ImGuiContext* GImGui = &GImDefaultContext;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// User facing structures
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
1
imgui.h
1
imgui.h
|
@ -444,6 +444,7 @@ namespace ImGui
|
|||
IMGUI_API void SetClipboardText(const char* text);
|
||||
|
||||
// Internal context access - if you want to use multiple context, share context between modules (e.g. DLL). There is a default context created and active by default.
|
||||
// All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context.
|
||||
IMGUI_API const char* GetVersion();
|
||||
IMGUI_API ImGuiContext* CreateContext(void* (*malloc_fn)(size_t) = NULL, void (*free_fn)(void*) = NULL);
|
||||
IMGUI_API void DestroyContext(ImGuiContext* ctx);
|
||||
|
|
Loading…
Reference in New Issue