mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-04 04:04:17 +01:00
OpenGL / OpenCL: add macOS support
Note: FF_LIBRARY_LOAD and friends are not used because loading framework bundles are not supported by FF_LIBRARY_LOAD and support it is not easy. Since CGL is guaranteed to be supported by macOS system, we simply use static linking in this case.
This commit is contained in:
@@ -10,7 +10,11 @@
|
||||
#include <string.h>
|
||||
|
||||
#define CL_TARGET_OPENCL_VERSION 100
|
||||
#ifdef __APPLE__
|
||||
#include <OpenCL/cl.h>
|
||||
#else
|
||||
#include <CL/cl.h>
|
||||
#endif
|
||||
|
||||
typedef struct OpenCLData
|
||||
{
|
||||
@@ -75,13 +79,21 @@ static const char* printOpenCL(FFinstance* instance)
|
||||
{
|
||||
OpenCLData data;
|
||||
|
||||
#ifdef __APPLE__
|
||||
data.ffclGetPlatformIDs = clGetPlatformIDs;
|
||||
data.ffclGetDeviceIDs = clGetDeviceIDs;
|
||||
data.ffclGetDeviceInfo = clGetDeviceInfo;
|
||||
#else
|
||||
FF_LIBRARY_LOAD(opencl, instance->config.libOpenCL, "dlopen libOpenCL.so failed", "libOpenCL.so", 1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetPlatformIDs);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceIDs);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opencl, data, clGetDeviceInfo);
|
||||
#endif
|
||||
|
||||
const char* error = openCLHandelData(instance, &data);
|
||||
#ifndef __APPLE__
|
||||
dlclose(opencl);
|
||||
#endif
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
|
||||
+54
-1
@@ -7,7 +7,7 @@
|
||||
#define FF_OPENGL_MODULE_NAME "OpenGL"
|
||||
#define FF_OPENGL_NUM_FORMAT_ARGS 4
|
||||
|
||||
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA)
|
||||
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) || defined(FF_HAVE_APPLECGL)
|
||||
#define FF_HAVE_GL 1
|
||||
#include "common/library.h"
|
||||
#ifdef __APPLE__
|
||||
@@ -337,6 +337,45 @@ static const char* osMesaPrint(FFinstance* instance)
|
||||
|
||||
#endif //FF_HAVE_OSMESA
|
||||
|
||||
#ifdef FF_HAVE_APPLECGL
|
||||
|
||||
#include <OpenGL/OpenGL.h>
|
||||
|
||||
static const char* appleCglPrint(FFinstance* instance)
|
||||
{
|
||||
CGLPixelFormatAttribute attrs[] = {
|
||||
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core,
|
||||
kCGLPFAAccelerated,
|
||||
0
|
||||
};
|
||||
CGLPixelFormatObj pix;
|
||||
GLint num;
|
||||
if (CGLChoosePixelFormat(attrs, &pix, &num) != kCGLNoError) {
|
||||
return "CGLChoosePixelFormat() failed";
|
||||
}
|
||||
|
||||
CGLContextObj ctx;
|
||||
if (CGLCreateContext(pix, NULL, &ctx) != kCGLNoError) {
|
||||
return "CGLCreateContext() failed";
|
||||
}
|
||||
if (CGLSetCurrentContext(ctx) != kCGLNoError) {
|
||||
return "CGLSetCurrentContext() failed";
|
||||
}
|
||||
|
||||
GLData glData = {
|
||||
.ffglGetString = glGetString
|
||||
};
|
||||
|
||||
const char* error = glHandlePrint(instance, &glData);
|
||||
|
||||
CGLDestroyContext(ctx);
|
||||
CGLDestroyPixelFormat(pix);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif //FF_HAVE_APPLECGL
|
||||
|
||||
static const char* glPrint(FFinstance* instance)
|
||||
{
|
||||
if(instance->config.glType == FF_GL_TYPE_GLX)
|
||||
@@ -366,6 +405,15 @@ static const char* glPrint(FFinstance* instance)
|
||||
#endif
|
||||
}
|
||||
|
||||
if(instance->config.glType == FF_GL_TYPE_APPLECGL)
|
||||
{
|
||||
#ifdef FF_HAVE_APPLECGL
|
||||
return appleCglPrint(instance);
|
||||
#else
|
||||
return "fastfetch was compiled without apple-cgl support";
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* error = ""; // not NULL dummy value
|
||||
|
||||
#ifdef FF_HAVE_EGL
|
||||
@@ -377,6 +425,11 @@ static const char* glPrint(FFinstance* instance)
|
||||
error = glxPrint(instance);
|
||||
#endif
|
||||
|
||||
#ifdef FF_HAVE_APPLECGL
|
||||
if(error != NULL)
|
||||
error = appleCglPrint(instance);
|
||||
#endif
|
||||
|
||||
//We don't use osmesa in auto mode here, because it is a software implementation,
|
||||
//that doesn't reflect the opengl supported by the hardware
|
||||
|
||||
|
||||
Reference in New Issue
Block a user