From 8fab706f31a208bbd429ab50b2c5faa06c516944 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 28 Jan 2025 14:31:13 +0100 Subject: [PATCH] WIP - Texture resizing favor growing height, halve pack nodes. --- imgui_draw.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index d57303c03..aa6f3e90b 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3841,9 +3841,10 @@ void ImFontAtlasBuildGrowTexture(ImFontAtlas* atlas, int old_tex_w, int old_tex_ IM_ASSERT(ImIsPowerOfTwo(atlas->TexMinWidth) && ImIsPowerOfTwo(atlas->TexMaxWidth) && ImIsPowerOfTwo(atlas->TexMinHeight) && ImIsPowerOfTwo(atlas->TexMaxHeight)); // Grow texture so it follows roughly a square. - // Caller should be taking account of RectsDiscardedSurface and may not need to grow. - int new_tex_w = (old_tex_h < old_tex_w) ? old_tex_w : old_tex_w * 2; - int new_tex_h = (old_tex_h < old_tex_w) ? old_tex_h * 2 : old_tex_h; + // - Grow height before width, as width imply more packing nodes. + // - Caller should be taking account of RectsDiscardedSurface and may not need to grow. + int new_tex_w = (old_tex_h <= old_tex_w) ? old_tex_w : old_tex_w * 2; + int new_tex_h = (old_tex_h <= old_tex_w) ? old_tex_h * 2 : old_tex_h; // Handle minimum size first (for pathologically large packed rects) const int pack_padding = atlas->TexGlyphPadding; @@ -3993,7 +3994,7 @@ void ImFontAtlasPackInit(ImFontAtlas * atlas) ImFontAtlasBuilder* builder = atlas->Builder; // In theory we could decide to reduce the number of nodes, e.g. halve them, and waste a little texture space, but it doesn't seem worth it. - const int pack_node_count = tex->Width; + const int pack_node_count = tex->Width / 2; builder->PackNodes.resize(pack_node_count); IM_STATIC_ASSERT(sizeof(stbrp_context) <= sizeof(stbrp_context_opaque)); stbrp_init_target((stbrp_context*)(void*)&builder->PackContext, tex->Width, tex->Height, builder->PackNodes.Data, builder->PackNodes.Size);