internal/graphicsdriver/metal: Skip clearing the screen on Metal

This commit is contained in:
Hajime Hoshi 2021-07-07 01:43:32 +09:00
parent 9cb1ff9cea
commit 38ce325958
4 changed files with 18 additions and 3 deletions

View File

@ -45,6 +45,7 @@ type Graphics interface {
SetVsyncEnabled(enabled bool)
FramebufferYDirection() YDirection
NeedsRestoring() bool
NeedsClearingScreen() bool
IsGL() bool
HasHighPrecisionFloat() bool
MaxImageSize() int

View File

@ -794,7 +794,11 @@ func (g *Graphics) draw(rps mtl.RenderPipelineState, dst *Image, dstRegion drive
rpd := mtl.RenderPassDescriptor{}
// Even though the destination pixels are not used, mtl.LoadActionDontCare might cause glitches
// (#1019). Always using mtl.LoadActionLoad is safe.
rpd.ColorAttachments[0].LoadAction = mtl.LoadActionLoad
if dst.screen {
rpd.ColorAttachments[0].LoadAction = mtl.LoadActionClear
} else {
rpd.ColorAttachments[0].LoadAction = mtl.LoadActionLoad
}
rpd.ColorAttachments[0].StoreAction = mtl.StoreActionStore
t := dst.mtlTexture()
@ -1015,6 +1019,10 @@ func (g *Graphics) NeedsRestoring() bool {
return false
}
func (g *Graphics) NeedsClearingScreen() bool {
return false
}
func (g *Graphics) IsGL() bool {
return false
}

View File

@ -337,6 +337,10 @@ func (g *Graphics) NeedsRestoring() bool {
return g.context.needsRestoring()
}
func (g *Graphics) NeedsClearingScreen() bool {
return true
}
func (g *Graphics) IsGL() bool {
return true
}

View File

@ -205,8 +205,10 @@ func (c *uiContext) updateImpl(updateCount int) error {
}
c.game.Draw(c.offscreen)
// This clear is needed for fullscreen mode or some mobile platforms (#622).
c.screen.Clear()
if uiDriver().Graphics().NeedsClearingScreen() {
// This clear is needed for fullscreen mode or some mobile platforms (#622).
c.screen.Clear()
}
op := &DrawImageOptions{}