internal/graphicsdriver/opengl/gl: always prefer OpenGL ES to OpenGL

Closes #2944
This commit is contained in:
Hajime Hoshi 2024-08-10 01:21:35 +09:00
parent 1a0f50503d
commit a5235eea86
2 changed files with 15 additions and 38 deletions

5
doc.go
View File

@ -93,11 +93,6 @@
// The option "featurelevel" is valid only for DirectX 12. // The option "featurelevel" is valid only for DirectX 12.
// The possible values are "11_0", "11_1", "12_0", "12_1", and "12_2". The default value is "11_0". // The possible values are "11_0", "11_1", "12_0", "12_1", and "12_2". The default value is "11_0".
// //
// `EBITENGINE_OPENGL` environment variable specifies various parameters for OpenGL.
// You can specify multiple values separated by a comma. The default value is empty (i.e. no parameters).
//
// "es": Use OpenGL ES. Without this, OpenGL and OpenGL ES are automatically chosen.
//
// # Build tags // # Build tags
// //
// `ebitenginedebug` outputs a log of graphics commands. This is useful to know what happens in Ebitengine. In general, the // `ebitenginedebug` outputs a log of graphics commands. This is useful to know what happens in Ebitengine. In general, the

View File

@ -18,8 +18,6 @@ package gl
import ( import (
"fmt" "fmt"
"os"
"runtime"
"strings" "strings"
"github.com/ebitengine/purego" "github.com/ebitengine/purego"
@ -31,25 +29,21 @@ var (
) )
func (c *defaultContext) init() error { func (c *defaultContext) init() error {
var preferES bool
if runtime.GOOS == "android" {
preferES = true
}
if !preferES {
for _, t := range strings.Split(os.Getenv("EBITENGINE_OPENGL"), ",") {
switch strings.TrimSpace(t) {
case "es":
preferES = true
break
}
}
}
// TODO: Use multiple %w-s as of Go 1.20. // TODO: Use multiple %w-s as of Go 1.20.
var errors []string var errors []string
// Try OpenGL first. OpenGL is preferable as this doesn't cause context losses. // Try OpenGL ES first. Some machines like Android and Raspberry Pi might work only with OpenGL ES.
if !preferES { for _, name := range []string{"libGLESv2.so", "libGLESv2.so.2", "libGLESv2.so.1", "libGLESv2.so.0"} {
lib, err := purego.Dlopen(name, purego.RTLD_LAZY|purego.RTLD_GLOBAL)
if err == nil {
libGLES = lib
c.isES = true
return nil
}
errors = append(errors, fmt.Sprintf("%s: %v", name, err))
}
// Try OpenGL next.
// Usually libGL.so or libGL.so.1 is used. libGL.so.2 might exist only on NetBSD. // Usually libGL.so or libGL.so.1 is used. libGL.so.2 might exist only on NetBSD.
// TODO: Should "libOpenGL.so.0" [1] and "libGLX.so.0" [2] be added? These were added as of GLFW 3.3.9. // TODO: Should "libOpenGL.so.0" [1] and "libGLX.so.0" [2] be added? These were added as of GLFW 3.3.9.
// [1] https://github.com/glfw/glfw/commit/55aad3c37b67f17279378db52da0a3ab81bbf26d // [1] https://github.com/glfw/glfw/commit/55aad3c37b67f17279378db52da0a3ab81bbf26d
@ -62,18 +56,6 @@ func (c *defaultContext) init() error {
} }
errors = append(errors, fmt.Sprintf("%s: %v", name, err)) errors = append(errors, fmt.Sprintf("%s: %v", name, err))
} }
}
// Try OpenGL ES.
for _, name := range []string{"libGLESv2.so", "libGLESv2.so.2", "libGLESv2.so.1", "libGLESv2.so.0"} {
lib, err := purego.Dlopen(name, purego.RTLD_LAZY|purego.RTLD_GLOBAL)
if err == nil {
libGLES = lib
c.isES = true
return nil
}
errors = append(errors, fmt.Sprintf("%s: %v", name, err))
}
return fmt.Errorf("gl: failed to load libGL.so and libGLESv2.so: %s", strings.Join(errors, ", ")) return fmt.Errorf("gl: failed to load libGL.so and libGLESv2.so: %s", strings.Join(errors, ", "))
} }