feat(glfw): allow to switch backend

This commit is contained in:
2026-08-21 23:17:21 +02:00
parent 519a9b88f4
commit 192cf571b1
6 changed files with 58 additions and 6 deletions
+20 -1
View File
@@ -7,6 +7,8 @@
#include "types.h" #include "types.h"
#include "constants.h"
#include "args.h" #include "args.h"
#include "config.h" #include "config.h"
#include "string.h" #include "string.h"
@@ -42,6 +44,10 @@ static void print_help(int status_code) {
"[-mr / -nmr] " "[-mr / -nmr] "
"[-tm] " "[-tm] "
"[-tf] " "[-tf] "
"[--x11] "
"[--wayland] "
"[--cocoa] "
"[--win32] "
"\n\n" "\n\n"
"Fusion Of Real-time Generative Effects.\n\n" "Fusion Of Real-time Generative Effects.\n\n"
"options:\n" "options:\n"
@@ -81,7 +87,11 @@ static void print_help(int status_code) {
" -mr, --midi-reconnect auto-reconnect midi (default)\n" " -mr, --midi-reconnect auto-reconnect midi (default)\n"
" -nmr, --no-midi-reconnect do not auto-reconnect midi\n" " -nmr, --no-midi-reconnect do not auto-reconnect midi\n"
" -tm, --trace-midi print midi code and values\n" " -tm, --trace-midi print midi code and values\n"
" -tf, --trace-fps print fps status of subsystems\n"); " -tf, --trace-fps print fps status of subsystems\n"
" --x11 force X11 GLFW backend\n"
" --wayland force Wayland GLFW backend\n"
" --cocoa force Cocoa GLFW backend\n"
" --win32 force Win32 GLFW backend\n");
exit(status_code); exit(status_code);
} }
@@ -152,6 +162,7 @@ void args_parse(Parameters *params, int argc, char **argv) {
params->midi_reconnect = true; params->midi_reconnect = true;
params->trace_midi = false; params->trace_midi = false;
params->trace_fps = false; params->trace_fps = false;
params->glfw_backend = GLFW_BACKEND_ANY;
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
arg = argv[i]; arg = argv[i];
@@ -220,6 +231,14 @@ void args_parse(Parameters *params, int argc, char **argv) {
params->trace_midi = true; params->trace_midi = true;
} else if (is_arg(arg, "-tf") || is_arg(arg, "--trace-fps")) { } else if (is_arg(arg, "-tf") || is_arg(arg, "--trace-fps")) {
params->trace_fps = true; params->trace_fps = true;
} else if (is_arg(arg, "--x11")) {
params->glfw_backend = GLFW_BACKEND_X11;
} else if (is_arg(arg, "--wayland")) {
params->glfw_backend = GLFW_BACKEND_WAYLAND;
} else if (is_arg(arg, "--cocoa")) {
params->glfw_backend = GLFW_BACKEND_COCOA;
} else if (is_arg(arg, "--win32")) {
params->glfw_backend = GLFW_BACKEND_WIN32;
} else { } else {
#ifdef VIDEO_IN #ifdef VIDEO_IN
if (is_arg(arg, "-vi") || is_arg(arg, "--video-in")) { if (is_arg(arg, "-vi") || is_arg(arg, "--video-in")) {
+6
View File
@@ -3,6 +3,12 @@
#ifndef CONSTANTS_H #ifndef CONSTANTS_H
#define CONSTANTS_H #define CONSTANTS_H
static const unsigned int GLFW_BACKEND_ANY = 0;
static const unsigned int GLFW_BACKEND_X11 = 1;
static const unsigned int GLFW_BACKEND_WAYLAND = 2;
static const unsigned int GLFW_BACKEND_COCOA = 3;
static const unsigned int GLFW_BACKEND_WIN32 = 4;
static const char *vertex_shader_text = static const char *vertex_shader_text =
"#version 460\n" "#version 460\n"
"const mat4 mvp = " "const mat4 mvp = "
+1 -1
View File
@@ -286,7 +286,7 @@ static bool init(const Parameters *params) {
start_state_background_write(); start_state_background_write();
window_startup(error_callback); window_startup(error_callback, params->glfw_backend);
context.tex_resolution[0] = params->internal_size; context.tex_resolution[0] = params->internal_size;
context.tex_resolution[1] = params->internal_size; context.tex_resolution[1] = params->internal_size;
+1
View File
@@ -58,6 +58,7 @@ typedef struct Parameters {
bool midi_reconnect; bool midi_reconnect;
bool trace_midi; bool trace_midi;
bool trace_fps; bool trace_fps;
unsigned int glfw_backend;
} Parameters; } Parameters;
// file.c // file.c
+29 -3
View File
@@ -5,9 +5,12 @@
#include "types.h" #include "types.h"
#include "constants.h"
#include "window.h" #include "window.h"
static void init_glfw(void (*error_callback)(int, const char *)) { static void init_glfw(void (*error_callback)(int, const char *),
const unsigned int backend) {
log_info("[GLFW] Initializing..."); log_info("[GLFW] Initializing...");
// set errors handler // set errors handler
@@ -16,6 +19,28 @@ static void init_glfw(void (*error_callback)(int, const char *)) {
// print current GLFW version // print current GLFW version
log_info("[GLFW] %s", glfwGetVersionString()); log_info("[GLFW] %s", glfwGetVersionString());
switch (backend) {
case GLFW_BACKEND_X11:
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
log_info("[GLFW] platform: X11");
break;
case GLFW_BACKEND_WAYLAND:
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
log_info("[GLFW] platform: Wayland");
break;
case GLFW_BACKEND_COCOA:
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_COCOA);
log_info("[GLFW] platform: Cocoa");
break;
case GLFW_BACKEND_WIN32:
glfwInitHint(GLFW_PLATFORM, GLFW_BACKEND_WIN32);
log_info("[GLFW] platform: Win32");
break;
default:
log_info("[GLFW] platform: Any");
break;
}
// init GLFW // init GLFW
if (!glfwInit()) { if (!glfwInit()) {
log_error("[GLFW] Initialization failed"); log_error("[GLFW] Initialization failed");
@@ -86,8 +111,9 @@ create_window(GLFWmonitor *monitor, const char *title, Window *shared_context,
static void use_window(GLFWwindow *window) { glfwMakeContextCurrent(window); } static void use_window(GLFWwindow *window) { glfwMakeContextCurrent(window); }
void window_startup(void (*error_callback)(int, const char *)) { void window_startup(void (*error_callback)(int, const char *),
init_glfw(error_callback); const unsigned int backend) {
init_glfw(error_callback, backend);
} }
void window_terminate() { void window_terminate() {
+1 -1
View File
@@ -3,7 +3,7 @@
#ifndef WINDOW_H #ifndef WINDOW_H
#define WINDOW_H #define WINDOW_H
void window_startup(void (*error_callback)(int, const char *)); void window_startup(void (*error_callback)(int, const char *), const unsigned int backend);
void window_terminate(); void window_terminate();