mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +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 {
|
type imageImpl struct {
|
||||||
disposed bool
|
disposed bool
|
||||||
restorable *restorable.Image
|
restorable *restorable.Image
|
||||||
screen bool
|
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +81,6 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
|||||||
}
|
}
|
||||||
i := &imageImpl{
|
i := &imageImpl{
|
||||||
restorable: img,
|
restorable: img,
|
||||||
screen: true,
|
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||||
return i, nil
|
return i, nil
|
||||||
@ -215,13 +213,7 @@ func (i *imageImpl) restore(context *opengl.Context) error {
|
|||||||
if i.disposed {
|
if i.disposed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if i.screen {
|
if err := i.restorable.Restore(context); err != nil {
|
||||||
if err := i.restorable.RestoreAsScreen(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := i.restorable.RestoreImage(context); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -45,6 +45,7 @@ type Image struct {
|
|||||||
stale bool
|
stale bool
|
||||||
|
|
||||||
volatile bool
|
volatile bool
|
||||||
|
screen bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewImage(width, height int, filter opengl.Filter, volatile bool) (*Image, error) {
|
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,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
volatile: true,
|
volatile: true,
|
||||||
|
screen: true,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +231,21 @@ func (p *Image) HasDependency() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RestoreImage restores *graphics.Image from the pixels using its state.
|
// 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 {
|
if p.volatile {
|
||||||
var err error
|
var err error
|
||||||
p.image, err = graphics.NewImage(p.width, p.height, p.filter)
|
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
|
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 {
|
func (p *Image) Dispose() error {
|
||||||
if err := p.image.Dispose(); err != nil {
|
if err := p.image.Dispose(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user