internal/ui: use DirectX as a fallback for old Windows

Initializing OpenGL can fail [1], though this is pretty rare. For such
this case, try DirectX as a fallback.

[1] https://answers.microsoft.com/en-us/windows/forum/all/my-drivers-dont-support-opengl/a1ee0267-4dc8-4385-a185-6ed322d78329

Updates #2613
This commit is contained in:
Hajime Hoshi 2023-03-31 03:15:49 +09:00
parent 370b7599bc
commit 1999f8a024

View File

@ -37,21 +37,36 @@ type graphicsDriverCreatorImpl struct {
}
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
// Creating a swap chain on an older machines than Windows 10 might fail (#2613).
var dxErr error
var glErr error
if winver.IsWindows10OrGreater() {
d, err := g.newDirectX()
if err == nil {
return d, GraphicsLibraryDirectX, nil
}
dxErr = err
}
o, err := g.newOpenGL()
if err == nil {
return o, GraphicsLibraryOpenGL, nil
o, err := g.newOpenGL()
if err == nil {
return o, GraphicsLibraryOpenGL, nil
}
glErr = err
} else {
// Creating a swap chain on an older machines than Windows 10 might fail (#2613).
// Prefer OpenGL to DirectX.
o, err := g.newOpenGL()
if err == nil {
return o, GraphicsLibraryOpenGL, nil
}
glErr = err
// Initializing OpenGL can fail, though this is pretty rare.
d, err := g.newDirectX()
if err == nil {
return d, GraphicsLibraryDirectX, nil
}
dxErr = err
}
glErr := err
return nil, GraphicsLibraryUnknown, fmt.Errorf("ui: failed to choose graphics drivers: DirectX: %v, OpenGL: %v", dxErr, glErr)
}