From d43c6ffe27bfc6dfc9c107e2ca68050fe1006763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 4 Sep 2024 14:50:29 +0800 Subject: [PATCH] OpenGL (macOS): support EGL (ANGLE) on macOS --- src/detection/opengl/opengl_apple.c | 19 ++++++++++++++++++- src/detection/opengl/opengl_shared.c | 13 ++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/detection/opengl/opengl_apple.c b/src/detection/opengl/opengl_apple.c index c6b56f07f..63751d6b8 100644 --- a/src/detection/opengl/opengl_apple.c +++ b/src/detection/opengl/opengl_apple.c @@ -34,7 +34,7 @@ static const char* cglHandlePixelFormat(FFOpenGLResult* result, CGLPixelFormatOb return error; } -const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLResult* result) +const char* cglDetectOpenGL(FFOpenGLResult* result) { CGLPixelFormatObj pixelFormat; CGLPixelFormatAttribute attrs[] = { @@ -51,3 +51,20 @@ const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLRes CGLDestroyPixelFormat(pixelFormat); return error; } + +const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) +{ + if (options->library == FF_OPENGL_LIBRARY_AUTO) + return cglDetectOpenGL(result); + else if (options->library == FF_OPENGL_LIBRARY_EGL) + { + #if __has_include() + const char* ffOpenGLDetectByEGL(FFOpenGLResult* result); + return ffOpenGLDetectByEGL(result); + #else + return "fastfetch was compiled without egl support"; + #endif + } + else + return "Unsupported OpenGL library"; +} diff --git a/src/detection/opengl/opengl_shared.c b/src/detection/opengl/opengl_shared.c index f8e190dc3..261260c48 100644 --- a/src/detection/opengl/opengl_shared.c +++ b/src/detection/opengl/opengl_shared.c @@ -74,14 +74,8 @@ static const char* eglHandleSurface(FFOpenGLResult* result, EGLData* data) static const char* eglHandleDisplay(FFOpenGLResult* result, EGLData* data) { - if(data->ffeglBindAPI( - #ifdef _WIN32 - EGL_OPENGL_ES_API - #else - EGL_OPENGL_API - #endif - ) != EGL_TRUE) - return "eglBindAPI returned EGL_FALSE"; + // try use OpenGL API. If failed, use the default API (usually OpenGL ES) + data->ffeglBindAPI(EGL_OPENGL_API); EGLint eglConfigCount; data->ffeglGetConfigs(data->display, &data->config, 1, &eglConfigCount); @@ -121,11 +115,12 @@ static const char* eglHandleData(FFOpenGLResult* result, EGLData* data) return error; } + const char* ffOpenGLDetectByEGL(FFOpenGLResult* result) { EGLData eglData; - FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen libEGL" FF_LIBRARY_EXTENSION " failed", "libEGL" FF_LIBRARY_EXTENSION, 1); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetProcAddress); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetDisplay); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglQueryString);