From 1038668db939f213bcbd026bec278258a54b8758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 9 Jul 2024 20:39:15 +0800 Subject: [PATCH] OpenGL: detect library version --- src/detection/gpu/gpu.c | 3 +++ src/detection/opengl/opengl.h | 2 +- src/detection/opengl/opengl_apple.c | 12 ++++++++---- src/detection/opengl/opengl_linux.c | 25 +++++++++++++++++++------ src/detection/opengl/opengl_windows.c | 8 ++++---- src/modules/opengl/opengl.c | 9 ++++++--- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/detection/gpu/gpu.c b/src/detection/gpu/gpu.c index 70eac725b..d9b30cd2e 100644 --- a/src/detection/gpu/gpu.c +++ b/src/detection/gpu/gpu.c @@ -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; } diff --git a/src/detection/opengl/opengl.h b/src/detection/opengl/opengl.h index 6614ea2f2..b8d5ce787 100644 --- a/src/detection/opengl/opengl.h +++ b/src/detection/opengl/opengl.h @@ -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); diff --git a/src/detection/opengl/opengl_apple.c b/src/detection/opengl/opengl_apple.c index 3a8e7ac5e..db3be29d2 100644 --- a/src/detection/opengl/opengl_apple.c +++ b/src/detection/opengl/opengl_apple.c @@ -6,14 +6,16 @@ #include #include // 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) diff --git a/src/detection/opengl/opengl_linux.c b/src/detection/opengl/opengl_linux.c index bc957add7..bd0d50e41 100644 --- a/src/detection/opengl/opengl_linux.c +++ b/src/detection/opengl/opengl_linux.c @@ -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) diff --git a/src/detection/opengl/opengl_windows.c b/src/detection/opengl/opengl_windows.c index e0b29fc8a..0ad0d4572 100644 --- a/src/detection/opengl/opengl_windows.c +++ b/src/detection/opengl/opengl_windows.c @@ -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) diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index e8a29870f..e7bbff3ee 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -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)