master ohmu/fastfetch-openbsd / src / detection / opengl / opengl_haiku.cpp
ohmu  ·  2026-10-15
 1#include <OpenGLKit.h>
 2
 3extern "C" {
 4#include "opengl.h"
 5#include "common/debug.h"
 6#include "common/io.h"
 7#if FF_HAVE_EGL
 8const char* ffOpenGLDetectByEGL(FFOpenGLResult* result);
 9#endif
10void ffOpenGLHandleResult(FFOpenGLResult* result, typeof(&glGetString) ffglGetString);
11}
12
13static const char* oglDetectOpenGL(FFOpenGLResult* result) {
14    BApplication app("application/x-vnd.fastfetch-cli-fastfetch");
15    FF_SUPPRESS_IO();
16
17    BGLView glView(BRect(), "ff_ogl_view", B_FOLLOW_NONE, B_WILL_DRAW, BGL_RGB);
18    auto ffglGetString = (decltype(&glGetString)) glView.GetGLProcAddress("glGetString");
19    if (!ffglGetString) {
20        FF_DEBUG("glView.GetGLProcAddress(glGetString) returned null");
21        return "glView.GetGLProcAddress() failed";
22    }
23    ffOpenGLHandleResult(result, ffglGetString);
24    ffStrbufSetStatic(&result->library, "OpenGLKit");
25    return nullptr;
26}
27
28const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) {
29    if (options->library == FF_OPENGL_LIBRARY_AUTO) {
30        return oglDetectOpenGL(result);
31    } else if (options->library == FF_OPENGL_LIBRARY_EGL) {
32#if FF_HAVE_EGL
33        return ffOpenGLDetectByEGL(result);
34#else
35        return "fastfetch was compiled without egl support";
36#endif
37    } else {
38        FF_DEBUG("Unsupported OpenGL library requested: %d", (int) options->library);
39        return "Unsupported OpenGL library";
40    }
41}