diff --git a/imgui.cpp b/imgui.cpp index d79690088..2a4001d65 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5231,6 +5231,8 @@ static void ImGui::UpdateTexturesEndFrame() tex->RefCount = (unsigned short)atlas->RefCount; g.PlatformIO.Textures.push_back(tex); } + for (ImTextureData* tex : g.UserTextures) + g.PlatformIO.Textures.push_back(tex); } // Called once a frame. Followed by SetCurrentFont() which sets up the remaining data. @@ -8613,6 +8615,19 @@ void ImGui::UpdateFontsEndFrame() PopFont(); } +void ImGui::RegisterUserTexture(ImTextureData* tex) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(tex->RefCount > 0); + g.UserTextures.push_back(tex); +} + +void ImGui::UnregisterUserTexture(ImTextureData* tex) +{ + ImGuiContext& g = *GImGui; + g.UserTextures.find_erase(tex); +} + void ImGui::RegisterFontAtlas(ImFontAtlas* atlas) { ImGuiContext& g = *GImGui; diff --git a/imgui.h b/imgui.h index 4ae0bd84b..3a8d05377 100644 --- a/imgui.h +++ b/imgui.h @@ -3905,7 +3905,7 @@ struct ImGuiPlatformIO // Textures list (the list is updated by calling ImGui::EndFrame or ImGui::Render) // The ImGui_ImplXXXX_RenderDrawData() function of each backend generally access this via ImDrawData::Textures which points to this. The array is available here mostly because backends will want to destroy textures on shutdown. - ImVector Textures; // List of textures used by Dear ImGui (most often 1). + ImVector Textures; // List of textures used by Dear ImGui (most often 1) + contents of external texture list is automatically appended into this. }; // (Optional) Support for IME (Input Method Editor) via the platform_io.Platform_SetImeDataFn() function. Handler is called during EndFrame(). diff --git a/imgui_internal.h b/imgui_internal.h index fc44490d4..a390add19 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2426,6 +2426,10 @@ struct ImGuiContext ImGuiPlatformImeData PlatformImeData; // Data updated by current frame. Will be applied at end of the frame. For some backends, this is required to have WantVisible=true in order to receive text message. ImGuiPlatformImeData PlatformImeDataPrev; // Previous frame data. When changed we call the platform_io.Platform_SetImeDataFn() handler. + // Extensions + // FIXME: We could provide an API to register one slot in an array held in ImGuiContext? + ImVector UserTextures; // List of textures created/managed by user or third-party extension. Automatically appended into platform_io.Textures[]. + // Settings bool SettingsLoaded; float SettingsDirtyTimer; // Save .ini Settings to memory when time reaches zero @@ -3108,6 +3112,8 @@ namespace ImGui IMGUI_API void SetNextWindowRefreshPolicy(ImGuiWindowRefreshFlags flags); // Fonts, drawing + IMGUI_API void RegisterUserTexture(ImTextureData* tex); // Register external texture + IMGUI_API void UnregisterUserTexture(ImTextureData* tex); IMGUI_API void RegisterFontAtlas(ImFontAtlas* atlas); IMGUI_API void UnregisterFontAtlas(ImFontAtlas* atlas); IMGUI_API void SetCurrentFont(ImFont* font, float font_size);