Skip to content

Commit

Permalink
graphicsdriver/metal: Bug fix: Reading pixels from GPU causes blinking
Browse files Browse the repository at this point in the history
Metal's Drawable should be obtained only when needed, or reading
pixels from GPU causes the blinking screen.

Fixes #865
  • Loading branch information
hajimehoshi committed May 11, 2019
1 parent 8f62a51 commit de341ca
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/graphicsdriver/metal/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit de341ca

Please # to comment.