diff --git a/internal/ui/context.go b/internal/ui/context.go index 3b0f506b9..1034954cc 100644 --- a/internal/ui/context.go +++ b/internal/ui/context.go @@ -145,7 +145,18 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update } func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics) { - c.offscreen.mipmap.SetVolatile(theGlobalState.isScreenClearedEveryFrame()) + if c.offscreen.volatile != theGlobalState.isScreenClearedEveryFrame() { + w, h := c.offscreen.width, c.offscreen.height + c.offscreen.MarkDisposed() + c.offscreen = c.game.NewOffscreenImage(w, h) + + // TODO: Give volatile/isolated property to the constructor. + if theGlobalState.isScreenClearedEveryFrame() { + c.offscreen.setVolatile(true) + } else { + c.offscreen.mipmap.SetIsolated(true) + } + } // Even though updateCount == 0, the offscreen is cleared and Draw is called. // Draw should not update the game state and then the screen should not be updated without Update, but @@ -245,11 +256,16 @@ func (c *context) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFac if c.offscreen == nil { c.offscreen = c.game.NewOffscreenImage(ow, oh) - // Keep the offscreen an isolated image from an atlas (#1938). - // The shader program for the screen is special and doesn't work well with an image on an atlas. - // An image on an atlas is surrounded by a transparent edge, - // and the shader program unexpectedly picks the pixel on the edges. - c.offscreen.mipmap.SetIsolated(true) + // TODO: Give volatile/isolated property to the constructor. + if theGlobalState.isScreenClearedEveryFrame() { + c.offscreen.setVolatile(true) + } else { + // Keep the offscreen an isolated image from an atlas (#1938). + // The shader program for the screen is special and doesn't work well with an image on an atlas. + // An image on an atlas is surrounded by a transparent edge, + // and the shader program unexpectedly picks the pixel on the edges. + c.offscreen.mipmap.SetIsolated(true) + } } return ow, oh diff --git a/internal/ui/image.go b/internal/ui/image.go index 56d37e700..d3ce4ed17 100644 --- a/internal/ui/image.go +++ b/internal/ui/image.go @@ -30,9 +30,10 @@ func SetPanicOnErrorOnReadingPixelsForTesting(value bool) { } type Image struct { - mipmap *mipmap.Mipmap - width int - height int + mipmap *mipmap.Mipmap + width int + height int + volatile bool } func NewImage(width, height int) *Image { @@ -51,6 +52,11 @@ func newScreenFramebufferImage(width, height int) *Image { } } +func (i *Image) setVolatile(volatile bool) { + i.volatile = volatile + i.mipmap.SetVolatile(volatile) +} + func (i *Image) MarkDisposed() { if i.mipmap == nil { return