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) SetVsyncEnabled(enabled bool)
FramebufferYDirection() YDirection FramebufferYDirection() YDirection
NeedsRestoring() bool NeedsRestoring() bool
NeedsClearingScreen() bool
IsGL() bool IsGL() bool
HasHighPrecisionFloat() bool HasHighPrecisionFloat() bool
MaxImageSize() int MaxImageSize() int

View File

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

View File

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

View File

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