From 7ec63acd1dc5d05c47c1915fe491df56bab7e0a2 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 19 Aug 2020 01:23:27 +0900 Subject: [PATCH] ebiten: Bug fix: Set the state of being volatile on SetClearingScreenSkipped Fixes #1309 --- examples/contextlost/main.go | 11 ++++++++++- run.go | 1 + uicontext.go | 11 ++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/contextlost/main.go b/examples/contextlost/main.go index 2d06d84a0..e8b799542 100644 --- a/examples/contextlost/main.go +++ b/examples/contextlost/main.go @@ -93,6 +93,10 @@ func (g *Game) Update(screen *ebiten.Image) error { return nil } + if inpututil.IsKeyJustPressed(ebiten.KeyS) { + ebiten.SetClearingScreenSkipped(!ebiten.IsClearingScreenSkipped()) + } + g.count++ return nil } @@ -107,7 +111,12 @@ func (g *Game) Draw(screen *ebiten.Image) { op.GeoM.Translate(screenWidth/2, screenHeight/2) screen.DrawImage(gophersImage, op) - ebitenutil.DebugPrint(screen, "Press Space to force to lose/restore the GL context!\n(Browser only)") + msg := `Press Space to force to lose/restore the GL context! +(Browser only) + +Press S to switch clearing the screen +at the beginning of each frame.` + ebitenutil.DebugPrint(screen, msg) } func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) { diff --git a/run.go b/run.go index b8698050a..f64eb5751 100644 --- a/run.go +++ b/run.go @@ -112,6 +112,7 @@ func SetClearingScreenSkipped(skipped bool) { v = 1 } atomic.StoreInt32(&isClearingScreenSkipped, v) + theUIContext.setClearingScreenSkipped(skipped) } // IsClearingScreenSkipped returns true if the frame isn't cleared at the beginning. diff --git a/uicontext.go b/uicontext.go index 57986100b..ede097e8c 100644 --- a/uicontext.go +++ b/uicontext.go @@ -176,7 +176,7 @@ func (c *uiContext) updateOffscreen() { } if c.offscreen == nil { c.offscreen = newImage(sw, sh, FilterDefault) - c.offscreen.mipmap.SetVolatile(true) + c.offscreen.mipmap.SetVolatile(!IsClearingScreenSkipped()) } // The window size is automatically adjusted when Run is used. @@ -193,6 +193,15 @@ func (c *uiContext) updateOffscreen() { // scale. This is fine since ebiten.ScreenScale will be deprecated. } +func (c *uiContext) setClearingScreenSkipped(skipped bool) { + c.m.Lock() + defer c.m.Unlock() + + if c.offscreen != nil { + c.offscreen.mipmap.SetVolatile(!skipped) + } +} + func (c *uiContext) setWindowResizable(resizable bool) { c.m.Lock() defer c.m.Unlock()