ebiten: Bug fix: Set the state of being volatile on SetClearingScreenSkipped

Fixes #1309
This commit is contained in:
Hajime Hoshi 2020-08-19 01:23:27 +09:00
parent 8aef1f9080
commit 7ec63acd1d
3 changed files with 21 additions and 2 deletions

View File

@ -93,6 +93,10 @@ func (g *Game) Update(screen *ebiten.Image) error {
return nil return nil
} }
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
ebiten.SetClearingScreenSkipped(!ebiten.IsClearingScreenSkipped())
}
g.count++ g.count++
return nil return nil
} }
@ -107,7 +111,12 @@ func (g *Game) Draw(screen *ebiten.Image) {
op.GeoM.Translate(screenWidth/2, screenHeight/2) op.GeoM.Translate(screenWidth/2, screenHeight/2)
screen.DrawImage(gophersImage, op) 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) { func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {

1
run.go
View File

@ -112,6 +112,7 @@ func SetClearingScreenSkipped(skipped bool) {
v = 1 v = 1
} }
atomic.StoreInt32(&isClearingScreenSkipped, v) atomic.StoreInt32(&isClearingScreenSkipped, v)
theUIContext.setClearingScreenSkipped(skipped)
} }
// IsClearingScreenSkipped returns true if the frame isn't cleared at the beginning. // IsClearingScreenSkipped returns true if the frame isn't cleared at the beginning.

View File

@ -176,7 +176,7 @@ func (c *uiContext) updateOffscreen() {
} }
if c.offscreen == nil { if c.offscreen == nil {
c.offscreen = newImage(sw, sh, FilterDefault) 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. // 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. // 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) { func (c *uiContext) setWindowResizable(resizable bool) {
c.m.Lock() c.m.Lock()
defer c.m.Unlock() defer c.m.Unlock()