diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/opengl/opengl_apple.c | |
Add the files
Diffstat (limited to 'src/detection/opengl/opengl_apple.c')
| -rw-r--r-- | src/detection/opengl/opengl_apple.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/detection/opengl/opengl_apple.c b/src/detection/opengl/opengl_apple.c new file mode 100644 index 0000000..9128593 --- /dev/null +++ b/src/detection/opengl/opengl_apple.c @@ -0,0 +1,66 @@ + +#include "fastfetch.h" +#include "opengl.h" + +#define GL_SILENCE_DEPRECATION +#include <OpenGL/gl.h> +#include <OpenGL/OpenGL.h> // This brings in CGL, not GL + +void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString); + +static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj context) { + if (CGLSetCurrentContext(context) != kCGLNoError) { + return "CGLSetCurrentContext() failed"; + } + + ffOpenGLHandleResult(result, &glGetString); + + GLint major, minor; + CGLGetVersion(&major, &minor); + ffStrbufSetF(&result->library, "CGL %d.%d", major, minor); + + return NULL; +} + +static const char* cglHandlePixelFormat(FFOpenGLResult* result, CGLPixelFormatObj pixelFormat) { + CGLContextObj context; + + if (CGLCreateContext(pixelFormat, NULL, &context) != kCGLNoError) { + return "CGLCreateContext() failed"; + } + + const char* error = cglHandleContext(result, context); + CGLDestroyContext(context); + return error; +} + +const char* cglDetectOpenGL(FFOpenGLResult* result) { + CGLPixelFormatObj pixelFormat; + CGLPixelFormatAttribute attrs[] = { + kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, kCGLPFAAccelerated, 0 + }; + + GLint num; + if (CGLChoosePixelFormat(attrs, &pixelFormat, &num) != kCGLNoError) { + return "CGLChoosePixelFormat() failed"; + } + + const char* error = cglHandlePixelFormat(result, pixelFormat); + 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"; + } +} |