mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-03 22:44:28 +01:00
internal/graphicsdriver/metal: refactoring: initialize the driver at Get
This commit is contained in:
parent
7b8ae76f26
commit
195b060911
@ -19,6 +19,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
@ -346,28 +347,31 @@ const (
|
|||||||
noStencil
|
noStencil
|
||||||
)
|
)
|
||||||
|
|
||||||
// isMetalAvailable reports whether Metal is available or not.
|
var (
|
||||||
var isMetalAvailable bool
|
// isMetalAvailable reports whether Metal is available or not.
|
||||||
|
isMetalAvailable bool
|
||||||
func init() {
|
isMetalAvailableOnce sync.Once
|
||||||
if !supportsMetal() {
|
)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize isMetalAvailable on the main thread.
|
|
||||||
// On old mac devices like iMac 2011, Metal is not supported (#779).
|
|
||||||
// TODO: Is there a better way to check whether Metal is available or not?
|
|
||||||
// It seems OK to call MTLCreateSystemDefaultDevice multiple times, so this should be fine.
|
|
||||||
if _, ok := mtl.CreateSystemDefaultDevice(); !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isMetalAvailable = true
|
|
||||||
}
|
|
||||||
|
|
||||||
var theGraphics Graphics
|
var theGraphics Graphics
|
||||||
|
|
||||||
func Get() *Graphics {
|
func Get() *Graphics {
|
||||||
|
isMetalAvailableOnce.Do(func() {
|
||||||
|
if !supportsMetal() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize isMetalAvailable on the main thread.
|
||||||
|
// TODO: Now ui.chooseGraphicsDriver is called on the main thread. Add an assertion.
|
||||||
|
|
||||||
|
// On old mac devices like iMac 2011, Metal is not supported (#779).
|
||||||
|
// TODO: Is there a better way to check whether Metal is available or not?
|
||||||
|
// It seems OK to call MTLCreateSystemDefaultDevice multiple times, so this should be fine.
|
||||||
|
if _, ok := mtl.CreateSystemDefaultDevice(); !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isMetalAvailable = true
|
||||||
|
})
|
||||||
if !isMetalAvailable {
|
if !isMetalAvailable {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user