mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
uidriver/glfw: Refactoring
This commit is contained in:
parent
c1adf60e69
commit
e797aed6c9
@ -29,40 +29,35 @@ package glfw
|
|||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var graphics driver.Graphics
|
||||||
// isMetalSupported represents whether Metal is supported.
|
|
||||||
isMetalSupported = true
|
|
||||||
|
|
||||||
// isMetalSupportedOnce initializes isMetalSupported.
|
func supportsMetal() bool {
|
||||||
//
|
// On old mac devices like iMac 2011, Metal is not supported (#779).
|
||||||
// Use sync.Once instead of init function to avoid init-order dependency (#886).
|
if _, err := mtl.CreateSystemDefaultDevice(); err != nil {
|
||||||
isMetalSupportedOnce sync.Once
|
return 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.getMacOSMinorVersion() <= 11 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if supportsMetal() {
|
||||||
|
graphics = metal.Get()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
graphics = opengl.Get()
|
||||||
|
}
|
||||||
|
|
||||||
func (*UserInterface) Graphics() driver.Graphics {
|
func (*UserInterface) Graphics() driver.Graphics {
|
||||||
isMetalSupportedOnce.Do(func() {
|
return graphics
|
||||||
// On old mac devices like iMac 2011, Metal is not supported (#779).
|
|
||||||
if _, err := mtl.CreateSystemDefaultDevice(); err != nil {
|
|
||||||
isMetalSupported = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 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.getMacOSMinorVersion() <= 11 {
|
|
||||||
isMetalSupported = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
})
|
|
||||||
if isMetalSupported {
|
|
||||||
return metal.Get()
|
|
||||||
}
|
|
||||||
return opengl.Get()
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user