diff --git a/internal/graphicsdriver/opengl/gl/procaddr_linbsd.go b/internal/graphicsdriver/opengl/gl/procaddr_linbsd.go index 794c9057ef4b..842d80ae60cd 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr_linbsd.go +++ b/internal/graphicsdriver/opengl/gl/procaddr_linbsd.go @@ -17,8 +17,13 @@ package gl import ( + "bufio" + "bytes" "errors" "fmt" + "os/exec" + "regexp" + "strconv" "github.com/ebitengine/purego" ) @@ -28,18 +33,41 @@ var ( libGLES uintptr ) +func isES30Available() bool { + var buf bytes.Buffer + cmd := exec.Command("glxinfo") + cmd.Stdout = &buf + if err := cmd.Run(); err != nil { + return false + } + + re := regexp.MustCompile(`^OpenGL ES profile version string: OpenGL ES (\d+)\.\d+`) + s := bufio.NewScanner(&buf) + for s.Scan() { + m := re.FindStringSubmatch(s.Text()) + if m == nil { + continue + } + major, _ := strconv.Atoi(m[1]) + return major >= 3 + } + return false +} + func (c *defaultContext) init() error { var errs []error - // Try OpenGL ES first. Some machines like Android and Raspberry Pi might work only with 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 + if isES30Available() { + // Try OpenGL ES first. Some machines like Android and Raspberry Pi might work only with 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 + } + errs = append(errs, fmt.Errorf("gl: Dlopen failed: name: %s: %w", name, err)) } - errs = append(errs, fmt.Errorf("gl: Dlopen failed: name: %s: %w", name, err)) } // Try OpenGL next.