77#define FF_OPENGL_MODULE_NAME "OpenGL"
88#define FF_OPENGL_NUM_FORMAT_ARGS 4
99
10- #if defined(FF_HAVE_EGL ) || defined(FF_HAVE_GLX ) || defined(FF_HAVE_OSMESA )
10+ #if defined(FF_HAVE_EGL ) || defined(FF_HAVE_GLX ) || defined(FF_HAVE_OSMESA ) || defined( FF_HAVE_APPLECGL )
1111#define FF_HAVE_GL 1
1212#include "common/library.h"
1313#ifdef __APPLE__
@@ -337,6 +337,45 @@ static const char* osMesaPrint(FFinstance* instance)
337337
338338#endif //FF_HAVE_OSMESA
339339
340+ #ifdef FF_HAVE_APPLECGL
341+
342+ #include <OpenGL/OpenGL.h>
343+
344+ static const char * appleCglPrint (FFinstance * instance )
345+ {
346+ CGLPixelFormatAttribute attrs [] = {
347+ kCGLPFAOpenGLProfile , (CGLPixelFormatAttribute )kCGLOGLPVersion_3_2_Core ,
348+ kCGLPFAAccelerated ,
349+ 0
350+ };
351+ CGLPixelFormatObj pix ;
352+ GLint num ;
353+ if (CGLChoosePixelFormat (attrs , & pix , & num ) != kCGLNoError ) {
354+ return "CGLChoosePixelFormat() failed" ;
355+ }
356+
357+ CGLContextObj ctx ;
358+ if (CGLCreateContext (pix , NULL , & ctx ) != kCGLNoError ) {
359+ return "CGLCreateContext() failed" ;
360+ }
361+ if (CGLSetCurrentContext (ctx ) != kCGLNoError ) {
362+ return "CGLSetCurrentContext() failed" ;
363+ }
364+
365+ GLData glData = {
366+ .ffglGetString = glGetString
367+ };
368+
369+ const char * error = glHandlePrint (instance , & glData );
370+
371+ CGLDestroyContext (ctx );
372+ CGLDestroyPixelFormat (pix );
373+
374+ return error ;
375+ }
376+
377+ #endif //FF_HAVE_APPLECGL
378+
340379static const char * glPrint (FFinstance * instance )
341380{
342381 if (instance -> config .glType == FF_GL_TYPE_GLX )
@@ -366,6 +405,15 @@ static const char* glPrint(FFinstance* instance)
366405 #endif
367406 }
368407
408+ if (instance -> config .glType == FF_GL_TYPE_APPLECGL )
409+ {
410+ #ifdef FF_HAVE_APPLECGL
411+ return appleCglPrint (instance );
412+ #else
413+ return "fastfetch was compiled without apple-cgl support" ;
414+ #endif
415+ }
416+
369417 const char * error = "" ; // not NULL dummy value
370418
371419 #ifdef FF_HAVE_EGL
@@ -377,6 +425,11 @@ static const char* glPrint(FFinstance* instance)
377425 error = glxPrint (instance );
378426 #endif
379427
428+ #ifdef FF_HAVE_APPLECGL
429+ if (error != NULL )
430+ error = appleCglPrint (instance );
431+ #endif
432+
380433 //We don't use osmesa in auto mode here, because it is a software implementation,
381434 //that doesn't reflect the opengl supported by the hardware
382435
0 commit comments