mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
Cache SubImage for the empty images
This commit is contained in:
parent
2b77b57b75
commit
569964d7e4
@ -24,7 +24,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyImage = ebiten.NewImage(3, 3)
|
emptyImage = ebiten.NewImage(3, 3)
|
||||||
|
emptySubImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -46,7 +47,7 @@ func DrawLine(dst *ebiten.Image, x1, y1, x2, y2 float64, clr color.Color) {
|
|||||||
op.ColorM = colormcache.ColorToColorM(clr)
|
op.ColorM = colormcache.ColorToColorM(clr)
|
||||||
// Filter must be 'nearest' filter (default).
|
// Filter must be 'nearest' filter (default).
|
||||||
// Linear filtering would make edges blurred.
|
// Linear filtering would make edges blurred.
|
||||||
dst.DrawImage(emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image), op)
|
dst.DrawImage(emptySubImage, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawRect draws a rectangle on the given destination dst.
|
// DrawRect draws a rectangle on the given destination dst.
|
||||||
|
7
image.go
7
image.go
@ -69,7 +69,10 @@ func (i *Image) Clear() {
|
|||||||
i.Fill(color.Transparent)
|
i.Fill(color.Transparent)
|
||||||
}
|
}
|
||||||
|
|
||||||
var emptyImage = NewImage(3, 3)
|
var (
|
||||||
|
emptyImage = NewImage(3, 3)
|
||||||
|
emptySubImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*Image)
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
w, h := emptyImage.Size()
|
w, h := emptyImage.Size()
|
||||||
@ -101,7 +104,7 @@ func (i *Image) Fill(clr color.Color) {
|
|||||||
op.ColorM.Scale(rf, gf, bf, af)
|
op.ColorM.Scale(rf, gf, bf, af)
|
||||||
op.CompositeMode = CompositeModeCopy
|
op.CompositeMode = CompositeModeCopy
|
||||||
|
|
||||||
i.DrawImage(emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*Image), op)
|
i.DrawImage(emptySubImage, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
func canSkipMipmap(geom GeoM, filter driver.Filter) bool {
|
func canSkipMipmap(geom GeoM, filter driver.Filter) bool {
|
||||||
|
@ -26,7 +26,10 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/vector/internal/triangulate"
|
"github.com/hajimehoshi/ebiten/v2/vector/internal/triangulate"
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyImage = ebiten.NewImage(3, 3)
|
var (
|
||||||
|
emptyImage = ebiten.NewImage(3, 3)
|
||||||
|
emptySubImage = emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
emptyImage.Fill(color.White)
|
emptyImage.Fill(color.White)
|
||||||
@ -139,5 +142,5 @@ func (p *Path) Fill(dst *ebiten.Image, op *FillOptions) {
|
|||||||
}
|
}
|
||||||
base += uint16(len(seg))
|
base += uint16(len(seg))
|
||||||
}
|
}
|
||||||
dst.DrawTriangles(vertices, indices, emptyImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image), nil)
|
dst.DrawTriangles(vertices, indices, emptySubImage, nil)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user