Skip to content

Commit

Permalink
internal/graphicsdriver/opengl/gl: bug fix: check ES 3.0 availability
Browse files Browse the repository at this point in the history
Updates #3152
  • Loading branch information
hajimehoshi committed Nov 4, 2024
1 parent 1014e45 commit c287e7b
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions internal/graphicsdriver/opengl/gl/procaddr_linbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
package gl

import (
"bufio"
"bytes"
"errors"
"fmt"
"os/exec"
"regexp"
"strconv"

"github.com/ebitengine/purego"
)
Expand All @@ -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.
Expand Down

0 comments on commit c287e7b

Please sign in to comment.