feat(glfw): allow to switch backend
This commit is contained in:
+29
-3
@@ -5,9 +5,12 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#include "constants.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...");
|
||||
|
||||
// set errors handler
|
||||
@@ -16,6 +19,28 @@ static void init_glfw(void (*error_callback)(int, const char *)) {
|
||||
// print current GLFW version
|
||||
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
|
||||
if (!glfwInit()) {
|
||||
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); }
|
||||
|
||||
void window_startup(void (*error_callback)(int, const char *)) {
|
||||
init_glfw(error_callback);
|
||||
void window_startup(void (*error_callback)(int, const char *),
|
||||
const unsigned int backend) {
|
||||
init_glfw(error_callback, backend);
|
||||
}
|
||||
|
||||
void window_terminate() {
|
||||
|
||||
Reference in New Issue
Block a user