mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/graphicsdriver/metal: refactoring
This commit is contained in:
parent
5f59807284
commit
1c57393393
@ -349,14 +349,10 @@ const (
|
|||||||
// isMetalAvailable reports whether Metal is available or not.
|
// isMetalAvailable reports whether Metal is available or not.
|
||||||
//
|
//
|
||||||
// On old mac devices like iMac 2011, Metal is not supported (#779).
|
// On old mac devices like iMac 2011, Metal is not supported (#779).
|
||||||
var isMetalAvailable bool
|
//
|
||||||
|
// initializeView calls mtl.CreateSystemDefualtDevice, which works only when Metal is available.
|
||||||
func init() {
|
// If there is a better way, this should be adopted.
|
||||||
// Initialize isMetalAvailable on the main thread.
|
var isMetalAvailable = theGraphics.initializeView() == nil
|
||||||
// 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.
|
|
||||||
_, isMetalAvailable = mtl.CreateSystemDefaultDevice()
|
|
||||||
}
|
|
||||||
|
|
||||||
var theGraphics Graphics
|
var theGraphics Graphics
|
||||||
|
|
||||||
@ -595,6 +591,10 @@ func operationToBlendFactor(c graphicsdriver.Operation) mtl.BlendFactor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) initializeView() error {
|
||||||
|
return g.view.initialize()
|
||||||
|
}
|
||||||
|
|
||||||
func (g *Graphics) Initialize() error {
|
func (g *Graphics) Initialize() error {
|
||||||
// Creating *State objects are expensive and reuse them whenever possible.
|
// Creating *State objects are expensive and reuse them whenever possible.
|
||||||
// See https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Cmd-Submiss/Cmd-Submiss.html
|
// See https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Cmd-Submiss/Cmd-Submiss.html
|
||||||
@ -611,9 +611,6 @@ func (g *Graphics) Initialize() error {
|
|||||||
g.dsss = map[stencilMode]mtl.DepthStencilState{}
|
g.dsss = map[stencilMode]mtl.DepthStencilState{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := g.view.initialize(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if g.transparent {
|
if g.transparent {
|
||||||
g.view.ml.SetOpaque(false)
|
g.view.ml.SetOpaque(false)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user