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_CGL )
10+ #if defined(FF_HAVE_EGL ) || defined(FF_HAVE_GLX ) || defined(FF_HAVE_OSMESA ) || defined(__APPLE__ )
1111#define FF_HAVE_GL 1
1212
1313#include "common/library.h"
@@ -339,41 +339,36 @@ static const char* osMesaPrint(FFinstance* instance)
339339
340340#endif //FF_HAVE_OSMESA
341341
342- #ifdef FF_HAVE_CGL
342+ #ifdef __APPLE__
343343
344344typedef struct CGLData
345345{
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-
354346 CGLPixelFormatObj pixelFormat ;
355347 CGLContextObj context ;
356348} CGLData ;
357349
358350static const char * cglHandleContext (FFinstance * instance , CGLData * data )
359351{
360- if (data -> ffCGLSetCurrentContext (data -> context ) != kCGLNoError )
352+ if (CGLSetCurrentContext (data -> context ) != kCGLNoError )
361353 return "CGLSetCurrentContext() failed" ;
362354
363- return glHandlePrint (instance , & data -> glData );
355+ GLData glData ;
356+ glData .ffglGetString = glGetString ;
357+
358+ return glHandlePrint (instance , & glData );
364359}
365360
366361static const char * cglHandlePixelFormat (FFinstance * instance , CGLData * data )
367362{
368- if (data -> ffCGLCreateContext (data -> pixelFormat , NULL , & data -> context ) != kCGLNoError )
363+ if (CGLCreateContext (data -> pixelFormat , NULL , & data -> context ) != kCGLNoError )
369364 return "CGLCreateContext() failed" ;
370365
371366 const char * error = cglHandleContext (instance , data );
372- data -> ffCGLDestroyContext (data -> context );
367+ CGLDestroyContext (data -> context );
373368 return error ;
374369}
375370
376- static const char * cglHandleData (FFinstance * instance , CGLData * data )
371+ static const char * cglPrint (FFinstance * instance )
377372{
378373 CGLPixelFormatAttribute attrs [] = {
379374 kCGLPFAOpenGLProfile , (CGLPixelFormatAttribute ) kCGLOGLPVersion_3_2_Core ,
@@ -382,32 +377,15 @@ static const char* cglHandleData(FFinstance* instance, CGLData* data)
382377 };
383378
384379 GLint num ;
385- if (data -> ffCGLChoosePixelFormat (attrs , & data -> pixelFormat , & num ) != kCGLNoError )
380+ if (CGLChoosePixelFormat (attrs , & data -> pixelFormat , & num ) != kCGLNoError )
386381 return "CGLChoosePixelFormat() failed" ;
387382
388383 const char * error = cglHandlePixelFormat (instance , data );
389- data -> ffCGLDestroyPixelFormat (data -> pixelFormat );
390- return error ;
391- }
392-
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 );
384+ CGLDestroyPixelFormat (data -> pixelFormat );
407385 return error ;
408386}
409387
410- #endif //FF_HAVE_CGL
388+ #else // __APPLE__
411389
412390static const char * glPrint (FFinstance * instance )
413391{
@@ -438,15 +416,6 @@ static const char* glPrint(FFinstance* instance)
438416 #endif
439417 }
440418
441- if (instance -> config .glType == FF_GL_TYPE_CGL )
442- {
443- #ifdef FF_HAVE_CGL
444- return cglPrint (instance );
445- #else
446- return "fastfetch was compiled without cgl support" ;
447- #endif
448- }
449-
450419 const char * error = "" ; // not NULL dummy value
451420
452421 #ifdef FF_HAVE_EGL
@@ -458,17 +427,14 @@ static const char* glPrint(FFinstance* instance)
458427 error = glxPrint (instance );
459428 #endif
460429
461- #ifdef FF_HAVE_CGL
462- if (error != NULL )
463- error = cglPrint (instance );
464- #endif
465-
466430 //We don't use osmesa in auto mode here, because it is a software implementation,
467431 //that doesn't reflect the opengl supported by the hardware
468432
469433 return error ;
470434}
471435
436+ #endif // !__APPLE__
437+
472438#endif // FF_HAVE_GL
473439
474440void ffPrintOpenGL (FFinstance * instance )
@@ -477,6 +443,8 @@ void ffPrintOpenGL(FFinstance* instance)
477443
478444 #ifndef FF_HAVE_GL
479445 error = "Fastfetch was built without gl support." ;
446+ #elif __APPLE__
447+ error = cglPrint (instance );
480448 #else
481449 error = glPrint (instance );
482450 #endif
0 commit comments