Implement optimizations for 2D text rendering #23
Reference in New Issue
Block a user
No description provided.
Delete Branch "ori_sky/JGL:master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The following patches are included:
J2D: Rewrite text rendering
This patch rewrites text rendering for
J2D::DrawString
to now constructa texture atlas for all ASCII-range glyphs in the FT font face, instead
of constructing a texture for every glyph.
This improves text rendering performance for several reasons:
a context switch for internal data like texture parameters, and also
cannot optimize for accesses to the same texture across draw calls.
This patch removes the need to call
glBindTexture
more than once percall to
J2D::DrawString
.be rendered in a single call to
glDrawArrays
. This is done by storingthe cached texture coordinates on
CachedGlyph
and constructing a fullarray of vertices and texture coordinates for the entire string at
once, resulting in only /one/ set of client-to-device attribute
uploads and only one draw call, instead of being required to upload
attribute data for each glyph separately.
FontCache: Use map for efficient glyph lookup
This patch updates
CachedFont
to now use anstd::map
for cached glyphs,instead of an
std::vector
.std::map
allows O(log n) lookup, whereasstd::vector
only allows O(n) lookup.Note:
std::unordered_map
technically has better lookup complexity here,with amortized O(1) lookup. However, hashmaps have a higher inherent
overhead than red-black trees so this would only be viable when going
above around 1000 entries, which should never happen here for ASCII
glyphs.