From 41f4acfb4ff259d97eecdf031b44c4853e54e8fc Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 12 Jun 2025 11:44:11 +0200 Subject: [PATCH] Fonts: add has_textures parameters to ImFontAtlasUpdateNewFrame(). --- docs/CHANGELOG.txt | 4 ++-- imgui.cpp | 7 +++---- imgui_draw.cpp | 11 ++++++----- imgui_internal.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7cda2db6c..20377e2aa 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -115,8 +115,8 @@ Breaking changes: to 4096 but that limit isn't necessary anymore, and Renderer_TextureMaxWidth covers this) However you may set TexMinWidth = TexMaxWidth for the same effect. - Fonts: if you create and manage ImFontAtlas instances yourself (instead of relying on - ImGuiContext to create one, you'll need to set the atlas->RendererHasTextures field - and call ImFontAtlasUpdateNewFrame() yourself. An assert will trigger if you don't. + ImGuiContext to create one, you'll need to call ImFontAtlasUpdateNewFrame() yourself. + An assert will trigger if you don't. - Fonts: obsolete ImGui::SetWindowFontScale() which is not useful anymore. Prefer using PushFontSize(style.FontSizeBase * factor) or to manipulate other scaling factors. - Fonts: obsoleted ImFont::Scale which is not useful anymore. diff --git a/imgui.cpp b/imgui.cpp index 90f9ecd2d..f57c305b4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -470,7 +470,7 @@ CODE - Fonts: ImFontConfig::OversampleH/OversampleV default to automatic (== 0) since v1.91.8. It is quite important you keep it automatic until we decide if we want to provide a way to express finer policy, otherwise you will likely waste texture space when using large glyphs. Note that the imgui_freetype backend doesn't use and does not need oversampling. - Fonts: specifying glyph ranges is now unnecessary. The value of ImFontConfig::GlyphRanges[] is only useful for legacy backends. All GetGlyphRangesXXXX() functions are now marked obsolete: GetGlyphRangesDefault(), GetGlyphRangesGreek(), GetGlyphRangesKorean(), GetGlyphRangesJapanese(), GetGlyphRangesChineseSimplifiedCommon(), GetGlyphRangesChineseFull(), GetGlyphRangesCyrillic(), GetGlyphRangesThai(), GetGlyphRangesVietnamese(). - Fonts: removed ImFontAtlas::TexDesiredWidth to enforce a texture width. (#327) - - Fonts: if you create and manage ImFontAtlas instances yourself (instead of relying on ImGuiContext to create one, you'll need to set the atlas->RendererHasTextures field and call ImFontAtlasUpdateNewFrame() yourself. An assert will trigger if you don't. + - Fonts: if you create and manage ImFontAtlas instances yourself (instead of relying on ImGuiContext to create one, you'll need to call ImFontAtlasUpdateNewFrame() yourself. An assert will trigger if you don't. - Fonts: obsolete ImGui::SetWindowFontScale() which is not useful anymore. Prefer using 'PushFontSize(style.FontSizeBase * factor)' or to manipulate other scaling factors. - Fonts: obsoleted ImFont::Scale which is not useful anymore. - Fonts: generally reworked Internals of ImFontAtlas and ImFont. While in theory a vast majority of users shouldn't be affected, some use cases or extensions might be. Among other things: @@ -5286,13 +5286,12 @@ static void ImGui::UpdateTexturesNewFrame() { if (atlas->OwnerContext == &g) { - atlas->RendererHasTextures = has_textures; - ImFontAtlasUpdateNewFrame(atlas, g.FrameCount); + ImFontAtlasUpdateNewFrame(atlas, g.FrameCount, has_textures); } else { IM_ASSERT(atlas->Builder != NULL && atlas->Builder->FrameCount != -1 && "If you manage font atlases yourself you need to call ImFontAtlasUpdateNewFrame() on it."); - IM_ASSERT(atlas->RendererHasTextures == has_textures && "If you manage font atlases yourself make sure atlas->RendererHasTextures is set consistently with all contexts using it."); + IM_ASSERT(atlas->RendererHasTextures == has_textures && "If you manage font atlases yourself make sure ImGuiBackendFlags_RendererHasTextures is set consistently with atlas->RendererHasTextures as specified in the ImFontAtlasUpdateNewFrame() call."); } } } diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 2e9a0b645..cd3d22ef9 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2716,12 +2716,13 @@ static void ImFontAtlasBuildUpdateRendererHasTexturesFromContext(ImFontAtlas* at } // Called by NewFrame() for atlases owned by a context. -// If you manually manage font atlases, you'll need to call this yourself + ensure atlas->RendererHasTextures is set. -// 'frame_count' needs to be provided because we can gc/prioritize baked fonts based on their age. -// 'frame_count' may not match those of imgui contexts using this atlas, as contexts may be updated as different frequencies. -void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count) +// If you manually manage font atlases, you'll need to call this yourself. +// - 'frame_count' needs to be provided because we can gc/prioritize baked fonts based on their age. +// - 'frame_count' may not match those of all imgui contexts using this atlas, as contexts may be updated as different frequencies. But generally you can use ImGui::GetFrameCount() on one of your context. +void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count, bool renderer_has_textures) { - IM_ASSERT(atlas->Builder == NULL || atlas->Builder->FrameCount < frame_count); // Protection against being called twice? + IM_ASSERT(atlas->Builder == NULL || atlas->Builder->FrameCount < frame_count); // Protection against being called twice. + atlas->RendererHasTextures = renderer_has_textures; // Check that font atlas was built or backend support texture reload in which case we can build now if (atlas->RendererHasTextures) diff --git a/imgui_internal.h b/imgui_internal.h index b80bf50b6..1d572d5a6 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3833,7 +3833,7 @@ IMGUI_API ImTextureRect* ImFontAtlasPackGetRect(ImFontAtlas* atlas, ImFontAtl IMGUI_API ImTextureRect* ImFontAtlasPackGetRectSafe(ImFontAtlas* atlas, ImFontAtlasRectId id); IMGUI_API void ImFontAtlasPackDiscardRect(ImFontAtlas* atlas, ImFontAtlasRectId id); -IMGUI_API void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count); +IMGUI_API void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count, bool renderer_has_textures); IMGUI_API void ImFontAtlasAddDrawListSharedData(ImFontAtlas* atlas, ImDrawListSharedData* data); IMGUI_API void ImFontAtlasRemoveDrawListSharedData(ImFontAtlas* atlas, ImDrawListSharedData* data); IMGUI_API void ImFontAtlasUpdateDrawListsTextures(ImFontAtlas* atlas, ImTextureRef old_tex, ImTextureRef new_tex);