summaryrefslogtreecommitdiffstats
path: root/src/detection/opengl/opengl_haiku.cpp
blob: 64a21a0d5968db2573aeb94d051a4b0145ccdeac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <OpenGLKit.h>

extern "C" {
#include "opengl.h"
#include "common/io.h"
#if FF_HAVE_EGL
const char* ffOpenGLDetectByEGL(FFOpenGLResult* result);
#endif
void ffOpenGLHandleResult(FFOpenGLResult* result, __typeof__(&glGetString) ffglGetString);
}

static const char* oglDetectOpenGL(FFOpenGLResult* result) {
    BApplication app("application/x-vnd.fastfetch-cli-fastfetch");
    FF_SUPPRESS_IO();

    BGLView glView(BRect(), "ff_ogl_view", B_FOLLOW_NONE, B_WILL_DRAW, BGL_RGB);
    auto ffglGetString = (decltype(&glGetString)) glView.GetGLProcAddress("glGetString");
    if (!ffglGetString) {
        return "glView.GetGLProcAddress() failed";
    }
    ffOpenGLHandleResult(result, ffglGetString);
    ffStrbufSetStatic(&result->library, "OpenGLKit");
    return NULL;
}

const char* ffDetectOpenGL(FFOpenGLOptions* options, FFOpenGLResult* result) {
    if (options->library == FF_OPENGL_LIBRARY_AUTO) {
        return oglDetectOpenGL(result);
    } else if (options->library == FF_OPENGL_LIBRARY_EGL) {
#if FF_HAVE_EGL
        return ffOpenGLDetectByEGL(result);
#else
        return "fastfetch was compiled without egl support";
#endif
    } else {
        return "Unsupported OpenGL library";
    }
}