From de341ca9ac939ada6e7c74925e6a56318f1eb5f5 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 11 May 2019 23:50:38 +0900 Subject: [PATCH] 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 --- internal/graphicsdriver/metal/driver.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/graphicsdriver/metal/driver.go b/internal/graphicsdriver/metal/driver.go index 0c1e41f2c..363d6581f 100644 --- a/internal/graphicsdriver/metal/driver.go +++ b/internal/graphicsdriver/metal/driver.go @@ -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