@ -1287,20 +1287,20 @@ bool ImFontAtlas::Build()
ClearTexData ( ) ;
// Count glyphs/ranges
int total_glyph _count = 0 ;
int total_ glyph_ range_count = 0 ;
int total_glyph s _count = 0 ;
int total_ ranges _count = 0 ;
for ( int input_i = 0 ; input_i < ConfigData . Size ; input_i + + )
{
ImFontConfig & cfg = ConfigData [ input_i ] ;
if ( ! cfg . GlyphRanges )
cfg . GlyphRanges = GetGlyphRangesDefault ( ) ;
for ( const ImWchar * in_range = cfg . GlyphRanges ; in_range [ 0 ] & & in_range [ 1 ] ; in_range + = 2 , total_ glyph_ range_count+ + )
total_glyph _count + = ( in_range [ 1 ] - in_range [ 0 ] ) + 1 ;
for ( const ImWchar * in_range = cfg . GlyphRanges ; in_range [ 0 ] & & in_range [ 1 ] ; in_range + = 2 , total_ ranges _count+ + )
total_glyph s _count + = ( in_range [ 1 ] - in_range [ 0 ] ) + 1 ;
}
// Start packing. We need a known width for the skyline algorithm. Using a dumb heuristic here to decide of width. User can override TexDesiredWidth and TexGlyphPadding if they wish.
// After packing is done, width shouldn't matter much, but some API/GPU have texture size limitations and increasing width can decrease height.
TexWidth = ( TexDesiredWidth > 0 ) ? TexDesiredWidth : ( total_glyph _count > 4000 ) ? 4096 : ( total_glyph _count > 2000 ) ? 2048 : ( total_glyph _count > 1000 ) ? 1024 : 512 ;
TexWidth = ( TexDesiredWidth > 0 ) ? TexDesiredWidth : ( total_glyph s _count > 4000 ) ? 4096 : ( total_glyph s _count > 2000 ) ? 2048 : ( total_glyph s _count > 1000 ) ? 1024 : 512 ;
TexHeight = 0 ;
const int max_tex_height = 1024 * 32 ;
stbtt_pack_context spc ;
@ -1337,12 +1337,12 @@ bool ImFontAtlas::Build()
// Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
int buf_packedchars_n = 0 , buf_rects_n = 0 , buf_ranges_n = 0 ;
stbtt_packedchar * buf_packedchars = ( stbtt_packedchar * ) ImGui : : MemAlloc ( total_glyph _count * sizeof ( stbtt_packedchar ) ) ;
stbrp_rect * buf_rects = ( stbrp_rect * ) ImGui : : MemAlloc ( total_glyph _count * sizeof ( stbrp_rect ) ) ;
stbtt_pack_range * buf_ranges = ( stbtt_pack_range * ) ImGui : : MemAlloc ( total_ glyph_ range_count * sizeof ( stbtt_pack_range ) ) ;
memset ( buf_packedchars , 0 , total_glyph _count * sizeof ( stbtt_packedchar ) ) ;
memset ( buf_rects , 0 , total_glyph _count * sizeof ( stbrp_rect ) ) ; // Unnecessary but let's clear this for the sake of sanity.
memset ( buf_ranges , 0 , total_ glyph_ range_count * sizeof ( stbtt_pack_range ) ) ;
stbtt_packedchar * buf_packedchars = ( stbtt_packedchar * ) ImGui : : MemAlloc ( total_glyph s _count * sizeof ( stbtt_packedchar ) ) ;
stbrp_rect * buf_rects = ( stbrp_rect * ) ImGui : : MemAlloc ( total_glyph s _count * sizeof ( stbrp_rect ) ) ;
stbtt_pack_range * buf_ranges = ( stbtt_pack_range * ) ImGui : : MemAlloc ( total_ ranges _count * sizeof ( stbtt_pack_range ) ) ;
memset ( buf_packedchars , 0 , total_glyph s _count * sizeof ( stbtt_packedchar ) ) ;
memset ( buf_rects , 0 , total_glyph s _count * sizeof ( stbrp_rect ) ) ; // Unnecessary but let's clear this for the sake of sanity.
memset ( buf_ranges , 0 , total_ ranges _count * sizeof ( stbtt_pack_range ) ) ;
// First font pass: pack all glyphs (no rendering at this point, we are working with rectangles in an infinitely tall texture at this point)
for ( int input_i = 0 ; input_i < ConfigData . Size ; input_i + + )
@ -1351,14 +1351,14 @@ bool ImFontAtlas::Build()
ImFontTempBuildData & tmp = tmp_array [ input_i ] ;
// Setup ranges
int glyph_count = 0 ;
int glyph _ranges_count = 0 ;
for ( const ImWchar * in_range = cfg . GlyphRanges ; in_range [ 0 ] & & in_range [ 1 ] ; in_range + = 2 , glyph _ranges_count+ + )
glyph_count + = ( in_range [ 1 ] - in_range [ 0 ] ) + 1 ;
int font_ glyphs _count = 0 ;
int font _ranges_count = 0 ;
for ( const ImWchar * in_range = cfg . GlyphRanges ; in_range [ 0 ] & & in_range [ 1 ] ; in_range + = 2 , font _ranges_count+ + )
font_ glyphs _count + = ( in_range [ 1 ] - in_range [ 0 ] ) + 1 ;
tmp . Ranges = buf_ranges + buf_ranges_n ;
tmp . RangesCount = glyph _ranges_count;
buf_ranges_n + = glyph _ranges_count;
for ( int i = 0 ; i < glyph _ranges_count; i + + )
tmp . RangesCount = font _ranges_count;
buf_ranges_n + = font _ranges_count;
for ( int i = 0 ; i < font _ranges_count; i + + )
{
const ImWchar * in_range = & cfg . GlyphRanges [ i * 2 ] ;
stbtt_pack_range & range = tmp . Ranges [ i ] ;
@ -1371,9 +1371,10 @@ bool ImFontAtlas::Build()
// Pack
tmp . Rects = buf_rects + buf_rects_n ;
buf_rects_n + = glyph_count;
buf_rects_n + = font_ glyphs _count;
stbtt_PackSetOversampling ( & spc , cfg . OversampleH , cfg . OversampleV ) ;
int n = stbtt_PackFontRangesGatherRects ( & spc , & tmp . FontInfo , tmp . Ranges , tmp . RangesCount , tmp . Rects ) ;
IM_ASSERT ( n = = font_glyphs_count ) ;
stbrp_pack_rects ( ( stbrp_context * ) spc . pack_info , tmp . Rects , n ) ;
// Extend texture height
@ -1381,9 +1382,9 @@ bool ImFontAtlas::Build()
if ( tmp . Rects [ i ] . was_packed )
TexHeight = ImMax ( TexHeight , tmp . Rects [ i ] . y + tmp . Rects [ i ] . h ) ;
}
IM_ASSERT ( buf_rects_n = = total_glyph _count) ;
IM_ASSERT ( buf_packedchars_n = = total_glyph _count) ;
IM_ASSERT ( buf_ranges_n = = total_ glyph_ range_count) ;
IM_ASSERT ( buf_rects_n = = total_glyph s _count) ;
IM_ASSERT ( buf_packedchars_n = = total_glyph s _count) ;
IM_ASSERT ( buf_ranges_n = = total_ ranges _count) ;
// Create texture
TexHeight = ImUpperPowerOfTwo ( TexHeight ) ;