From dc0c6e0907402c424edb00689f8536e94d2db26d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 12 Jan 2019 01:29:20 +0900 Subject: [PATCH] graphicscommand: Use GL on macOS 10.11 or older (#781) --- internal/graphicscommand/driver_mac.go | 28 ++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/graphicscommand/driver_mac.go b/internal/graphicscommand/driver_mac.go index 21e96c716..c824b7ea2 100644 --- a/internal/graphicscommand/driver_mac.go +++ b/internal/graphicscommand/driver_mac.go @@ -17,6 +17,17 @@ package graphicscommand +// #cgo CFLAGS: -x objective-c +// #cgo LDFLAGS: -framework Foundation +// +// #import +// +// static int getDarwinMinorVersion() { +// NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; +// return (int)version.minorVersion; +// } +import "C" + import ( "github.com/hajimehoshi/ebiten/internal/graphicsdriver" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal" @@ -24,19 +35,28 @@ import ( "github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl" ) -// isMetalSupported represents whether Metal is supported. -var isMetalSupported = true +var ( + // isMetalSupported represents whether Metal is supported. + isMetalSupported = true + + darwinMajorVersion = 0 +) func init() { + // On old mac devices like iMac 2011, Metal is not supported (#779). if _, err := mtl.CreateSystemDefaultDevice(); err != nil { isMetalSupported = false } + // On macOS 10.11 El Capitan, there is a rendering issue on Metal (#781). + // Use the OpenGL in macOS 10.11 or older. + if C.getDarwinMinorVersion() <= 11 { + isMetalSupported = false + } } func Driver() graphicsdriver.GraphicsDriver { if isMetalSupported { return metal.Get() - } else { - return opengl.Get() } + return opengl.Get() }