mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
internal/graphicsdriver/opengl/gl: use C version for Android
Unfortunately PureGo's dlopen didn't work on some Android devices. Use the Cgo version instead in the same way as v2.7. Closes #3052
This commit is contained in:
parent
856b339298
commit
297efea68b
@ -2,7 +2,7 @@
|
|||||||
// SPDX-FileCopyrightText: 2014 Eric Woroshow
|
// SPDX-FileCopyrightText: 2014 Eric Woroshow
|
||||||
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
|
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
|
||||||
|
|
||||||
//go:build nintendosdk
|
//go:build android || nintendosdk
|
||||||
|
|
||||||
package gl
|
package gl
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//go:build (darwin || freebsd || linux || netbsd || openbsd || windows) && !nintendosdk && !playstation5
|
//go:build (darwin || freebsd || (linux && !android) || netbsd || openbsd || windows) && !nintendosdk && !playstation5
|
||||||
|
|
||||||
package gl
|
package gl
|
||||||
|
|
||||||
|
67
internal/graphicsdriver/opengl/gl/procaddr_android.go
Normal file
67
internal/graphicsdriver/opengl/gl/procaddr_android.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright 2024 The Ebitengine Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package gl
|
||||||
|
|
||||||
|
// Unfortunately, PureGo's dlopen didn't work well on some Android devices (#3052).
|
||||||
|
// Use Cgo instead until PureGo is fixed.
|
||||||
|
|
||||||
|
// #include <dlfcn.h>
|
||||||
|
// #include <stdlib.h>
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
libGLES unsafe.Pointer
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *defaultContext) init() error {
|
||||||
|
// TODO: Use multiple %w-s as of Go 1.20.
|
||||||
|
var errors []string
|
||||||
|
|
||||||
|
// Try OpenGL ES.
|
||||||
|
for _, name := range []string{"libGLESv2.so", "libGLESv2.so.2", "libGLESv2.so.1", "libGLESv2.so.0"} {
|
||||||
|
cname := C.CString(name)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
lib := C.dlopen(cname, C.RTLD_LAZY|C.RTLD_GLOBAL)
|
||||||
|
if lib != nil {
|
||||||
|
libGLES = lib
|
||||||
|
c.isES = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if cerr := C.dlerror(); cerr != nil {
|
||||||
|
errors = append(errors, fmt.Sprintf("%s: %v", name, C.GoString(cerr)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("gl: failed to load libGLESv2.so: %s", strings.Join(errors, ", "))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *defaultContext) getProcAddress(name string) (uintptr, error) {
|
||||||
|
cname := C.CString(name)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
addr := C.dlsym(libGLES, cname)
|
||||||
|
if addr == nil {
|
||||||
|
if cerr := C.dlerror(); cerr != nil {
|
||||||
|
return 0, fmt.Errorf("gl: failed to load %s: %v", name, C.GoString(cerr))
|
||||||
|
}
|
||||||
|
return 0, fmt.Errorf("gl: failed to load %s", name)
|
||||||
|
}
|
||||||
|
return uintptr(addr), nil
|
||||||
|
}
|
@ -12,14 +12,13 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
//go:build (freebsd || linux || netbsd || openbsd) && !nintendosdk && !playstation5
|
//go:build (freebsd || (linux && !android) || netbsd || openbsd) && !nintendosdk && !playstation5
|
||||||
|
|
||||||
package gl
|
package gl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ebitengine/purego"
|
"github.com/ebitengine/purego"
|
||||||
@ -32,16 +31,11 @@ var (
|
|||||||
|
|
||||||
func (c *defaultContext) init() error {
|
func (c *defaultContext) init() error {
|
||||||
var preferES bool
|
var preferES bool
|
||||||
if runtime.GOOS == "android" {
|
for _, t := range strings.Split(os.Getenv("EBITENGINE_OPENGL"), ",") {
|
||||||
preferES = true
|
switch strings.TrimSpace(t) {
|
||||||
}
|
case "es":
|
||||||
if !preferES {
|
preferES = true
|
||||||
for _, t := range strings.Split(os.Getenv("EBITENGINE_OPENGL"), ",") {
|
break
|
||||||
switch strings.TrimSpace(t) {
|
|
||||||
case "es":
|
|
||||||
preferES = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user