Skip to content

Commit 1038668

Browse files
committed
OpenGL: detect library version
1 parent 49639b6 commit 1038668

File tree

6 files changed

+41
-18
lines changed

6 files changed

+41
-18
lines changed

src/detection/gpu/gpu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const char* detectByOpenGL(FFlist* gpus)
4242
ffStrbufInit(&result.renderer);
4343
ffStrbufInit(&result.vendor);
4444
ffStrbufInit(&result.slv);
45+
ffStrbufInit(&result.library);
46+
4547
const char* error = ffDetectOpenGL(&instance.config.modules.openGL, &result);
4648
if (!error)
4749
{
@@ -75,6 +77,7 @@ const char* detectByOpenGL(FFlist* gpus)
7577
ffStrbufDestroy(&result.renderer);
7678
ffStrbufDestroy(&result.vendor);
7779
ffStrbufDestroy(&result.slv);
80+
ffStrbufDestroy(&result.library);
7881
return error;
7982
}
8083

src/detection/opengl/opengl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ typedef struct FFOpenGLResult
88
FFstrbuf renderer;
99
FFstrbuf vendor;
1010
FFstrbuf slv;
11-
const char* library;
11+
FFstrbuf library;
1212
} FFOpenGLResult;
1313

1414
const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result);

src/detection/opengl/opengl_apple.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,26 @@
66
#include <OpenGL/gl.h>
77
#include <OpenGL/OpenGL.h> // This brings in CGL, not GL
88

9-
static const char* glHandleResult(FFOpenGLResult* result)
9+
static void glHandleResult(FFOpenGLResult* result)
1010
{
1111
ffStrbufAppendS(&result->version, (const char*) glGetString(GL_VERSION));
1212
ffStrbufAppendS(&result->renderer, (const char*) glGetString(GL_RENDERER));
1313
ffStrbufAppendS(&result->vendor, (const char*) glGetString(GL_VENDOR));
1414
ffStrbufAppendS(&result->slv, (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
15-
result->library = "CGL";
16-
return NULL;
15+
16+
GLint major, minor;
17+
CGLGetVersion(&major, &minor);
18+
ffStrbufAppendF(&result->library, "CGL %d.%d", major, minor);
1719
}
1820

1921
static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj context)
2022
{
2123
if(CGLSetCurrentContext(context) != kCGLNoError)
2224
return "CGLSetCurrentContext() failed";
2325

24-
return glHandleResult(result);
26+
glHandleResult(result);
27+
28+
return NULL;
2529
}
2630

2731
static const char* cglHandlePixelFormat(FFOpenGLResult* result, CGLPixelFormatObj pixelFormat)

src/detection/opengl/opengl_linux.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ typedef struct GLData
1818
FF_LIBRARY_SYMBOL(glGetString)
1919
} GLData;
2020

21-
static const char* glHandleResult(FFOpenGLResult* result, const GLData* data, const char* library)
21+
static void glHandleResult(FFOpenGLResult* result, const GLData* data)
2222
{
2323
ffStrbufAppendS(&result->version, (const char*) data->ffglGetString(GL_VERSION));
2424
ffStrbufAppendS(&result->renderer, (const char*) data->ffglGetString(GL_RENDERER));
2525
ffStrbufAppendS(&result->vendor, (const char*) data->ffglGetString(GL_VENDOR));
2626
ffStrbufAppendS(&result->slv, (const char*) data->ffglGetString(GL_SHADING_LANGUAGE_VERSION));
27-
result->library = library;
28-
return NULL;
2927
}
3028

3129
#endif // FF_HAVE_GL
@@ -41,6 +39,7 @@ typedef struct EGLData
4139

4240
FF_LIBRARY_SYMBOL(eglGetProcAddress)
4341
FF_LIBRARY_SYMBOL(eglGetDisplay)
42+
FF_LIBRARY_SYMBOL(eglQueryString)
4443
FF_LIBRARY_SYMBOL(eglInitialize)
4544
FF_LIBRARY_SYMBOL(eglBindAPI)
4645
FF_LIBRARY_SYMBOL(eglGetConfigs)
@@ -62,7 +61,9 @@ static const char* eglHandleContext(FFOpenGLResult* result, EGLData* data)
6261
if(data->ffeglMakeCurrent(data->display, data->surface, data->surface, data->context) != EGL_TRUE)
6362
return "eglMakeCurrent returned EGL_FALSE";
6463

65-
return glHandleResult(result, &data->glData, "EGL");
64+
glHandleResult(result, &data->glData);
65+
ffStrbufSetF(&result->library, "EGL %s", data->ffeglQueryString(data->display, EGL_VERSION));
66+
return NULL;
6667
}
6768

6869
static const char* eglHandleSurface(FFOpenGLResult* result, EGLData* data)
@@ -126,6 +127,7 @@ static const char* eglPrint(FFOpenGLResult* result)
126127
FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1);
127128
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetProcAddress);
128129
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetDisplay);
130+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglQueryString);
129131
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglInitialize);
130132
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglBindAPI);
131133
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetConfigs);
@@ -150,6 +152,7 @@ typedef struct GLXData
150152
GLData glData;
151153

152154
FF_LIBRARY_SYMBOL(glXGetProcAddress)
155+
FF_LIBRARY_SYMBOL(glXQueryVersion)
153156
FF_LIBRARY_SYMBOL(XOpenDisplay)
154157
FF_LIBRARY_SYMBOL(glXChooseVisual)
155158
FF_LIBRARY_SYMBOL(XCreatePixmap);
@@ -173,8 +176,15 @@ static const char* glxHandleContext(FFOpenGLResult* result, GLXData* data)
173176
{
174177
if(data->ffglXMakeCurrent(data->display, data->glxPixmap, data->context) != True)
175178
return "glXMakeCurrent returned False";
179+
glHandleResult(result, &data->glData);
180+
181+
int major, minor;
182+
if (data->ffglXQueryVersion(data->display, &major, &minor))
183+
ffStrbufSetF(&result->library, "GLX %d.%d", major, minor);
184+
else
185+
ffStrbufSetStatic(&result->library, "GLX");
176186

177-
return glHandleResult(result, &data->glData, "GLX");
187+
return NULL;
178188
}
179189

