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 ) || defined(FF_HAVE_APPLECGL )
10+ #if defined(FF_HAVE_EGL ) || defined(FF_HAVE_GLX ) || defined(FF_HAVE_OSMESA ) || defined(FF_HAVE_CGL )
1111#define FF_HAVE_GL 1
12+
1213#include "common/library.h"
14+
1315#ifdef __APPLE__
14- #define GL_SILENCE_DEPRECATION
15- #include <OpenGL/gl.h>
16+ #define GL_SILENCE_DEPRECATION
17+ #include <OpenGL/gl.h>
1618#else
17- #include <GL/gl.h>
19+ #include <GL/gl.h>
1820#endif
1921
2022#define FF_OPENGL_BUFFER_WIDTH 1
@@ -337,44 +339,75 @@ static const char* osMesaPrint(FFinstance* instance)
337339
338340#endif //FF_HAVE_OSMESA
339341
340- #ifdef FF_HAVE_APPLECGL
342+ #ifdef FF_HAVE_CGL
343+
344+ typedef struct CGLData
345+ {
346+ GLData glData ;
347+
348+ FF_LIBRARY_SYMBOL (CGLChoosePixelFormat );
349+ FF_LIBRARY_SYMBOL (CGLCreateContext );
350+ FF_LIBRARY_SYMBOL (CGLSetCurrentContext );
351+ FF_LIBRARY_SYMBOL (CGLDestroyContext );
352+ FF_LIBRARY_SYMBOL (CGLDestroyPixelFormat );
353+
354+ CGLPixelFormatObj pixelFormat ;
355+ CGLContextObj context ;
356+ } CGLData ;
357+
358+ static const char * cglHandleContext (FFinstance * instance , CGLData * data )
359+ {
360+ if (data -> ffCGLSetCurrentContext (data -> context ) != kCGLNoError )
361+ return "CGLSetCurrentContext() failed" ;
341362
342- #include <OpenGL/OpenGL.h>
363+ return glHandlePrint (instance , & data -> glData );
364+ }
343365
344- static const char * appleCglPrint (FFinstance * instance )
366+ static const char * cglHandlePixelFormat (FFinstance * instance , CGLData * data )
367+ {
368+ if (data -> ffCGLCreateContext (data -> pixelFormat , NULL , & data -> context ) != kCGLNoError )
369+ return "CGLCreateContext() failed" ;
370+
371+ const char * error = cglHandleContext (instance , data );
372+ data -> ffCGLDestroyContext (data -> context );
373+ return error ;
374+ }
375+
376+ static const char * cglHandleData (FFinstance * instance , CGLData * data )
345377{
346378 CGLPixelFormatAttribute attrs [] = {
347- kCGLPFAOpenGLProfile , (CGLPixelFormatAttribute )kCGLOGLPVersion_3_2_Core ,
379+ kCGLPFAOpenGLProfile , (CGLPixelFormatAttribute ) kCGLOGLPVersion_3_2_Core ,
348380 kCGLPFAAccelerated ,
349381 0
350382 };
351- CGLPixelFormatObj pix ;
383+
352384 GLint num ;
353- if (CGLChoosePixelFormat (attrs , & pix , & num ) != kCGLNoError ) {
385+ if (data -> ffCGLChoosePixelFormat (attrs , & data -> pixelFormat , & num ) != kCGLNoError )
354386 return "CGLChoosePixelFormat() failed" ;
355- }
356387
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 );
388+ const char * error = cglHandlePixelFormat (instance , data );
389+ data -> ffCGLDestroyPixelFormat (data -> pixelFormat );
390+ return error ;
391+ }
373392
393+ static const char * cglPrint (FFinstance * instance )
394+ {
395+ CGLData data ;
396+
397+ FF_LIBRARY_LOAD (cgl , instance -> config .libCGL , "dlopen cgl failed" , "/System/Library/Frameworks/OpenGL.framework/OpenGL" , -1 );
398+ FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (cgl , data , CGLChoosePixelFormat );
399+ FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (cgl , data , CGLCreateContext );
400+ FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (cgl , data , CGLSetCurrentContext );
401+ FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (cgl , data , CGLDestroyContext );
402+ FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (cgl , data , CGLDestroyPixelFormat );
403+ FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE (cgl , data .glData , glGetString );
404+
405+ const char * error = cglHandleData (instance , & data );
406+ dlclose (cgl );
374407 return error ;
375408}
376409
377- #endif //FF_HAVE_APPLECGL
410+ #endif //FF_HAVE_CGL
378411
379412static const char * glPrint (FFinstance * instance )
380413{
@@ -405,12 +438,12 @@ static const char* glPrint(FFinstance* instance)
405438 #endif
406439 }
407440
408- if (instance -> config .glType == FF_GL_TYPE_APPLECGL )
441+ if (instance -> config .glType == FF_GL_TYPE_CGL )
409442 {
410- #ifdef FF_HAVE_APPLECGL
411- return appleCglPrint (instance );
443+ #ifdef FF_HAVE_CGL
444+ return cglPrint (instance );
412445 #else
413- return "fastfetch was compiled without apple- cgl support" ;
446+ return "fastfetch was compiled without cgl support" ;
414447 #endif
415448 }
416449
@@ -425,9 +458,9 @@ static const char* glPrint(FFinstance* instance)
425458 error = glxPrint (instance );
426459 #endif
427460
428- #ifdef FF_HAVE_APPLECGL
461+ #ifdef FF_HAVE_CGL
429462 if (error != NULL )
430- error = appleCglPrint (instance );
463+ error = cglPrint (instance );
431464 #endif
432465
433466 //We don't use osmesa in auto mode here, because it is a software implementation,
0 commit comments