mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
internal/graphicsdriver/gl: use PureGo for Linux and UNIX
Updates #2284
This commit is contained in:
parent
f34932151d
commit
59fb259181
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
|||||||
github.com/ebitengine/gomobile v0.0.0-20240429094902-cf88669c3591
|
github.com/ebitengine/gomobile v0.0.0-20240429094902-cf88669c3591
|
||||||
github.com/ebitengine/hideconsole v1.0.0
|
github.com/ebitengine/hideconsole v1.0.0
|
||||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1
|
github.com/ebitengine/oto/v3 v3.3.0-alpha.1
|
||||||
github.com/ebitengine/purego v0.8.0-alpha.1
|
github.com/ebitengine/purego v0.8.0-alpha.1.0.20240429114929-1ff8716e2490
|
||||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f
|
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f
|
||||||
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703
|
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703
|
||||||
github.com/hajimehoshi/bitmapfont/v3 v3.1.0
|
github.com/hajimehoshi/bitmapfont/v3 v3.1.0
|
||||||
|
4
go.sum
4
go.sum
@ -4,8 +4,8 @@ github.com/ebitengine/hideconsole v1.0.0 h1:5J4U0kXF+pv/DhiXt5/lTz0eO5ogJ1iXb8Yj
|
|||||||
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
|
github.com/ebitengine/hideconsole v1.0.0/go.mod h1:hTTBTvVYWKBuxPr7peweneWdkUwEuHuB3C1R/ielR1A=
|
||||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk=
|
github.com/ebitengine/oto/v3 v3.3.0-alpha.1 h1:J2nBmQwPLKc4+yLObytq1jKNydI96l6EjZfgefiqGbk=
|
||||||
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg=
|
github.com/ebitengine/oto/v3 v3.3.0-alpha.1/go.mod h1:T2/VV0UWG97GEEf4kORMU2nCneYT/YmwSTxPutSVaUg=
|
||||||
github.com/ebitengine/purego v0.8.0-alpha.1 h1:52AgJTNaQRi7YtOtdJl4hkxNWhAGMxuDuDjOVIp5Ojk=
|
github.com/ebitengine/purego v0.8.0-alpha.1.0.20240429114929-1ff8716e2490 h1:hOHVTszt219H/6Ma0o/RvZ++BPJtj2PMie+3fyA+sTs=
|
||||||
github.com/ebitengine/purego v0.8.0-alpha.1/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM=
|
github.com/ebitengine/purego v0.8.0-alpha.1.0.20240429114929-1ff8716e2490/go.mod h1:y8L+ZRLphbdPW2xs41fur/KaW57yTzrFsqsclHyHrTM=
|
||||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f h1:ysqRe+lvUiL0dH5XzkH0Bz68bFMPJ4f5Si4L/HD9SGk=
|
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f h1:ysqRe+lvUiL0dH5XzkH0Bz68bFMPJ4f5Si4L/HD9SGk=
|
||||||
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRRv/IoHixuZ9bElZnXbmfoUVPGQpdsJ4sVuX38=
|
github.com/gen2brain/mpeg v0.3.2-0.20240412154320-a2ac4fc8a46f/go.mod h1:i/ebyRRv/IoHixuZ9bElZnXbmfoUVPGQpdsJ4sVuX38=
|
||||||
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog=
|
github.com/go-text/typesetting v0.1.1-0.20240402181327-ced1d6822703 h1:AqtMl9yw7r319Ah4W2afQm3Ql+PEsQKHds18tGvKhog=
|
||||||
|
@ -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 !darwin && !js && !windows && !playstation5
|
//go:build 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 || windows
|
//go:build (darwin || freebsd || linux || netbsd || openbsd || windows) && !nintendosdk && !playstation5
|
||||||
|
|
||||||
package gl
|
package gl
|
||||||
|
|
||||||
|
@ -16,38 +16,18 @@
|
|||||||
|
|
||||||
package gl
|
package gl
|
||||||
|
|
||||||
// #cgo LDFLAGS: -ldl
|
|
||||||
//
|
|
||||||
// #include <dlfcn.h>
|
|
||||||
// #include <stdlib.h>
|
|
||||||
//
|
|
||||||
// static void* getProcAddressGL(void* libGL, const char* name) {
|
|
||||||
// static void*(*glXGetProcAddress)(const char*);
|
|
||||||
// if (!glXGetProcAddress) {
|
|
||||||
// glXGetProcAddress = dlsym(libGL, "glXGetProcAddress");
|
|
||||||
// if (!glXGetProcAddress) {
|
|
||||||
// glXGetProcAddress = dlsym(libGL, "glXGetProcAddressARB");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return glXGetProcAddress(name);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// static void* getProcAddressGLES(void* libGLES, const char* name) {
|
|
||||||
// return dlsym(libGLES, name);
|
|
||||||
// }
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
|
||||||
|
"github.com/ebitengine/purego"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
libGL unsafe.Pointer
|
libGL uintptr
|
||||||
libGLES unsafe.Pointer
|
libGLES uintptr
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *defaultContext) init() error {
|
func (c *defaultContext) init() error {
|
||||||
@ -72,10 +52,8 @@ func (c *defaultContext) init() error {
|
|||||||
// [1] https://github.com/glfw/glfw/commit/55aad3c37b67f17279378db52da0a3ab81bbf26d
|
// [1] https://github.com/glfw/glfw/commit/55aad3c37b67f17279378db52da0a3ab81bbf26d
|
||||||
// [2] https://github.com/glfw/glfw/commit/c18851f52ec9704eb06464058a600845ec1eada1
|
// [2] https://github.com/glfw/glfw/commit/c18851f52ec9704eb06464058a600845ec1eada1
|
||||||
for _, name := range []string{"libGL.so", "libGL.so.2", "libGL.so.1", "libGL.so.0"} {
|
for _, name := range []string{"libGL.so", "libGL.so.2", "libGL.so.1", "libGL.so.0"} {
|
||||||
cname := C.CString(name)
|
lib, err := purego.Dlopen(name, purego.RTLD_LAZY|purego.RTLD_GLOBAL)
|
||||||
lib := C.dlopen(cname, C.RTLD_LAZY|C.RTLD_GLOBAL)
|
if err == nil {
|
||||||
C.free(unsafe.Pointer(cname))
|
|
||||||
if lib != nil {
|
|
||||||
libGL = lib
|
libGL = lib
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -84,10 +62,8 @@ func (c *defaultContext) init() error {
|
|||||||
|
|
||||||
// Try OpenGL ES.
|
// Try OpenGL ES.
|
||||||
for _, name := range []string{"libGLESv2.so", "libGLESv2.so.2", "libGLESv2.so.1", "libGLESv2.so.0"} {
|
for _, name := range []string{"libGLESv2.so", "libGLESv2.so.2", "libGLESv2.so.1", "libGLESv2.so.0"} {
|
||||||
cname := C.CString(name)
|
lib, err := purego.Dlopen(name, purego.RTLD_LAZY|purego.RTLD_GLOBAL)
|
||||||
lib := C.dlopen(cname, C.RTLD_LAZY|C.RTLD_GLOBAL)
|
if err == nil {
|
||||||
C.free(unsafe.Pointer(cname))
|
|
||||||
if lib != nil {
|
|
||||||
libGLES = lib
|
libGLES = lib
|
||||||
c.isES = true
|
c.isES = true
|
||||||
return nil
|
return nil
|
||||||
@ -99,19 +75,32 @@ func (c *defaultContext) init() error {
|
|||||||
|
|
||||||
func (c *defaultContext) getProcAddress(name string) (uintptr, error) {
|
func (c *defaultContext) getProcAddress(name string) (uintptr, error) {
|
||||||
if c.isES {
|
if c.isES {
|
||||||
return getProcAddressGLES(name), nil
|
return getProcAddressGLES(name)
|
||||||
}
|
}
|
||||||
return getProcAddressGL(name), nil
|
return getProcAddressGL(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProcAddressGL(name string) uintptr {
|
var glXGetProcAddress func(name string) uintptr
|
||||||
cname := C.CString(name)
|
|
||||||
defer C.free(unsafe.Pointer(cname))
|
func getProcAddressGL(name string) (uintptr, error) {
|
||||||
return uintptr(C.getProcAddressGL(libGL, cname))
|
if glXGetProcAddress == nil {
|
||||||
|
if _, err := purego.Dlsym(libGL, "glXGetProcAddress"); err == nil {
|
||||||
|
purego.RegisterLibFunc(&glXGetProcAddress, libGL, "glXGetProcAddress")
|
||||||
|
} else if _, err := purego.Dlsym(libGL, "glXGetProcAddressARB"); err == nil {
|
||||||
|
purego.RegisterLibFunc(&glXGetProcAddress, libGL, "glXGetProcAddressARB")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if glXGetProcAddress == nil {
|
||||||
|
return 0, fmt.Errorf("gl: failed to find glXGetProcAddress or glXGetProcAddressARB in libGL.so")
|
||||||
|
}
|
||||||
|
|
||||||
|
return glXGetProcAddress(name), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getProcAddressGLES(name string) uintptr {
|
func getProcAddressGLES(name string) (uintptr, error) {
|
||||||
cname := C.CString(name)
|
proc, err := purego.Dlsym(libGLES, name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
if err != nil {
|
||||||
return uintptr(C.getProcAddressGLES(libGLES, cname))
|
return 0, err
|
||||||
|
}
|
||||||
|
return proc, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user