diff --git a/internal/ui/context.go b/internal/ui/context.go index 2c5d32e3e..04783e302 100644 --- a/internal/ui/context.go +++ b/internal/ui/context.go @@ -53,7 +53,7 @@ type context struct { offscreenWidth float64 offscreenHeight float64 - isOffscreenDirty bool + isOffscreenModified bool skipCount int } @@ -157,6 +157,9 @@ func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, forceDraw boo c.offscreen = c.game.NewOffscreenImage(w, h) } + // isOffscreenModified is updated when an offscreen's modifyCallback. + c.isOffscreenModified = false + // 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 // users might want to process something at Draw with the time intervals of FPS. @@ -164,8 +167,6 @@ func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, forceDraw boo c.offscreen.clear() } - // isOffscreenDirty is updated when an offscreen's drawCallback. - c.isOffscreenDirty = false if err := c.game.DrawOffscreen(); err != nil { return err } @@ -173,7 +174,7 @@ func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, forceDraw boo // 180 might be too big but this is a enough value to consider exiting from fullscreen on macOS (#2500). const maxSkipCount = 180 - if !forceDraw && !theGlobalState.isScreenClearedEveryFrame() && !c.isOffscreenDirty { + if !forceDraw && !c.isOffscreenModified { if c.skipCount < maxSkipCount { c.skipCount++ } @@ -232,8 +233,8 @@ func (c *context) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFac } if c.offscreen == nil { c.offscreen = c.game.NewOffscreenImage(ow, oh) - c.offscreen.drawCallback = func() { - c.isOffscreenDirty = true + c.offscreen.modifyCallback = func() { + c.isOffscreenModified = true } } diff --git a/internal/ui/image.go b/internal/ui/image.go index 7c5eb3153..04e987051 100644 --- a/internal/ui/image.go +++ b/internal/ui/image.go @@ -46,9 +46,9 @@ type Image struct { bigOffscreenBufferBlend graphicsdriver.Blend bigOffscreenBufferDirty bool - // drawCallback is a callback called when DrawTriangles or WritePixels is called. - // drawCallback is useful to detect whether the image is manipulated or not after a certain time. - drawCallback func() + // modifyCallback is a callback called when DrawTriangles or WritePixels is called. + // modifyCallback is useful to detect whether the image is manipulated or not after a certain time. + modifyCallback func() // These temporary vertices must not be reused until the vertices are sent to the graphics command queue. @@ -78,12 +78,12 @@ func (i *Image) MarkDisposed() { i.mipmap.MarkDisposed() i.mipmap = nil i.dotsBuffer = nil - i.drawCallback = nil + i.modifyCallback = nil } func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms []uint32, evenOdd bool, canSkipMipmap bool, antialias bool) { - if i.drawCallback != nil { - i.drawCallback() + if i.modifyCallback != nil { + i.modifyCallback() } if antialias { @@ -160,8 +160,8 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [ } func (i *Image) WritePixels(pix []byte, x, y, width, height int) { - if i.drawCallback != nil { - i.drawCallback() + if i.modifyCallback != nil { + i.modifyCallback() } if width == 1 && height == 1 {