mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/graphicsdriver/directx: defer the initialization
This commit is contained in:
parent
b4491ab94d
commit
59798d29f4
@ -20,6 +20,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
@ -32,18 +33,24 @@ import (
|
|||||||
|
|
||||||
const frameCount = 2
|
const frameCount = 2
|
||||||
|
|
||||||
const is64bit = uint64(^uintptr(0)) == ^uint64(0)
|
|
||||||
|
|
||||||
// isDirectXAvailable indicates whether DirectX is available or not.
|
// isDirectXAvailable indicates whether DirectX is available or not.
|
||||||
// In 32bit machines, DirectX is not used because
|
var (
|
||||||
// 1) The functions syscall.Syscall cannot accept 64bit values as one argument
|
isDirectXAvailable bool
|
||||||
// 2) The struct layouts can be different
|
isDirectXAvailableOnce sync.Once
|
||||||
// TODO: Support DirectX for 32bit machines (#2088).
|
)
|
||||||
var isDirectXAvailable = is64bit && theGraphics.initializeDevice() == nil
|
|
||||||
|
|
||||||
var theGraphics Graphics
|
var theGraphics Graphics
|
||||||
|
|
||||||
func Get() *Graphics {
|
func Get() *Graphics {
|
||||||
|
isDirectXAvailableOnce.Do(func() {
|
||||||
|
const is64bit = uint64(^uintptr(0)) == ^uint64(0)
|
||||||
|
|
||||||
|
// In 32bit machines, DirectX is not used because
|
||||||
|
// 1) The functions syscall.Syscall cannot accept 64bit values as one argument
|
||||||
|
// 2) The struct layouts can be different
|
||||||
|
// TODO: Support DirectX for 32bit machines (#2088).
|
||||||
|
isDirectXAvailable = is64bit && theGraphics.initializeDevice() == nil
|
||||||
|
})
|
||||||
if !isDirectXAvailable {
|
if !isDirectXAvailable {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user