mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +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")
|
return errors.New("ebiten: image is already disposed")
|
||||||
}
|
}
|
||||||
rgba := color.RGBAModel.Convert(clr).(color.RGBA)
|
rgba := color.RGBAModel.Convert(clr).(color.RGBA)
|
||||||
i.restorable.Fill(rgba)
|
if err := i.restorable.Fill(rgba); err != nil {
|
||||||
return i.restorable.Image().Fill(rgba)
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) clearIfVolatile() error {
|
func (i *imageImpl) clearIfVolatile() error {
|
||||||
@ -122,8 +124,10 @@ func (i *imageImpl) clearIfVolatile() error {
|
|||||||
if !i.volatile {
|
if !i.volatile {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
i.restorable.Clear()
|
if err := i.restorable.Clear(); err != nil {
|
||||||
return i.restorable.Image().Fill(color.RGBA{})
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
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
|
geom := options.GeoM
|
||||||
colorm := options.ColorM
|
colorm := options.ColorM
|
||||||
mode := opengl.CompositeMode(options.CompositeMode)
|
mode := opengl.CompositeMode(options.CompositeMode)
|
||||||
if image.impl.restorable.IsStale() {
|
if err := i.restorable.DrawImage(image.impl.restorable, vertices, &geom, &colorm, mode); err != nil {
|
||||||
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 {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -73,10 +73,6 @@ func NewScreenFramebufferImage(width, height int) (*Image, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) IsStale() bool {
|
|
||||||
return p.stale
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Image) MakeStale() {
|
func (p *Image) MakeStale() {
|
||||||
p.basePixels = nil
|
p.basePixels = nil
|
||||||
p.baseColor = color.RGBA{}
|
p.baseColor = color.RGBA{}
|
||||||
@ -84,18 +80,29 @@ func (p *Image) MakeStale() {
|
|||||||
p.stale = true
|
p.stale = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) Clear() {
|
func (p *Image) Clear() error {
|
||||||
p.basePixels = nil
|
p.basePixels = nil
|
||||||
p.baseColor = color.RGBA{}
|
p.baseColor = color.RGBA{}
|
||||||
p.drawImageHistory = nil
|
p.drawImageHistory = nil
|
||||||
p.stale = false
|
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.basePixels = nil
|
||||||
p.baseColor = clr
|
p.baseColor = clr
|
||||||
p.drawImageHistory = nil
|
p.drawImageHistory = nil
|
||||||
p.stale = false
|
p.stale = false
|
||||||
|
if err := p.image.Fill(clr); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) ReplacePixels(pixels []uint8) {
|
func (p *Image) ReplacePixels(pixels []uint8) {
|
||||||
@ -108,12 +115,24 @@ func (p *Image) ReplacePixels(pixels []uint8) {
|
|||||||
p.stale = false
|
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 {
|
func (p *Image) Image() *graphics.Image {
|
||||||
// TODO: This function is temporary. Remove this.
|
// TODO: This function is temporary. Remove this.
|
||||||
return p.image
|
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 {
|
if p.stale {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user