mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
graphics: Fix restoring logic
This commit is contained in:
parent
127cd4cab6
commit
f897c3958e
@ -97,7 +97,7 @@ func (c *graphicsContext) Resume() error {
|
|||||||
if err := graphics.Initialize(ui.GLContext()); err != nil {
|
if err := graphics.Initialize(ui.GLContext()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := theImages.restorePixels(); err != nil {
|
if err := theImages.restorePixels(ui.GLContext()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
20
image.go
20
image.go
@ -89,11 +89,11 @@ func (i *images) remove(img *Image) {
|
|||||||
delete(i.images, img.impl)
|
delete(i.images, img.impl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *images) restorePixels() error {
|
func (i *images) restorePixels(context *opengl.Context) error {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
defer i.m.Unlock()
|
defer i.m.Unlock()
|
||||||
for img := range i.images {
|
for img := range i.images {
|
||||||
if err := img.restorePixels(); err != nil {
|
if err := img.restorePixels(context); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ func (i *imageImpl) At(x, y int) color.Color {
|
|||||||
return color.RGBA{r, g, b, a}
|
return color.RGBA{r, g, b, a}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imageImpl) restorePixels() error {
|
func (i *imageImpl) restorePixels(context *opengl.Context) error {
|
||||||
imageM.Lock()
|
imageM.Lock()
|
||||||
defer imageM.Unlock()
|
defer imageM.Unlock()
|
||||||
if i.defaultFramebuffer {
|
if i.defaultFramebuffer {
|
||||||
@ -302,15 +302,19 @@ func (i *imageImpl) restorePixels() error {
|
|||||||
if i.disposed {
|
if i.disposed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if i.pixels == nil {
|
|
||||||
return errors.New("ebiten: pixels must not be nil")
|
|
||||||
}
|
|
||||||
if i.texture != nil {
|
if i.texture != nil {
|
||||||
return errors.New("ebiten: texture must be nil")
|
// TODO: As the texture is already disposed, is it correct to delete it here?
|
||||||
|
if err := i.texture.Dispose(context); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if i.framebuffer != nil {
|
if i.framebuffer != nil {
|
||||||
return errors.New("ebiten: framebuffer must be nil")
|
// TODO: Ditto
|
||||||
|
if err := i.framebuffer.Dispose(context); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: Recalc i.pixels here
|
||||||
img := image.NewRGBA(image.Rect(0, 0, i.width, i.height))
|
img := image.NewRGBA(image.Rect(0, 0, i.width, i.height))
|
||||||
for j := 0; j < i.height; j++ {
|
for j := 0; j < i.height; j++ {
|
||||||
copy(img.Pix[j*img.Stride:], i.pixels[j*i.width*4:(j+1)*i.width*4])
|
copy(img.Pix[j*img.Stride:], i.pixels[j*i.width*4:(j+1)*i.width*4])
|
||||||
|
Loading…
Reference in New Issue
Block a user