mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/ui: simplify the logic of skipping rendering
This commit is contained in:
parent
59295cc85f
commit
38f802cb40
@ -53,7 +53,7 @@ type context struct {
|
|||||||
offscreenWidth float64
|
offscreenWidth float64
|
||||||
offscreenHeight float64
|
offscreenHeight float64
|
||||||
|
|
||||||
isOffscreenDirty bool
|
isOffscreenModified bool
|
||||||
|
|
||||||
skipCount int
|
skipCount int
|
||||||
}
|
}
|
||||||
@ -157,6 +157,9 @@ func (c *context) drawGame(graphicsDriver graphicsdriver.Graphics, forceDraw boo
|
|||||||
c.offscreen = c.game.NewOffscreenImage(w, h)
|
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.
|
// 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
|
// 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.
|
// 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()
|
c.offscreen.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
// isOffscreenDirty is updated when an offscreen's drawCallback.
|
|
||||||
c.isOffscreenDirty = false
|
|
||||||
if err := c.game.DrawOffscreen(); err != nil {
|
if err := c.game.DrawOffscreen(); err != nil {
|
||||||
return err
|
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).
|
// 180 might be too big but this is a enough value to consider exiting from fullscreen on macOS (#2500).
|
||||||
const maxSkipCount = 180
|
const maxSkipCount = 180
|
||||||
|
|
||||||
if !forceDraw && !theGlobalState.isScreenClearedEveryFrame() && !c.isOffscreenDirty {
|
if !forceDraw && !c.isOffscreenModified {
|
||||||
if c.skipCount < maxSkipCount {
|
if c.skipCount < maxSkipCount {
|
||||||
c.skipCount++
|
c.skipCount++
|
||||||
}
|
}
|
||||||
@ -232,8 +233,8 @@ func (c *context) layoutGame(outsideWidth, outsideHeight float64, deviceScaleFac
|
|||||||
}
|
}
|
||||||
if c.offscreen == nil {
|
if c.offscreen == nil {
|
||||||
c.offscreen = c.game.NewOffscreenImage(ow, oh)
|
c.offscreen = c.game.NewOffscreenImage(ow, oh)
|
||||||
c.offscreen.drawCallback = func() {
|
c.offscreen.modifyCallback = func() {
|
||||||
c.isOffscreenDirty = true
|
c.isOffscreenModified = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,9 +46,9 @@ type Image struct {
|
|||||||
bigOffscreenBufferBlend graphicsdriver.Blend
|
bigOffscreenBufferBlend graphicsdriver.Blend
|
||||||
bigOffscreenBufferDirty bool
|
bigOffscreenBufferDirty bool
|
||||||
|
|
||||||
// drawCallback is a callback called when DrawTriangles or WritePixels is called.
|
// modifyCallback 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.
|
// modifyCallback is useful to detect whether the image is manipulated or not after a certain time.
|
||||||
drawCallback func()
|
modifyCallback func()
|
||||||
|
|
||||||
// These temporary vertices must not be reused until the vertices are sent to the graphics command queue.
|
// 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.MarkDisposed()
|
||||||
i.mipmap = nil
|
i.mipmap = nil
|
||||||
i.dotsBuffer = 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) {
|
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 {
|
if i.modifyCallback != nil {
|
||||||
i.drawCallback()
|
i.modifyCallback()
|
||||||
}
|
}
|
||||||
|
|
||||||
if antialias {
|
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) {
|
func (i *Image) WritePixels(pix []byte, x, y, width, height int) {
|
||||||
if i.drawCallback != nil {
|
if i.modifyCallback != nil {
|
||||||
i.drawCallback()
|
i.modifyCallback()
|
||||||
}
|
}
|
||||||
|
|
||||||
if width == 1 && height == 1 {
|
if width == 1 && height == 1 {
|
||||||
|
Loading…
Reference in New Issue
Block a user