internal/glfwwin: create a pseudo monitor for Xbox

Updates #1162
This commit is contained in:
Hajime Hoshi 2022-05-29 15:38:13 +09:00
parent f8163f93c0
commit 05d49c5a52
3 changed files with 38 additions and 3 deletions

View File

@ -44,3 +44,18 @@ func isXbox() bool {
t := C.XSystemGetDeviceType()
return t != _XSystemDeviceType_Unknown && t != _XSystemDeviceType_Pc
}
func monitorResolution() (int, int) {
switch C.XSystemGetDeviceType() {
case _XSystemDeviceType_XboxOne, _XSystemDeviceType_XboxOneS:
return 1920, 1080
case _XSystemDeviceType_XboxScarlettLockhart:
// Series S
return 2560, 1440
case _XSystemDeviceType_XboxOneX, _XSystemDeviceType_XboxOneXDevkit, _XSystemDeviceType_XboxScarlettAnaconda, _XSystemDeviceType_XboxScarlettDevkit:
// Series X
return 3840, 2160
default:
return 1920, 1080
}
}

View File

@ -20,3 +20,7 @@ package glfwwin
func isXbox() bool {
return false
}
func monitorResolution() (int, int) {
panic("glfwwin: monitorResolution is not implemented in this environment")
}

View File

@ -259,9 +259,25 @@ func platformInit() error {
return err
}
if isXbox() {
// TODO: Create a dummy window.
// The resolution can be deterined based on a device.
// See https://github.com/microsoft/Xbox-GDK-Samples/blob/1f44bdabed6e340170e2c7d1007500e4dff897bb/Samples/IntroGraphics/SimpleDynamicResources/Main.cpp#L118-L148
// On Xbox, APIs to get monitors are not available.
// Create a pseudo monitor instance instead.
w, h := monitorResolution()
mode := &VidMode{
Width: w,
Height: h,
RedBits: 8,
GreenBits: 8,
BlueBits: 8,
RefreshRate: 0, // TODO: Is it possible to get an appropriate refresh rate?
}
m := &Monitor{
name: "Xbox Monitor",
modes: []*VidMode{mode},
currentMode: mode,
}
if err := inputMonitor(m, Connected, _GLFW_INSERT_LAST); err != nil {
return err
}
} else {
if err := pollMonitorsWin32(); err != nil {
return err