text: Improve the comment

This commit is contained in:
Hajime Hoshi 2021-04-27 02:28:52 +09:00
parent cdf700ed84
commit 3f97386d8e

View File

@ -156,10 +156,13 @@ var textM sync.Mutex
// Line height is based on Metrics().Height of the font.
//
// Glyphs used for rendering are cached in least-recently-used way.
// It is OK to call Draw with a same text and a same face at every frame in terms of performance.
// Then old glyphs might be evicted from the cache.
// It is not guaranteed that all the glyphs given at Draw are cached.
// The cache is shared with CacheGlyphs.
//
// The two functions are implemented like this:
// It is OK to call Draw with a same text and a same face at every frame in terms of performance.
//
// Draw and CacheGlyphs are implemented like this:
//
// Draw = Create glyphs by `(*ebiten.Image).ReplacePixels` and put them into the cache if necessary
// + Draw them onto the destination by `(*ebiten.Image).DrawImage`
@ -278,8 +281,18 @@ func BoundString(face font.Face, text string) image.Rectangle {
}
// CacheGlyphs precaches the glyphs for the given text and the given font face into the cache.
//
// Glyphs used for rendering are cached in least-recently-used way.
// Then old glyphs might be evicted from the cache.
// It is not guaranteed that all the glyphs given at CacheGlyphs are cached.
// The cache is shared with Draw.
//
// Draw and CacheGlyphs are implemented like this:
//
// Draw = Create glyphs by `(*ebiten.Image).ReplacePixels` and put them into the cache if necessary
// + Draw them onto the destination by `(*ebiten.Image).DrawImage`
// CacheGlyphs = Create glyphs by `(*ebiten.Image).ReplacePixels` and put them into the cache if necessary
//
// Draw automatically creates and caches necessary glyphs, so usually you don't have to call CacheGlyphs
// explicitly. However, for example, when you call Draw for each rune of one big text, Draw tries to create the glyph
// cache and render it for each rune. This is very inefficient because creating a glyph image and rendering it are
@ -287,12 +300,6 @@ func BoundString(face font.Face, text string) image.Rectangle {
// one draw call. CacheGlyphs creates necessary glyphs without rendering them so that these operations are likely
// merged into one draw call regardless of the size of the text.
//
// The two functions are implemented like this:
//
// Draw = Create glyphs by `(*ebiten.Image).ReplacePixels` and put them into the cache if necessary
// + Draw them onto the destination by `(*ebiten.Image).DrawImage`
// CacheGlyphs = Create glyphs by `(*ebiten.Image).ReplacePixels` and put them into the cache if necessary
//
// If a rune's glyph is already cached, CacheGlyphs does nothing for the rune.
func CacheGlyphs(face font.Face, text string) {
textM.Lock()