mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Squash duplicated sf::Font glyphs to single chars
Before this change, `sf::Font` always rendered/provided one character per Unicode codepoint, even if that character wasn't represented by the current font file or duplicated. This caused more texture space to be used than necessary, which is especially apparent, when trying to render a large amount of unhandled glyphs (the texture would literally fill up with empty squares representing missing characters).
This commit is contained in:
parent
bcb013b45b
commit
dc0dfd601a
@ -71,10 +71,10 @@ namespace
|
||||
return output;
|
||||
}
|
||||
|
||||
// Combine outline thickness, boldness and codepoint into a single 64-bit key
|
||||
sf::Uint64 combine(float outlineThickness, bool bold, sf::Uint32 codePoint)
|
||||
// Combine outline thickness, boldness and font glyph index into a single 64-bit key
|
||||
sf::Uint64 combine(float outlineThickness, bool bold, sf::Uint32 index)
|
||||
{
|
||||
return (static_cast<sf::Uint64>(reinterpret<sf::Uint32>(outlineThickness)) << 32) | (static_cast<sf::Uint64>(bold) << 31) | codePoint;
|
||||
return (static_cast<sf::Uint64>(reinterpret<sf::Uint32>(outlineThickness)) << 32) | (static_cast<sf::Uint64>(bold) << 31) | index;
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,8 +346,8 @@ const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool b
|
||||
// Get the page corresponding to the character size
|
||||
GlyphTable& glyphs = m_pages[characterSize].glyphs;
|
||||
|
||||
// Build the key by combining the code point, bold flag, and outline thickness
|
||||
Uint64 key = combine(outlineThickness, bold, codePoint);
|
||||
// Build the key by combining the glyph index (based on code point), bold flag, and outline thickness
|
||||
Uint64 key = combine(outlineThickness, bold, FT_Get_Char_Index(static_cast<FT_Face>(m_face), codePoint));
|
||||
|
||||
// Search the glyph into the cache
|
||||
GlyphTable::const_iterator it = glyphs.find(key);
|
||||
|
Loading…
Reference in New Issue
Block a user