OpenGL (macOS): support EGL (ANGLE) on macOS

This commit is contained in:
李通洲 2024-09-04 14:50:29 +08:00
parent cf7c5d3cfa
commit d43c6ffe27
No known key found for this signature in database
GPG Key ID: 269AD4F5325A22A3
2 changed files with 22 additions and 10 deletions

View File

@ -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(<EGL/egl.h>)
const char* ffOpenGLDetectByEGL(FFOpenGLResult* result);
return ffOpenGLDetectByEGL(result);
#else
return "fastfetch was compiled without egl support";
#endif
}
else
return "Unsupported OpenGL library";
}

View File

@ -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);