Skip to content

Commit 4777f7b

Browse files
committed
OpenGL (Windows): support EGL via ANGLE
1 parent 1038668 commit 4777f7b

File tree

10 files changed

+210
-197
lines changed

10 files changed

+210
-197
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "LINUX OR B
6161
cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "LINUX OR BSD OR APPLE OR SunOS" OFF)
6262
cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF)
6363
cmake_dependent_option(ENABLE_ZLIB "Enable zlib" ON "ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7" OFF)
64-
cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR BSD OR SunOS" OFF)
64+
cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR BSD OR WIN32 OR SunOS" OFF)
6565
cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR BSD OR SunOS" OFF)
6666
cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR BSD OR SunOS" OFF)
6767
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD OR WIN32 OR ANDROID OR SunOS" OFF)
@@ -307,6 +307,7 @@ set(LIBFASTFETCH_SRC
307307
src/detection/media/media.c
308308
src/detection/netio/netio.c
309309
src/detection/opencl/opencl.c
310+
src/detection/opengl/opengl_shared.c
310311
src/detection/os/os.c
311312
src/detection/packages/packages.c
312313
src/detection/physicalmemory/physicalmemory.c

src/detection/opengl/opengl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ typedef struct FFOpenGLResult
1111
FFstrbuf library;
1212
} FFOpenGLResult;
1313

14+
#define FF_OPENGL_BUFFER_WIDTH 1
15+
#define FF_OPENGL_BUFFER_HEIGHT 1
16+
1417
const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result);

src/detection/opengl/opengl_apple.c

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

9-
static void glHandleResult(FFOpenGLResult* result)
10-
{
11-
ffStrbufAppendS(&result->version, (const char*) glGetString(GL_VERSION));
12-
ffStrbufAppendS(&result->renderer, (const char*) glGetString(GL_RENDERER));
13-
ffStrbufAppendS(&result->vendor, (const char*) glGetString(GL_VENDOR));
14-
ffStrbufAppendS(&result->slv, (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
15-
16-
GLint major, minor;
17-
CGLGetVersion(&major, &minor);
18-
ffStrbufAppendF(&result->library, "CGL %d.%d", major, minor);
19-
}
9+
void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString);
2010

2111
static const char* cglHandleContext(FFOpenGLResult* result, CGLContextObj context)
2212
{
2313
if(CGLSetCurrentContext(context) != kCGLNoError)
2414
return "CGLSetCurrentContext() failed";
2515

26-
glHandleResult(result);
16+
ffOpenGLHandleResult(result, &glGetString);
17+
18+
GLint major, minor;
19+
CGLGetVersion(&major, &minor);
20+
ffStrbufSetF(&result->library, "CGL %d.%d", major, minor);
2721

2822
return NULL;
2923
}

src/detection/opengl/opengl_linux.c

Lines changed: 18 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -10,147 +10,17 @@
1010

1111
#include <GL/gl.h>
1212

13-
#define FF_OPENGL_BUFFER_WIDTH 1
14-
#define FF_OPENGL_BUFFER_HEIGHT 1
15-
16-
typedef struct GLData
17-
{
18-
FF_LIBRARY_SYMBOL(glGetString)
19-
} GLData;
20-
21-
static void glHandleResult(FFOpenGLResult* result, const GLData* data)
22-
{
23-
ffStrbufAppendS(&result->version, (const char*) data->ffglGetString(GL_VERSION));
24-
ffStrbufAppendS(&result->renderer, (const char*) data->ffglGetString(GL_RENDERER));
25-
ffStrbufAppendS(&result->vendor, (const char*) data->ffglGetString(GL_VENDOR));
26-
ffStrbufAppendS(&result->slv, (const char*) data->ffglGetString(GL_SHADING_LANGUAGE_VERSION));
27-
}
13+
void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString);
2814

2915
#endif // FF_HAVE_GL
3016

