mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
text: Cache color matrices for performance
This commit is contained in:
parent
9118772fd1
commit
12cef4d27e
20
text/text.go
20
text/text.go
@ -124,6 +124,10 @@ func fixed26_6ToFloat64(x fixed.Int26_6) float64 {
|
|||||||
return float64(x) / (1 << 6)
|
return float64(x) / (1 << 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
colorMCache = map[color.Color]ebiten.ColorM{}
|
||||||
|
)
|
||||||
|
|
||||||
func (g *glyph) draw(dst *ebiten.Image, x, y fixed.Int26_6, clr color.Color) {
|
func (g *glyph) draw(dst *ebiten.Image, x, y fixed.Int26_6, clr color.Color) {
|
||||||
cr, cg, cb, ca := clr.RGBA()
|
cr, cg, cb, ca := clr.RGBA()
|
||||||
if ca == 0 {
|
if ca == 0 {
|
||||||
@ -134,11 +138,17 @@ func (g *glyph) draw(dst *ebiten.Image, x, y fixed.Int26_6, clr color.Color) {
|
|||||||
op := &ebiten.DrawImageOptions{}
|
op := &ebiten.DrawImageOptions{}
|
||||||
op.GeoM.Translate(fixed26_6ToFloat64(x+b.Min.X), fixed26_6ToFloat64(y+b.Min.Y))
|
op.GeoM.Translate(fixed26_6ToFloat64(x+b.Min.X), fixed26_6ToFloat64(y+b.Min.Y))
|
||||||
|
|
||||||
rf := float64(cr) / float64(ca)
|
cm, ok := colorMCache[clr]
|
||||||
gf := float64(cg) / float64(ca)
|
if !ok {
|
||||||
bf := float64(cb) / float64(ca)
|
rf := float64(cr) / float64(ca)
|
||||||
af := float64(ca) / 0xffff
|
gf := float64(cg) / float64(ca)
|
||||||
op.ColorM.Scale(rf, gf, bf, af)
|
bf := float64(cb) / float64(ca)
|
||||||
|
af := float64(ca) / 0xffff
|
||||||
|
cm.Reset()
|
||||||
|
cm.Scale(rf, gf, bf, af)
|
||||||
|
colorMCache[clr] = cm
|
||||||
|
}
|
||||||
|
op.ColorM = cm
|
||||||
|
|
||||||
a := atlases[g.char.face][g.char.atlasGroup()]
|
a := atlases[g.char.face][g.char.atlasGroup()]
|
||||||
sx, sy := a.at(g)
|
sx, sy := a.at(g)
|
||||||
|
Loading…
Reference in New Issue
Block a user