graphics_darwin.go (1767B)
1 // Copyright 2018 The Ebiten Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build !ebitengl 16 17 package glfw 18 19 // #cgo CFLAGS: -x objective-c 20 // #cgo LDFLAGS: -framework Foundation 21 // 22 // #import <Foundation/Foundation.h> 23 // 24 // static int getMacOSMinorVersion() { 25 // NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; 26 // return (int)version.minorVersion; 27 // } 28 import "C" 29 30 import ( 31 "github.com/hajimehoshi/ebiten/v2/internal/driver" 32 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal" 33 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl" 34 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl" 35 ) 36 37 var graphics driver.Graphics 38 39 func supportsMetal() bool { 40 // On old mac devices like iMac 2011, Metal is not supported (#779). 41 if _, err := mtl.CreateSystemDefaultDevice(); err != nil { 42 return false 43 } 44 // On macOS 10.11 El Capitan, there is a rendering issue on Metal (#781). 45 // Use the OpenGL in macOS 10.11 or older. 46 if C.getMacOSMinorVersion() <= 11 { 47 return false 48 } 49 return true 50 } 51 52 func init() { 53 if supportsMetal() { 54 graphics = metal.Get() 55 return 56 } 57 graphics = opengl.Get() 58 } 59 60 func (*UserInterface) Graphics() driver.Graphics { 61 return graphics 62 }