mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
restorable: Remove arguments from restoring functions
This commit is contained in:
parent
02151e48ea
commit
b8b7e97511
@ -233,18 +233,18 @@ func (i *imageImpl) restore(context *opengl.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if i.screen {
|
if i.screen {
|
||||||
if err := i.restorable.RestoreAsScreen(i.width, i.height); err != nil {
|
if err := i.restorable.RestoreAsScreen(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if i.volatile {
|
if i.volatile {
|
||||||
if err := i.restorable.Recreate(i.width, i.height, glFilter(i.filter)); err != nil {
|
if err := i.restorable.Recreate(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := i.restorable.RestoreImage(context, i.width, i.height, glFilter(i.filter)); err != nil {
|
if err := i.restorable.RestoreImage(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -34,6 +34,9 @@ type drawImageHistoryItem struct {
|
|||||||
// Image represents an image of an image for restoring when GL context is lost.
|
// Image represents an image of an image for restoring when GL context is lost.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
image *graphics.Image
|
image *graphics.Image
|
||||||
|
width int
|
||||||
|
height int
|
||||||
|
filter opengl.Filter
|
||||||
|
|
||||||
// baseImage and baseColor are exclusive.
|
// baseImage and baseColor are exclusive.
|
||||||
basePixels []uint8
|
basePixels []uint8
|
||||||
@ -49,6 +52,9 @@ func NewImage(width, height int, filter opengl.Filter) (*Image, error) {
|
|||||||
}
|
}
|
||||||
return &Image{
|
return &Image{
|
||||||
image: img,
|
image: img,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
filter: filter,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +64,13 @@ func NewImageFromImage(source *image.RGBA, filter opengl.Filter) (*Image, error)
|
|||||||
// TODO: texture should be removed here?
|
// TODO: texture should be removed here?
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
size := source.Bounds().Size()
|
||||||
|
width, height := size.X, size.Y
|
||||||
return &Image{
|
return &Image{
|
||||||
image: img,
|
image: img,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
filter: filter,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +81,8 @@ func NewScreenFramebufferImage(width, height int) (*Image, error) {
|
|||||||
}
|
}
|
||||||
return &Image{
|
return &Image{
|
||||||
image: img,
|
image: img,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,17 +215,17 @@ 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, width, height int, filter opengl.Filter) error {
|
func (p *Image) RestoreImage(context *opengl.Context) error {
|
||||||
if p.stale {
|
if p.stale {
|
||||||
return errors.New("restorable: pixels must not be stale when restoring")
|
return errors.New("restorable: pixels must not be stale when restoring")
|
||||||
}
|
}
|
||||||
img := image.NewRGBA(image.Rect(0, 0, width, height))
|
img := image.NewRGBA(image.Rect(0, 0, p.width, p.height))
|
||||||
if p.basePixels != nil {
|
if p.basePixels != nil {
|
||||||
for j := 0; j < height; j++ {
|
for j := 0; j < p.height; j++ {
|
||||||
copy(img.Pix[j*img.Stride:], p.basePixels[j*width*4:(j+1)*width*4])
|
copy(img.Pix[j*img.Stride:], p.basePixels[j*p.width*4:(j+1)*p.width*4])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gimg, err := graphics.NewImageFromImage(img, filter)
|
gimg, err := graphics.NewImageFromImage(img, p.filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -245,11 +258,11 @@ func (p *Image) RestoreImage(context *opengl.Context, width, height int, filter
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) RestoreAsScreen(width, height int) error {
|
func (p *Image) RestoreAsScreen() error {
|
||||||
// The screen image should also be recreated because framebuffer might
|
// The screen image should also be recreated because framebuffer might
|
||||||
// be changed.
|
// be changed.
|
||||||
var err error
|
var err error
|
||||||
p.image, err = graphics.NewScreenFramebufferImage(width, height)
|
p.image, err = graphics.NewScreenFramebufferImage(p.width, p.height)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -257,9 +270,9 @@ func (p *Image) RestoreAsScreen(width, height int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Image) Recreate(width, height int, filter opengl.Filter) error {
|
func (p *Image) Recreate() error {
|
||||||
var err error
|
var err error
|
||||||
p.image, err = graphics.NewImage(width, height, filter)
|
p.image, err = graphics.NewImage(p.width, p.height, p.filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user