From 78f8ddbda8ca1df54a47d21b175b2866abec3327 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 13 Nov 2022 19:51:36 +0900 Subject: [PATCH] internal/graphicsdriver/opengl/gl: load OpenGLES.framework if possible on Darwin Closes #2449 --- .../graphicsdriver/opengl/gl/default_gles.go | 19 ++++--------------- .../opengl/gl/default_purego.go | 2 +- .../opengl/gl/procaddr_darwin.go | 10 +++++++++- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/internal/graphicsdriver/opengl/gl/default_gles.go b/internal/graphicsdriver/opengl/gl/default_gles.go index cf70e3b46..506b32794 100644 --- a/internal/graphicsdriver/opengl/gl/default_gles.go +++ b/internal/graphicsdriver/opengl/gl/default_gles.go @@ -12,25 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build android || ios || opengles +//go:build android || opengles package gl -// #cgo !darwin CFLAGS: -Dos_notdarwin -// #cgo darwin CFLAGS: -Dos_darwin -// #cgo !android,!darwin pkg-config: glesv2 -// #cgo android LDFLAGS: -lGLESv2 -// #cgo darwin LDFLAGS: -framework OpenGLES -// -// #if defined(os_darwin) -// #define GLES_SILENCE_DEPRECATION -// #include -// #endif -// -// #if defined(os_notdarwin) -// #include -// #endif +// #cgo !android pkg-config: glesv2 +// #cgo android LDFLAGS: -lGLESv2 // +// #include // #include import "C" diff --git a/internal/graphicsdriver/opengl/gl/default_purego.go b/internal/graphicsdriver/opengl/gl/default_purego.go index d579c38d1..55c718ce8 100644 --- a/internal/graphicsdriver/opengl/gl/default_purego.go +++ b/internal/graphicsdriver/opengl/gl/default_purego.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build (darwin || windows) && !ios && !opengles +//go:build darwin || windows package gl diff --git a/internal/graphicsdriver/opengl/gl/procaddr_darwin.go b/internal/graphicsdriver/opengl/gl/procaddr_darwin.go index 38a537b33..35c5babba 100644 --- a/internal/graphicsdriver/opengl/gl/procaddr_darwin.go +++ b/internal/graphicsdriver/opengl/gl/procaddr_darwin.go @@ -7,7 +7,15 @@ import ( "github.com/ebitengine/purego" ) -var opengl = purego.Dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", purego.RTLD_GLOBAL) +var opengl uintptr + +func init() { + opengl = purego.Dlopen("/System/Library/Frameworks/OpenGLES.framework/Versions/Current/OpenGLES", purego.RTLD_GLOBAL) + if opengl != 0 { + return + } + opengl = purego.Dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", purego.RTLD_GLOBAL) +} func getProcAddress(name string) uintptr { return purego.Dlsym(opengl, name)