mirror of
https://github.com/ocornut/imgui.git
synced 2025-02-08 23:19:40 +01:00
Font: Internals: make used page maps smaller. Since it's extremely rarely used and for iterations only. ~34->16 bytes with ImWchar32.
This commit is contained in:
parent
f2262eb81a
commit
487d7f9a29
@ -16177,9 +16177,9 @@ void ImGui::DebugNodeFont(ImFont* font)
|
|||||||
// Skip ahead if a large bunch of glyphs are not present in the font (test in chunks of 4k)
|
// Skip ahead if a large bunch of glyphs are not present in the font (test in chunks of 4k)
|
||||||
// This is only a small optimization to reduce the number of iterations when IM_UNICODE_MAX_CODEPOINT
|
// This is only a small optimization to reduce the number of iterations when IM_UNICODE_MAX_CODEPOINT
|
||||||
// is large // (if ImWchar==ImWchar32 we will do at least about 272 queries here)
|
// is large // (if ImWchar==ImWchar32 we will do at least about 272 queries here)
|
||||||
if (!(base & 4095) && font->IsGlyphRangeUnused(base, base + 4095))
|
if (!(base & 8191) && font->IsGlyphRangeUnused(base, base + 8191))
|
||||||
{
|
{
|
||||||
base += 4096 - 256;
|
base += 8192 - 256;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
imgui.h
2
imgui.h
@ -3461,7 +3461,7 @@ struct ImFont
|
|||||||
float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
|
float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
|
||||||
float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] (unscaled)
|
float Ascent, Descent; // 4+4 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize] (unscaled)
|
||||||
int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
|
int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
|
||||||
ImU8 Used4kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/4096/8]; // 2 bytes if ImWchar=ImWchar16, 34 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations across all used codepoints.
|
ImU8 Used8kPagesMap[(IM_UNICODE_CODEPOINT_MAX+1)/8192/8]; // 1 bytes if ImWchar=ImWchar16, 16 bytes if ImWchar==ImWchar32. Store 1-bit for each block of 4K codepoints that has one active glyph. This is mainly used to facilitate iterations across all used codepoints.
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
IMGUI_API ImFont();
|
IMGUI_API ImFont();
|
||||||
|
@ -3689,7 +3689,7 @@ ImFont::ImFont()
|
|||||||
Scale = 1.0f;
|
Scale = 1.0f;
|
||||||
Ascent = Descent = 0.0f;
|
Ascent = Descent = 0.0f;
|
||||||
MetricsTotalSurface = 0;
|
MetricsTotalSurface = 0;
|
||||||
memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap));
|
memset(Used8kPagesMap, 0, sizeof(Used8kPagesMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
ImFont::~ImFont()
|
ImFont::~ImFont()
|
||||||
@ -3709,7 +3709,7 @@ void ImFont::ClearOutputData()
|
|||||||
DirtyLookupTables = true;
|
DirtyLookupTables = true;
|
||||||
Ascent = Descent = 0.0f;
|
Ascent = Descent = 0.0f;
|
||||||
MetricsTotalSurface = 0;
|
MetricsTotalSurface = 0;
|
||||||
memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap));
|
memset(Used8kPagesMap, 0, sizeof(Used8kPagesMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ImWchar FindFirstExistingGlyph(ImFont* font, const ImWchar* candidate_chars, int candidate_chars_count)
|
static ImWchar FindFirstExistingGlyph(ImFont* font, const ImWchar* candidate_chars, int candidate_chars_count)
|
||||||
@ -3732,7 +3732,7 @@ void ImFont::BuildLookupTable()
|
|||||||
IndexAdvanceX.clear();
|
IndexAdvanceX.clear();
|
||||||
IndexLookup.clear();
|
IndexLookup.clear();
|
||||||
DirtyLookupTables = false;
|
DirtyLookupTables = false;
|
||||||
memset(Used4kPagesMap, 0, sizeof(Used4kPagesMap));
|
memset(Used8kPagesMap, 0, sizeof(Used8kPagesMap));
|
||||||
GrowIndex(max_codepoint + 1);
|
GrowIndex(max_codepoint + 1);
|
||||||
for (int i = 0; i < Glyphs.Size; i++)
|
for (int i = 0; i < Glyphs.Size; i++)
|
||||||
{
|
{
|
||||||
@ -3741,8 +3741,8 @@ void ImFont::BuildLookupTable()
|
|||||||
IndexLookup[codepoint] = (ImWchar)i;
|
IndexLookup[codepoint] = (ImWchar)i;
|
||||||
|
|
||||||
// Mark 4K page as used
|
// Mark 4K page as used
|
||||||
const int page_n = codepoint / 4096;
|
const int page_n = codepoint / 8192;
|
||||||
Used4kPagesMap[page_n >> 3] |= 1 << (page_n & 7);
|
Used8kPagesMap[page_n >> 3] |= 1 << (page_n & 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a glyph to handle TAB
|
// Create a glyph to handle TAB
|
||||||
@ -3804,15 +3804,15 @@ void ImFont::BuildLookupTable()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// API is designed this way to avoid exposing the 4K page size
|
// API is designed this way to avoid exposing the 8K page size
|
||||||
// e.g. use with IsGlyphRangeUnused(0, 255)
|
// e.g. use with IsGlyphRangeUnused(0, 255)
|
||||||
bool ImFont::IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last)
|
bool ImFont::IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last)
|
||||||
{
|
{
|
||||||
unsigned int page_begin = (c_begin / 4096);
|
unsigned int page_begin = (c_begin / 8192);
|
||||||
unsigned int page_last = (c_last / 4096);
|
unsigned int page_last = (c_last / 8192);
|
||||||
for (unsigned int page_n = page_begin; page_n <= page_last; page_n++)
|
for (unsigned int page_n = page_begin; page_n <= page_last; page_n++)
|
||||||
if ((page_n >> 3) < sizeof(Used4kPagesMap))
|
if ((page_n >> 3) < sizeof(Used8kPagesMap))
|
||||||
if (Used4kPagesMap[page_n >> 3] & (1 << (page_n & 7)))
|
if (Used8kPagesMap[page_n >> 3] & (1 << (page_n & 7)))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user