internal/graphicsdriver/directx: use OpenGL as the default on old Windows

On old machines, CreateSwapChain might fail without a specific reasons.
Probably this is due to an issue in drivers, and if so, there is nothing
we can do. When choosing a graphics library, prefer OpenGL on such old
machines.

Updates #2613
This commit is contained in:
Hajime Hoshi 2023-03-31 02:21:08 +09:00
parent 182ac21866
commit 370b7599bc

View File

@ -29,6 +29,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/directx"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
"github.com/hajimehoshi/ebiten/v2/internal/microsoftgdk"
"github.com/hajimehoshi/ebiten/v2/internal/winver"
)
type graphicsDriverCreatorImpl struct {
@ -36,15 +37,23 @@ type graphicsDriverCreatorImpl struct {
}
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
d, err1 := g.newDirectX()
if err1 == nil {
return d, GraphicsLibraryDirectX, nil
// Creating a swap chain on an older machines than Windows 10 might fail (#2613).
var dxErr error
if winver.IsWindows10OrGreater() {
d, err := g.newDirectX()
if err == nil {
return d, GraphicsLibraryDirectX, nil
}
dxErr = err
}
o, err2 := g.newOpenGL()
if err2 == nil {
o, err := g.newOpenGL()
if err == nil {
return o, GraphicsLibraryOpenGL, nil
}
return nil, GraphicsLibraryUnknown, fmt.Errorf("ui: failed to choose graphics drivers: DirectX: %v, OpenGL: %v", err1, err2)
glErr := err
return nil, GraphicsLibraryUnknown, fmt.Errorf("ui: failed to choose graphics drivers: DirectX: %v, OpenGL: %v", dxErr, glErr)
}
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {