mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
OpenGL: detect library version
This commit is contained in:
@@ -42,6 +42,8 @@ const char* detectByOpenGL(FFlist* gpus)
|
||||
ffStrbufInit(&result.renderer);
|
||||
ffStrbufInit(&result.vendor);
|
||||
ffStrbufInit(&result.slv);
|
||||
ffStrbufInit(&result.library);
|
||||
|
||||
const char* error = ffDetectOpenGL(&instance.config.modules.openGL, &result);
|
||||
if (!error)
|
||||
{
|
||||
@@ -75,6 +77,7 @@ const char* detectByOpenGL(FFlist* gpus)
|
||||
ffStrbufDestroy(&result.renderer);
|
||||
ffStrbufDestroy(&result.vendor);
|
||||
ffStrbufDestroy(&result.slv);
|
||||
ffStrbufDestroy(&result.library);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ typedef struct FFOpenGLResult
|
||||
FFstrbuf renderer;
|
||||
FFstrbuf vendor;
|
||||
FFstrbuf slv;
|
||||
const char* library;
|
||||
FFstrbuf library;
|
||||
} FFOpenGLResult;
|
||||
|
||||
const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result);
|
||||
|
||||
@@ -6,14 +6,16 @@
|
||||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/OpenGL.h> // This brings in CGL, not GL
|
||||
|
||||
static const char* glHandleResult(FFOpenGLResult* result)
|
||||
static void glHandleResult(FFOpenGLResult* result)
|
||||
{
|
||||
ffStrbufAppendS(&result->version, (const char*) glGetString(GL_VERSION));
|
||||
ffStrbufAppendS(&result->renderer, (const char*) glGetString(GL_RENDERER));
|
||||
ffStrbufAppendS(&result->vendor, (const char*) glGetString(GL_VENDOR));
|
||||
ffStrbufAppendS(&result->slv, (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
result->library = "CGL";
|
||||
return NULL;
|
||||
|
||||
GLint major, minor;
|
||||
CGLGetVersion(&major, &minor);
|
||||
ffStrbufAppendF(&result->library, "CGL %d.%d", major, minor);
|
||||
}
|
||||
|
||||
static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj context)
|
||||
@@ -21,7 +23,9 @@ static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj contex
|
||||
if(CGLSetCurrentContext(context) != kCGLNoError)
|
||||
return "CGLSetCurrentContext() failed";
|
||||
|
||||
return glHandleResult(result);
|
||||
glHandleResult(result);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* cglHandlePixelFormat(FFOpenGLResult* result, CGLPixelFormatObj pixelFormat)
|
||||
|
||||
@@ -18,14 +18,12 @@ typedef struct GLData
|
||||
FF_LIBRARY_SYMBOL(glGetString)
|
||||
} GLData;
|
||||
|
||||
static const char* glHandleResult(FFOpenGLResult* result, const GLData* data, const char* library)
|
||||
static void glHandleResult(FFOpenGLResult* result, const GLData* data)
|
||||
{
|
||||
ffStrbufAppendS(&result->version, (const char*) data->ffglGetString(GL_VERSION));
|
||||
ffStrbufAppendS(&result->renderer, (const char*) data->ffglGetString(GL_RENDERER));
|
||||
ffStrbufAppendS(&result->vendor, (const char*) data->ffglGetString(GL_VENDOR));
|
||||
ffStrbufAppendS(&result->slv, (const char*) data->ffglGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
result->library = library;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif // FF_HAVE_GL
|
||||
@@ -41,6 +39,7 @@ typedef struct EGLData
|
||||
|
||||
FF_LIBRARY_SYMBOL(eglGetProcAddress)
|
||||
FF_LIBRARY_SYMBOL(eglGetDisplay)
|
||||
FF_LIBRARY_SYMBOL(eglQueryString)
|
||||
FF_LIBRARY_SYMBOL(eglInitialize)
|
||||
FF_LIBRARY_SYMBOL(eglBindAPI)
|
||||
FF_LIBRARY_SYMBOL(eglGetConfigs)
|
||||
@@ -62,7 +61,9 @@ static const char* eglHandleContext(FFOpenGLResult* result, EGLData* data)
|
||||
if(data->ffeglMakeCurrent(data->display, data->surface, data->surface, data->context) != EGL_TRUE)
|
||||
return "eglMakeCurrent returned EGL_FALSE";
|
||||
|
||||
return glHandleResult(result, &data->glData, "EGL");
|
||||
glHandleResult(result, &data->glData);
|
||||
ffStrbufSetF(&result->library, "EGL %s", data->ffeglQueryString(data->display, EGL_VERSION));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* eglHandleSurface(FFOpenGLResult* result, EGLData* data)
|
||||
@@ -126,6 +127,7 @@ static const char* eglPrint(FFOpenGLResult* result)
|
||||
FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetProcAddress);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetDisplay);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglQueryString);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglInitialize);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglBindAPI);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetConfigs);
|
||||
@@ -150,6 +152,7 @@ typedef struct GLXData
|
||||
GLData glData;
|
||||
|
||||
FF_LIBRARY_SYMBOL(glXGetProcAddress)
|
||||
FF_LIBRARY_SYMBOL(glXQueryVersion)
|
||||
FF_LIBRARY_SYMBOL(XOpenDisplay)
|
||||
FF_LIBRARY_SYMBOL(glXChooseVisual)
|
||||
FF_LIBRARY_SYMBOL(XCreatePixmap);
|
||||
@@ -173,8 +176,15 @@ static const char* glxHandleContext(FFOpenGLResult* result, GLXData* data)
|
||||
{
|
||||
if(data->ffglXMakeCurrent(data->display, data->glxPixmap, data->context) != True)
|
||||
return "glXMakeCurrent returned False";
|
||||
glHandleResult(result, &data->glData);
|
||||
|
||||
return glHandleResult(result, &data->glData, "GLX");
|
||||
int major, minor;
|
||||
if (data->ffglXQueryVersion(data->display, &major, &minor))
|
||||
ffStrbufSetF(&result->library, "GLX %d.%d", major, minor);
|
||||
else
|
||||
ffStrbufSetStatic(&result->library, "GLX");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* glxHandleGLXPixmap(FFOpenGLResult* result, GLXData* data)
|
||||
@@ -242,6 +252,7 @@ static const char* glxPrint(FFOpenGLResult* result)
|
||||
|
||||
FF_LIBRARY_LOAD(glx, &instance.config.library.libGLX, "dlopen glx failed", "libGLX" FF_LIBRARY_EXTENSION, 1);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXGetProcAddress);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXQueryVersion);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XOpenDisplay);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXChooseVisual);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XCreatePixmap);
|
||||
@@ -285,7 +296,9 @@ static const char* osMesaHandleContext(FFOpenGLResult* result, OSMesaData* data)
|
||||
if(data->ffOSMesaMakeCurrent(data->context, buffer, GL_UNSIGNED_BYTE, FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT) != GL_TRUE)
|
||||
return "OSMesaMakeCurrent returned GL_FALSE";
|
||||
|
||||
return glHandleResult(result, &data->glData, "OSMesa");
|
||||
glHandleResult(result, &data->glData);
|
||||
ffStrbufSetF(&result->library, "OSMesa %d.%d.%d", OSMESA_MAJOR_VERSION, OSMESA_MINOR_VERSION, OSMESA_PATCH_VERSION);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* osMesaHandleData(FFOpenGLResult* result, OSMesaData* data)
|
||||
|
||||
@@ -19,21 +19,21 @@ typedef struct WGLData
|
||||
FF_LIBRARY_SYMBOL(wglDeleteContext)
|
||||
} WGLData;
|
||||
|
||||
static const char* glHandleResult(WGLData* wglData)
|
||||
static void glHandleResult(WGLData* wglData)
|
||||
{
|
||||
ffStrbufAppendS(&wglData->result->version, (const char*) wglData->ffglGetString(GL_VERSION));
|
||||
ffStrbufAppendS(&wglData->result->renderer, (const char*) wglData->ffglGetString(GL_RENDERER));
|
||||
ffStrbufAppendS(&wglData->result->vendor, (const char*) wglData->ffglGetString(GL_VENDOR));
|
||||
ffStrbufAppendS(&wglData->result->slv, (const char*) wglData->ffglGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
wglData->result->library = "WGL";
|
||||
return NULL;
|
||||
ffStrbufSetStatic(&wglData->result->library, "WGL 1.0");
|
||||
}
|
||||
|
||||
static const char* wglHandleContext(WGLData* wglData, HDC hdc, HGLRC context)
|
||||
{
|
||||
if(wglData->ffwglMakeCurrent(hdc, context) == FALSE)
|
||||
return "wglMakeCurrent() failed";
|
||||
return glHandleResult(wglData);
|
||||
glHandleResult(wglData);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const char* wglHandlePixelFormat(WGLData* wglData, HWND hWnd)
|
||||
|
||||
@@ -13,7 +13,7 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
|
||||
ffStrbufInit(&result.renderer);
|
||||
ffStrbufInit(&result.vendor);
|
||||
ffStrbufInit(&result.slv);
|
||||
result.library = "Unknown";
|
||||
ffStrbufInit(&result.library);
|
||||
|
||||
const char* error = ffDetectOpenGL(options, &result);
|
||||
if(error)
|
||||
@@ -34,7 +34,7 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.renderer, "renderer"},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor, "vendor"},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.slv, "slv"},
|
||||
{FF_FORMAT_ARG_TYPE_STRING, result.library, "library"},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.library, "library"},
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
|
||||
ffStrbufDestroy(&result.renderer);
|
||||
ffStrbufDestroy(&result.vendor);
|
||||
ffStrbufDestroy(&result.slv);
|
||||
ffStrbufDestroy(&result.library);
|
||||
}
|
||||
|
||||
bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, const char* value)
|
||||
@@ -140,6 +141,7 @@ void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson
|
||||
ffStrbufInit(&result.renderer);
|
||||
ffStrbufInit(&result.vendor);
|
||||
ffStrbufInit(&result.slv);
|
||||
ffStrbufInit(&result.library);
|
||||
|
||||
const char* error = ffDetectOpenGL(options, &result);
|
||||
if(error != NULL)
|
||||
@@ -153,13 +155,14 @@ void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "renderer", &result.renderer);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &result.vendor);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "slv", &result.slv);
|
||||
yyjson_mut_obj_add_str(doc, obj, "library", result.library);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "library", &result.library);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&result.version);
|
||||
ffStrbufDestroy(&result.renderer);
|
||||
ffStrbufDestroy(&result.vendor);
|
||||
ffStrbufDestroy(&result.slv);
|
||||
ffStrbufDestroy(&result.library);
|
||||
}
|
||||
|
||||
void ffPrintOpenGLHelpFormat(void)
|
||||
|
||||
Reference in New Issue
Block a user