mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
restorable: Remove IsStale
This commit is contained in:
parent
cae75fac69
commit
e7558036ae
19
imageimpl.go
19
imageimpl.go
@ -109,8 +109,10 @@ func (i *imageImpl) Fill(clr color.Color) error {
|
||||
return errors.New("ebiten: image is already disposed")
|
||||
}
|
||||
rgba := color.RGBAModel.Convert(clr).(color.RGBA)
|
||||
i.restorable.Fill(rgba)
|
||||
return i.restorable.Image().Fill(rgba)
|
||||
if err := i.restorable.Fill(rgba); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *imageImpl) clearIfVolatile() error {
|
||||
@ -122,8 +124,10 @@ func (i *imageImpl) clearIfVolatile() error {
|
||||
if !i.volatile {
|
||||
return nil
|
||||
}
|
||||
i.restorable.Clear()
|
||||
return i.restorable.Image().Fill(color.RGBA{})
|
||||
if err := i.restorable.Clear(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||
@ -160,12 +164,7 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||
geom := options.GeoM
|
||||
colorm := options.ColorM
|
||||
mode := opengl.CompositeMode(options.CompositeMode)
|
||||
if image.impl.restorable.IsStale() {
|
||||
i.restorable.MakeStale()
|
||||
} else {
|
||||
i.restorable.AppendDrawImageHistory(image.impl.restorable.Image(), vertices, &geom, &colorm, mode)
|
||||
}
|
||||
if err := i.restorable.Image().DrawImage(image.impl.restorable.Image(), vertices, &geom, &colorm, mode); err != nil {
|
||||
if err := i.restorable.DrawImage(image.impl.restorable, vertices, &geom, &colorm, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -73,10 +73,6 @@ func NewScreenFramebufferImage(width, height int) (*Image, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Image) IsStale() bool {
|
||||
return p.stale
|
||||
}
|
||||
|
||||
func (p *Image) MakeStale() {
|
||||
p.basePixels = nil
|
||||
p.baseColor = color.RGBA{}
|
||||
@ -84,18 +80,29 @@ func (p *Image) MakeStale() {
|
||||
p.stale = true
|
||||
}
|
||||
|
||||
func (p *Image) Clear() {
|
||||
func (p *Image) Clear() error {
|
||||
p.basePixels = nil
|
||||
p.baseColor = color.RGBA{}
|
||||
p.drawImageHistory = nil
|
||||
p.stale = false
|
||||
if p.image == nil {
|
||||
panic("not reach")
|
||||
}
|
||||
if err := p.image.Fill(color.RGBA{}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Image) Fill(clr color.RGBA) {
|
||||
func (p *Image) Fill(clr color.RGBA) error {
|
||||
p.basePixels = nil
|
||||
p.baseColor = clr
|
||||
p.drawImageHistory = nil
|
||||
p.stale = false
|
||||
if err := p.image.Fill(clr); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Image) ReplacePixels(pixels []uint8) {
|
||||
@ -108,12 +115,24 @@ func (p *Image) ReplacePixels(pixels []uint8) {
|
||||
p.stale = false
|
||||
}
|
||||
|
||||
func (p *Image) DrawImage(img *Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) error {
|
||||
if img.stale {
|
||||
p.MakeStale()
|
||||
} else {
|
||||
p.appendDrawImageHistory(img.image, vertices, geom, colorm, mode)
|
||||
}
|
||||
if err := p.image.DrawImage(img.image, vertices, geom, colorm, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Image) Image() *graphics.Image {
|
||||
// TODO: This function is temporary. Remove this.
|
||||
return p.image
|
||||
}
|
||||
|
||||
func (p *Image) AppendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) {
|
||||
func (p *Image) appendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) {
|
||||
if p.stale {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user