From 9018fda92e580b155f6b00d51cce2e2a3cf90d82 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 16 Feb 2025 22:52:51 +0800 Subject: [PATCH] OpenGL (Haiku): add support --- CMakeLists.txt | 3 ++- src/detection/opengl/opengl_haiku.cpp | 38 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/detection/opengl/opengl_haiku.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 73c421d1..1e698be6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1160,7 +1160,7 @@ elseif(Haiku) src/detection/memory/memory_haiku.c src/detection/mouse/mouse_haiku.cpp src/detection/netio/netio_haiku.cpp - src/detection/opengl/opengl_linux.c + src/detection/opengl/opengl_haiku.cpp src/detection/os/os_haiku.c src/detection/packages/packages_haiku.c src/detection/poweradapter/poweradapter_nosupport.c @@ -1650,6 +1650,7 @@ elseif(Haiku) PRIVATE "media" PRIVATE "device" PRIVATE "bluetooth" + PRIVATE "GL" PRIVATE "be" PRIVATE "gnu" ) diff --git a/src/detection/opengl/opengl_haiku.cpp b/src/detection/opengl/opengl_haiku.cpp new file mode 100644 index 00000000..504c47ce --- /dev/null +++ b/src/detection/opengl/opengl_haiku.cpp @@ -0,0 +1,38 @@ +#include + +extern "C" { +#include "opengl.h" +#include "common/io/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); + 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"; +}