mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
text: Improve the comment
This commit is contained in:
parent
cdf700ed84
commit
3f97386d8e
23
text/text.go
23
text/text.go
@ -156,10 +156,13 @@ var textM sync.Mutex
|
|||||||
// Line height is based on Metrics().Height of the font.
|
// Line height is based on Metrics().Height of the font.
|
||||||
//
|
//
|
||||||
// Glyphs used for rendering are cached in least-recently-used way.
|
// 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 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 = Create glyphs by `(*ebiten.Image).ReplacePixels` and put them into the cache if necessary
|
||||||
// + Draw them onto the destination by `(*ebiten.Image).DrawImage`
|
// + 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.
|
// 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.
|
// 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
|
// 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
|
// 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
|
// 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
|
// 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.
|
// 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.
|
// If a rune's glyph is already cached, CacheGlyphs does nothing for the rune.
|
||||||
func CacheGlyphs(face font.Face, text string) {
|
func CacheGlyphs(face font.Face, text string) {
|
||||||
textM.Lock()
|
textM.Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user