mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: Replace emptyImage with dummyImage (not initialized)
This commit is contained in:
parent
abdfb3b713
commit
87daa82ad9
@ -102,11 +102,12 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
||||
// TODO: This clear is needed only when the screen size is changed.
|
||||
if c.offsetX > 0 || c.offsetY > 0 {
|
||||
op := &DrawImageOptions{}
|
||||
w, h := emptyImage.Size()
|
||||
w, h := dummyImage.Size()
|
||||
s := float64(graphics.MaxImageSize())
|
||||
op.GeoM.Scale(s/float64(w), s/float64(h))
|
||||
op.ColorM.Scale(0, 0, 0, 0)
|
||||
op.CompositeMode = CompositeModeCopy
|
||||
c.screen.DrawImage(emptyImage, op)
|
||||
c.screen.DrawImage(dummyImage, op)
|
||||
}
|
||||
|
||||
dw, dh := c.screen.Size()
|
||||
|
21
image.go
21
image.go
@ -26,20 +26,10 @@ import (
|
||||
"github.com/hajimehoshi/ebiten/internal/shareable"
|
||||
)
|
||||
|
||||
// emptyImage is an empty image used for filling other images with a uniform color.
|
||||
// dummyImage is an empty image used for filling other images with a uniform color.
|
||||
//
|
||||
// Do not call Fill or Clear on emptyImage or the program causes infinite recursion.
|
||||
var emptyImage *Image
|
||||
|
||||
func init() {
|
||||
const (
|
||||
w = 16
|
||||
h = 16
|
||||
)
|
||||
emptyImage = newImageWithoutInit(w, h)
|
||||
pix := make([]uint8, w*h*4)
|
||||
_ = emptyImage.ReplacePixels(pix)
|
||||
}
|
||||
// Do not call Fill or Clear on dummyImage or the program causes infinite recursion.
|
||||
var dummyImage = newImageWithoutInit(16, 16)
|
||||
|
||||
// Image represents a rectangle set of pixels.
|
||||
// The pixel format is alpha-premultiplied RGBA.
|
||||
@ -92,11 +82,12 @@ func (i *Image) Fill(clr color.Color) error {
|
||||
|
||||
func (i *Image) fill(r, g, b, a uint8) {
|
||||
wd, hd := i.Size()
|
||||
ws, hs := emptyImage.Size()
|
||||
ws, hs := dummyImage.Size()
|
||||
sw := float64(wd) / float64(ws)
|
||||
sh := float64(hd) / float64(hs)
|
||||
op := &DrawImageOptions{}
|
||||
op.GeoM.Scale(sw, sh)
|
||||
op.ColorM.Scale(0, 0, 0, 0)
|
||||
if a > 0 {
|
||||
rf := float64(r) / float64(a)
|
||||
gf := float64(g) / float64(a)
|
||||
@ -106,7 +97,7 @@ func (i *Image) fill(r, g, b, a uint8) {
|
||||
}
|
||||
op.CompositeMode = CompositeModeCopy
|
||||
op.Filter = FilterNearest
|
||||
_ = i.DrawImage(emptyImage, op)
|
||||
_ = i.DrawImage(dummyImage, op)
|
||||
}
|
||||
|
||||
func (i *Image) isDisposed() bool {
|
||||
|
Loading…
Reference in New Issue
Block a user