180190
static const char* glxHandleGLXPixmap(FFOpenGLResult* result, GLXData* data)
@@ -242,6 +252,7 @@ static const char* glxPrint(FFOpenGLResult* result)
242252

243253
FF_LIBRARY_LOAD(glx, &instance.config.library.libGLX, "dlopen glx failed", "libGLX" FF_LIBRARY_EXTENSION, 1);
244254
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXGetProcAddress);
255+
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXQueryVersion);
245256
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XOpenDisplay);
246257
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXChooseVisual);
247258
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XCreatePixmap);
@@ -285,7 +296,9 @@ static const char* osMesaHandleContext(FFOpenGLResult* result, OSMesaData* data)
285296
if(data->ffOSMesaMakeCurrent(data->context, buffer, GL_UNSIGNED_BYTE, FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT) != GL_TRUE)
286297
return "OSMesaMakeCurrent returned GL_FALSE";
287298

288-
return glHandleResult(result, &data->glData, "OSMesa");
299+
glHandleResult(result, &data->glData);
300+
ffStrbufSetF(&result->library, "OSMesa %d.%d.%d", OSMESA_MAJOR_VERSION, OSMESA_MINOR_VERSION, OSMESA_PATCH_VERSION);
301+
return NULL;
289302
}
290303

291304
static const char* osMesaHandleData(FFOpenGLResult* result, OSMesaData* data)

src/detection/opengl/opengl_windows.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ typedef struct WGLData
1919
FF_LIBRARY_SYMBOL(wglDeleteContext)
2020
} WGLData;
2121

22-
static const char* glHandleResult(WGLData* wglData)
22+
static void glHandleResult(WGLData* wglData)
2323
{
2424
ffStrbufAppendS(&wglData->result->version, (const char*) wglData->ffglGetString(GL_VERSION));
2525
ffStrbufAppendS(&wglData->result->renderer, (const char*) wglData->ffglGetString(GL_RENDERER));
2626
ffStrbufAppendS(&wglData->result->vendor, (const char*) wglData->ffglGetString(GL_VENDOR));
2727
ffStrbufAppendS(&wglData->result->slv, (const char*) wglData->ffglGetString(GL_SHADING_LANGUAGE_VERSION));
28-
wglData->result->library = "WGL";
29-
return NULL;
28+
ffStrbufSetStatic(&wglData->result->library, "WGL 1.0");
3029
}
3130

3231
static const char* wglHandleContext(WGLData* wglData, HDC hdc, HGLRC context)
3332
{
3433
if(wglData->ffwglMakeCurrent(hdc, context) == FALSE)
3534
return "wglMakeCurrent() failed";
36-
return glHandleResult(wglData);
35+
glHandleResult(wglData);
36+
return NULL;
3737
}
3838

3939
static const char* wglHandlePixelFormat(WGLData* wglData, HWND hWnd)

src/modules/opengl/opengl.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
1313
ffStrbufInit(&result.renderer);
1414
ffStrbufInit(&result.vendor);
1515
ffStrbufInit(&result.slv);
16-
result.library = "Unknown";
16+
ffStrbufInit(&result.library);
1717

1818
const char* error = ffDetectOpenGL(options, &result);
1919
if(error)
@@ -34,14 +34,15 @@ void ffPrintOpenGL(FFOpenGLOptions* options)
3434
{FF_FORMAT_ARG_TYPE_STRBUF, &result.renderer, "renderer"},
3535
{FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor, "vendor"},
3636
{FF_FORMAT_ARG_TYPE_STRBUF, &result.slv, "slv"},
37-
{FF_FORMAT_ARG_TYPE_STRING, result.library, "library"},
37+
{FF_FORMAT_ARG_TYPE_STRBUF, &result.library, "library"},
3838
}));
3939
}
4040

4141
ffStrbufDestroy(&result.version);
4242
ffStrbufDestroy(&result.renderer);
4343
ffStrbufDestroy(&result.vendor);
4444
ffStrbufDestroy(&result.slv);
45+
ffStrbufDestroy(&result.library);
4546
}
4647

4748
bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, const char* value)
@@ -140,6 +141,7 @@ void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson
140141
ffStrbufInit(&result.renderer);
141142
ffStrbufInit(&result.vendor);
142143
ffStrbufInit(&result.slv);
144+
ffStrbufInit(&result.library);
143145

144146
const char* error = ffDetectOpenGL(options, &result);
145147
if(error != NULL)
@@ -153,13 +155,14 @@ void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson
153155
yyjson_mut_obj_add_strbuf(doc, obj, "renderer", &result.renderer);
154156
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &result.vendor);
155157
yyjson_mut_obj_add_strbuf(doc, obj, "slv", &result.slv);
156-
yyjson_mut_obj_add_str(doc, obj, "library", result.library);
158+
yyjson_mut_obj_add_strbuf(doc, obj, "library", &result.library);
157159
}
158160

159161
ffStrbufDestroy(&result.version);
160162
ffStrbufDestroy(&result.renderer);
161163
ffStrbufDestroy(&result.vendor);
162164
ffStrbufDestroy(&result.slv);
165+
ffStrbufDestroy(&result.library);
163166
}
164167

165168
void ffPrintOpenGLHelpFormat(void)

0 commit comments

Comments
 (0)