31-
#ifdef FF_HAVE_EGL
32-
#include "common/io/io.h"
33-
34-
#include <EGL/egl.h>
35-
36-
typedef struct EGLData
37-
{
38-
GLData glData;
39-
40-
FF_LIBRARY_SYMBOL(eglGetProcAddress)
41-
FF_LIBRARY_SYMBOL(eglGetDisplay)
42-
FF_LIBRARY_SYMBOL(eglQueryString)
43-
FF_LIBRARY_SYMBOL(eglInitialize)
44-
FF_LIBRARY_SYMBOL(eglBindAPI)
45-
FF_LIBRARY_SYMBOL(eglGetConfigs)
46-
FF_LIBRARY_SYMBOL(eglCreatePbufferSurface)
47-
FF_LIBRARY_SYMBOL(eglCreateContext)
48-
FF_LIBRARY_SYMBOL(eglMakeCurrent)
49-
FF_LIBRARY_SYMBOL(eglDestroyContext)
50-
FF_LIBRARY_SYMBOL(eglDestroySurface)
51-
FF_LIBRARY_SYMBOL(eglTerminate)
52-
53-
EGLDisplay display;
54-
EGLConfig config;
55-
EGLSurface surface;
56-
EGLContext context;
57-
} EGLData;
58-
59-
static const char* eglHandleContext(FFOpenGLResult* result, EGLData* data)
60-
{
61-
if(data->ffeglMakeCurrent(data->display, data->surface, data->surface, data->context) != EGL_TRUE)
62-
return "eglMakeCurrent returned EGL_FALSE";
63-
64-
glHandleResult(result, &data->glData);
65-
ffStrbufSetF(&result->library, "EGL %s", data->ffeglQueryString(data->display, EGL_VERSION));
66-
return NULL;
67-
}
68-
69-
static const char* eglHandleSurface(FFOpenGLResult* result, EGLData* data)
70-
{
71-
data->context = data->ffeglCreateContext(data->display, data->config, EGL_NO_CONTEXT, (EGLint[]){EGL_NONE});
72-
if(data->context == EGL_NO_CONTEXT)
73-
return "eglCreateContext returned EGL_NO_CONTEXT";
74-
75-
const char* error = eglHandleContext(result, data);
76-
data->ffeglDestroyContext(data->display, data->context);
77-
return error;
78-
}
79-
80-
static const char* eglHandleDisplay(FFOpenGLResult* result, EGLData* data)
81-
{
82-
if(data->ffeglBindAPI(EGL_OPENGL_API) != EGL_TRUE)
83-
return "eglBindAPI returned EGL_FALSE";
84-
85-
EGLint eglConfigCount;
86-
data->ffeglGetConfigs(data->display, &data->config, 1, &eglConfigCount);
87-
if(eglConfigCount == 0)
88-
return "eglGetConfigs returned 0 configs";
89-
90-
data->surface = data->ffeglCreatePbufferSurface(data->display, data->config, (EGLint[]){
91-
EGL_WIDTH, FF_OPENGL_BUFFER_WIDTH,
92-
EGL_HEIGHT, FF_OPENGL_BUFFER_HEIGHT,
93-
EGL_NONE
94-
});
95-
96-
if(data->surface == EGL_NO_SURFACE)
97-
return "eglCreatePbufferSurface returned EGL_NO_SURFACE";
98-
99-
const char* error = eglHandleSurface(result, data);
100-
data->ffeglDestroySurface(data->display, data->surface);
101-
return error;
102-
}
103-
104-
static const char* eglHandleData(FFOpenGLResult* result, EGLData* data)
105-
{
106-
data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) data->ffeglGetProcAddress("glGetString");
107-
if(!data->glData.ffglGetString)
108-
return "eglGetProcAddress(glGetString) returned NULL";
109-
110-
data->display = data->ffeglGetDisplay(EGL_DEFAULT_DISPLAY);
111-
if(data->display == EGL_NO_DISPLAY)
112-
return "eglGetDisplay returned EGL_NO_DISPLAY";
113-
114-
EGLint major, minor;
115-
if(data->ffeglInitialize(data->display, &major, &minor) == EGL_FALSE)
116-
return "eglInitialize returned EGL_FALSE";
117-
118-
const char* error = eglHandleDisplay(result, data);
119-
data->ffeglTerminate(data->display);
120-
return error;
121-
}
122-
123-
static const char* eglPrint(FFOpenGLResult* result)
124-
{
125-
EGLData eglData;
126-
127-
FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1);
128-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetProcAddress);
129-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetDisplay);
130-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglQueryString);
131-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglInitialize);
132-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglBindAPI);
133-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetConfigs);
134-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglCreatePbufferSurface);
135-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglCreateContext);
136-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglMakeCurrent);
137-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglDestroyContext);
138-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglDestroySurface);
139-
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglTerminate);
140-
141-
FF_SUPPRESS_IO();
142-
return eglHandleData(result, &eglData);
143-
}
144-
145-
#endif //FF_HAVE_EGL
14617

14718
#ifdef FF_HAVE_GLX
14819
#include <GL/glx.h>
14920

