graphicsdriver/metal: Bug fix: Reading pixels from GPU causes blinking

Metal's Drawable should be obtained only when needed, or reading
pixels from GPU causes the blinking screen.

Fixes #865
This commit is contained in:
Hajime Hoshi 2019-05-11 23:50:38 +09:00
parent 8f62a510ab
commit de341ca9ac

View File

@ -316,14 +316,6 @@ func (d *Driver) Begin() {
// NSAutoreleasePool is required to release drawable correctly (#847).
// https://developer.apple.com/library/archive/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide/Drawables.html
d.pool = C.allocAutoreleasePool()
drawable, err := d.ml.NextDrawable()
if err != nil {
// Drawable is nil. This can happen at the initial state. Let's wait and see.
return nil
}
d.screenDrawable = drawable
return nil
})
}
@ -631,6 +623,14 @@ func (d *Driver) Draw(indexLen int, indexOffset int, mode graphics.CompositeMode
}
var t mtl.Texture
if d.dst.screen {
if d.screenDrawable == (ca.MetalDrawable{}) {
drawable, err := d.ml.NextDrawable()
if err != nil {
// Drawable is nil. This can happen at the initial state. Let's wait and see.
return nil
}
d.screenDrawable = drawable
}
t = d.screenDrawable.Texture()
} else {
t = d.dst.texture