mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
restoring: Refactoring: Add Image.screen and unify restoring functions
This commit is contained in:
parent
c73860caa2
commit
959abec06d
10
imageimpl.go
10
imageimpl.go
@ -30,7 +30,6 @@ import (
|
||||
type imageImpl struct {
|
||||
disposed bool
|
||||
restorable *restorable.Image
|
||||
screen bool
|
||||
m sync.Mutex
|
||||
}
|
||||
|
||||
@ -82,7 +81,6 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
||||
}
|
||||
i := &imageImpl{
|
||||
restorable: img,
|
||||
screen: true,
|
||||
}
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
return i, nil
|
||||
@ -215,13 +213,7 @@ func (i *imageImpl) restore(context *opengl.Context) error {
|
||||
if i.disposed {
|
||||
return nil
|
||||
}
|
||||
if i.screen {
|
||||
if err := i.restorable.RestoreAsScreen(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if err := i.restorable.RestoreImage(context); err != nil {
|
||||
if err := i.restorable.Restore(context); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -45,6 +45,7 @@ type Image struct {
|
||||
stale bool
|
||||
|
||||
volatile bool
|
||||
screen bool
|
||||
}
|
||||
|
||||
func NewImage(width, height int, filter opengl.Filter, volatile bool) (*Image, error) {
|
||||
@ -87,6 +88,7 @@ func NewScreenFramebufferImage(width, height int) (*Image, error) {
|
||||
width: width,
|
||||
height: height,
|
||||
volatile: true,
|
||||
screen: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -229,7 +231,21 @@ func (p *Image) HasDependency() bool {
|
||||
}
|
||||
|
||||
// RestoreImage restores *graphics.Image from the pixels using its state.
|
||||
func (p *Image) RestoreImage(context *opengl.Context) error {
|
||||
func (p *Image) Restore(context *opengl.Context) error {
|
||||
if p.screen {
|
||||
// The screen image should also be recreated because framebuffer might
|
||||
// be changed.
|
||||
var err error
|
||||
p.image, err = graphics.NewScreenFramebufferImage(p.width, p.height)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.basePixels = nil
|
||||
p.baseColor = color.RGBA{}
|
||||
p.drawImageHistory = nil
|
||||
p.stale = false
|
||||
return nil
|
||||
}
|
||||
if p.volatile {
|
||||
var err error
|
||||
p.image, err = graphics.NewImage(p.width, p.height, p.filter)
|
||||
@ -284,18 +300,6 @@ func (p *Image) RestoreImage(context *opengl.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Image) RestoreAsScreen() error {
|
||||
// The screen image should also be recreated because framebuffer might
|
||||
// be changed.
|
||||
var err error
|
||||
p.image, err = graphics.NewScreenFramebufferImage(p.width, p.height)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: Reset other values?
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Image) Dispose() error {
|
||||
if err := p.image.Dispose(); err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user