15021
typedef struct GLXData
15122
{
152-
GLData glData;
153-
23+
FF_LIBRARY_SYMBOL(glGetString)
15424
FF_LIBRARY_SYMBOL(glXGetProcAddress)
15525
FF_LIBRARY_SYMBOL(glXQueryVersion)
15626
FF_LIBRARY_SYMBOL(XOpenDisplay)
@@ -176,7 +46,7 @@ static const char* glxHandleContext(FFOpenGLResult* result, GLXData* data)
17646
{
17747
if(data->ffglXMakeCurrent(data->display, data->glxPixmap, data->context) != True)
17848
return "glXMakeCurrent returned False";
179-
glHandleResult(result, &data->glData);
49+
ffOpenGLHandleResult(result, data->ffglGetString);
18050

18151
int major, minor;
18252
if (data->ffglXQueryVersion(data->display, &major, &minor))
@@ -233,8 +103,8 @@ static const char* glxHandleDisplay(FFOpenGLResult* result, GLXData* data)
233103

234104
static const char* glxHandleData(FFOpenGLResult* result, GLXData* data)
235105
{
236-
data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) data->ffglXGetProcAddress((const GLubyte*) "glGetString");
237-
if(data->glData.ffglGetString == NULL)
106+
data->ffglGetString = (__typeof__(data->ffglGetString)) data->ffglXGetProcAddress((const GLubyte*) "glGetString");
107+
if(data->ffglGetString == NULL)
238108
return "glXGetProcAddress(glGetString) returned NULL";
239109

240110
data->display = data->ffXOpenDisplay(NULL);
@@ -246,7 +116,7 @@ static const char* glxHandleData(FFOpenGLResult* result, GLXData* data)
246116
return error;
247117
}
248118

249-
static const char* glxPrint(FFOpenGLResult* result)
119+
static const char* detectByGlx(FFOpenGLResult* result)
250120
{
251121
GLXData data;
252122

@@ -279,8 +149,7 @@ static const char* glxPrint(FFOpenGLResult* result)
279149

280150
typedef struct OSMesaData
281151
{
282-
GLData glData;
283-
152+
FF_LIBRARY_SYMBOL(glGetString)
284153
FF_LIBRARY_SYMBOL(OSMesaGetProcAddress)
285154
FF_LIBRARY_SYMBOL(OSMesaCreateContext)
286155
FF_LIBRARY_SYMBOL(OSMesaMakeCurrent)
@@ -296,16 +165,15 @@ static const char* osMesaHandleContext(FFOpenGLResult* result, OSMesaData* data)
296165
if(data->ffOSMesaMakeCurrent(data->context, buffer, GL_UNSIGNED_BYTE, FF_OPENGL_BUFFER_WIDTH, FF_OPENGL_BUFFER_HEIGHT) != GL_TRUE)
297166
return "OSMesaMakeCurrent returned GL_FALSE";
298167

299-
glHandleResult(result, &data->glData);
168+
ffOpenGLHandleResult(result, data->ffglGetString);
300169
ffStrbufSetF(&result->library, "OSMesa %d.%d.%d", OSMESA_MAJOR_VERSION, OSMESA_MINOR_VERSION, OSMESA_PATCH_VERSION);
301170
return NULL;
302171
}
303172

304173
static const char* osMesaHandleData(FFOpenGLResult* result, OSMesaData* data)
305174
{
306-
//The case to void* is required here, because OSMESAproc can't be cast to (__typeof__(data->glData.ffglGetString)) without a warning, even though it is the actual type.
307-
data->glData.ffglGetString = (__typeof__(data->glData.ffglGetString)) (void*) data->ffOSMesaGetProcAddress("glGetString");
308-
if(data->glData.ffglGetString == NULL)
175+
data->ffglGetString = (void*) data->ffOSMesaGetProcAddress("glGetString");
176+
if(data->ffglGetString == NULL)
309177
return "OSMesaGetProcAddress(glGetString) returned NULL";
310178

311179
data->context = data->ffOSMesaCreateContext(OSMESA_RGBA, NULL);
@@ -317,7 +185,7 @@ static const char* osMesaHandleData(FFOpenGLResult* result, OSMesaData* data)
317185
return error;
318186
}
319187

320-
static const char* osMesaPrint(FFOpenGLResult* result)
188+
static const char* detectByOsMesa(FFOpenGLResult* result)
321189
{
322190
OSMesaData data;
323191

@@ -339,7 +207,7 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result)
339207
if(options->library == FF_OPENGL_LIBRARY_GLX)
340208
{
341209
#ifdef FF_HAVE_GLX
342-
return glxPrint(result);
210+
return detectByGlx(result);
343211
#else
344212
return "fastfetch was compiled without glx support";
345213
#endif
@@ -348,7 +216,8 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result)
348216
if(options->library == FF_OPENGL_LIBRARY_EGL)
349217
{
350218
#ifdef FF_HAVE_EGL
351-
return eglPrint(result);
219+
const char* ffOpenGLDetectByEGL(FFOpenGLResult* result);
220+
return ffOpenGLDetectByEGL(result);
352221
#else
353222
return "fastfetch was compiled without egl support";
354223
#endif
@@ -357,7 +226,7 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result)
357226
if(options->library == FF_OPENGL_LIBRARY_OSMESA)
358227
{
359228
#ifdef FF_HAVE_OSMESA
360-
return osMesaPrint(result);
229+
return detectByOsMesa(result);
361230
#else
362231
return "fastfetch was compiled without osmesa support";
363232
#endif
@@ -366,12 +235,13 @@ const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result)
366235
const char* error = ""; // not NULL dummy value
367236

368237
#ifdef FF_HAVE_EGL
369-
error = eglPrint(result);
238+
const char* ffOpenGLDetectByEGL(FFOpenGLResult* result);
239+
error = ffOpenGLDetectByEGL(result);
370240
#endif
371241

372242
#ifdef FF_HAVE_GLX
373243
if(error != NULL)
374-
error = glxPrint(result);
244+
error = detectByGlx(result);
375245
#endif
376246

377247
//We don't use osmesa in auto mode here, because it is a software implementation,

0 commit comments

Comments
 (0)