graphics_darwin.go (2003B)
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 //go:build !ebitengl 16 // +build !ebitengl 17 18 package glfw 19 20 // #cgo CFLAGS: -x objective-c 21 // #cgo LDFLAGS: -framework Foundation 22 // 23 // #import <Foundation/Foundation.h> 24 // 25 // static int getMacOSMajorVersion() { 26 // NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; 27 // return (int)version.majorVersion; 28 // } 29 // 30 // static int getMacOSMinorVersion() { 31 // NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; 32 // return (int)version.minorVersion; 33 // } 34 import "C" 35 36 import ( 37 "github.com/hajimehoshi/ebiten/v2/internal/driver" 38 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal" 39 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl" 40 "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl" 41 ) 42 43 var graphics driver.Graphics 44 45 func supportsMetal() bool { 46 // On old mac devices like iMac 2011, Metal is not supported (#779). 47 if _, err := mtl.CreateSystemDefaultDevice(); err != nil { 48 return false 49 } 50 51 // On macOS 10.11 El Capitan, there is a rendering issue on Metal (#781). 52 // Use the OpenGL in macOS 10.11 or older. 53 if C.getMacOSMajorVersion() <= 10 && C.getMacOSMinorVersion() <= 11 { 54 return false 55 } 56 return true 57 } 58 59 func init() { 60 if supportsMetal() { 61 graphics = metal.Get() 62 return 63 } 64 graphics = opengl.Get() 65 } 66 67 func (*UserInterface) Graphics() driver.Graphics { 68 return graphics 69 }