mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:14:37 +02:00
OpenGL (Windows): remove hard dep of opengl32
Ref: https://github.com/fastfetch-cli/fastfetch/issues/623#issuecomment-1815682290
This commit is contained in:
@@ -896,7 +896,6 @@ elseif(WIN32)
|
||||
PRIVATE "iphlpapi"
|
||||
PRIVATE "ole32"
|
||||
PRIVATE "oleaut32"
|
||||
PRIVATE "opengl32"
|
||||
PRIVATE "ws2_32"
|
||||
PRIVATE "ntdll"
|
||||
PRIVATE "version"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "opengl.h"
|
||||
#include "common/library.h"
|
||||
#include "common/printing.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <GL/gl.h>
|
||||
@@ -8,23 +8,34 @@
|
||||
#define GL_SHADING_LANGUAGE_VERSION 0x8B8C
|
||||
#endif
|
||||
|
||||
static const char* glHandleResult(FFOpenGLResult* result)
|
||||
typedef struct WGLData
|
||||
{
|
||||
ffStrbufAppendS(&result->version, (const char*) glGetString(GL_VERSION));
|
||||
ffStrbufAppendS(&result->renderer, (const char*) glGetString(GL_RENDERER));
|
||||
ffStrbufAppendS(&result->vendor, (const char*) glGetString(GL_VENDOR));
|
||||
ffStrbufAppendS(&result->slv, (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
FFOpenGLResult* result;
|
||||
const char* error;
|
||||
|
||||
FF_LIBRARY_SYMBOL(glGetString)
|
||||
FF_LIBRARY_SYMBOL(wglMakeCurrent)
|
||||
FF_LIBRARY_SYMBOL(wglCreateContext)
|
||||
FF_LIBRARY_SYMBOL(wglDeleteContext)
|
||||
} WGLData;
|
||||
|
||||
static const char* glHandleResult(WGLData* wglData)
|
||||
{
|
||||
ffStrbufAppendS(&wglData->result->version, (const char*) wglData->ffglGetString(GL_VERSION));
|
||||
ffStrbufAppendS(&wglData->result->renderer, (const char*) wglData->ffglGetString(GL_RENDERER));
|
||||
ffStrbufAppendS(&wglData->result->vendor, (const char*) wglData->ffglGetString(GL_VENDOR));
|
||||
ffStrbufAppendS(&wglData->result->slv, (const char*) wglData->ffglGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* wglHandleContext(FFOpenGLResult* result, HDC hdc, HGLRC context)
|
||||
static const char* wglHandleContext(WGLData* wglData, HDC hdc, HGLRC context)
|
||||
{
|
||||
if(wglMakeCurrent(hdc, context) == FALSE)
|
||||
if(wglData->ffwglMakeCurrent(hdc, context) == FALSE)
|
||||
return "wglMakeCurrent() failed";
|
||||
return glHandleResult(result);
|
||||
return glHandleResult(wglData);
|
||||
}
|
||||
|
||||
const char* wglHandlePixelFormat(FFOpenGLResult* result, HWND hWnd)
|
||||
static const char* wglHandlePixelFormat(WGLData* wglData, HWND hWnd)
|
||||
{
|
||||
PIXELFORMATDESCRIPTOR pfd =
|
||||
{
|
||||
@@ -51,29 +62,23 @@ const char* wglHandlePixelFormat(FFOpenGLResult* result, HWND hWnd)
|
||||
if(SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd) == FALSE)
|
||||
return "SetPixelFormat() failed";
|
||||
|
||||
HGLRC context = wglCreateContext(hdc);
|
||||
HGLRC context = wglData->ffwglCreateContext(hdc);
|
||||
if(context == NULL)
|
||||
return "wglCreateContext() failed";
|
||||
|
||||
const char* error = wglHandleContext(result, hdc, context);
|
||||
wglDeleteContext(context);
|
||||
const char* error = wglHandleContext(wglData, hdc, context);
|
||||
wglData->ffwglDeleteContext(context);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
typedef struct WGLData
|
||||
{
|
||||
FFOpenGLResult* result;
|
||||
const char* error;
|
||||
} WGLData;
|
||||
|
||||
LRESULT CALLBACK wglHandleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
static LRESULT CALLBACK wglHandleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch(message)
|
||||
{
|
||||
case WM_CREATE: {
|
||||
WGLData* wglData = (WGLData*)((CREATESTRUCT*)lParam)->lpCreateParams;
|
||||
wglData->error = wglHandlePixelFormat(wglData->result, hWnd);
|
||||
wglData->error = wglHandlePixelFormat(wglData, hWnd);
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
}
|
||||
@@ -84,6 +89,15 @@ LRESULT CALLBACK wglHandleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
|
||||
|
||||
const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLResult* result)
|
||||
{
|
||||
FF_LIBRARY_LOAD(opengl32, NULL, "dlopen opengl32" FF_LIBRARY_EXTENSION " failed", "opengl32" FF_LIBRARY_EXTENSION, 1);
|
||||
|
||||
WGLData data = { .result = result };
|
||||
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, glGetString);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, wglMakeCurrent);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, wglCreateContext);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(opengl32, data, wglDeleteContext);
|
||||
|
||||
MSG msg = {0};
|
||||
WNDCLASSW wc = {
|
||||
.lpfnWndProc = wglHandleWndProc,
|
||||
@@ -95,7 +109,6 @@ const char* ffDetectOpenGL(FF_MAYBE_UNUSED FFOpenGLOptions* options, FFOpenGLRes
|
||||
if(!RegisterClassW(&wc))
|
||||
return "RegisterClassW() failed";
|
||||
|
||||
WGLData data = { .result = result };
|
||||
HWND hWnd = CreateWindowW(wc.lpszClassName, L"ogl_version_check", 0, 0, 0, 1, 1, NULL, NULL, NULL, &data);
|
||||
|
||||
while(GetMessageW(&msg, hWnd, 0, 0) > 0)
|
||||
|
||||
Reference in New Issue
Block a user