From 26c56565cc0573ce23eb8d172a6765bce1f657ce Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 18 Apr 2025 12:55:00 +0200 Subject: Separate glx and egl from window system to prepare for wayland --- src/window/window.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/window/window.c') diff --git a/src/window/window.c b/src/window/window.c index 56df01a..a11bc15 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -1,5 +1,6 @@ #include "../../include/mgl/window/window.h" -#include "../../include/mgl/window/x11/window.h" +#include "../../include/mgl/window/x11.h" +#include "../../include/mgl/window/wayland.h" #include "../../include/mgl/mgl.h" #include @@ -8,12 +9,22 @@ #include int mgl_window_init(mgl_window *self, const char *title, const mgl_window_create_params *params, mgl_window_handle existing_window) { - // TODO: Handle |params->window_system| memset(self, 0, sizeof(*self)); self->vsync_enabled = true; self->key_repeat_enabled = true; mgl_clock_init(&self->frame_timer); - return mgl_x11_window_init(self, title, params, 0) ? 0 : -1; + + mgl_context *context = mgl_get_context(); + switch(context->window_system) { + case MGL_WINDOW_SYSTEM_NATIVE: + assert(false); + break; + case MGL_WINDOW_SYSTEM_X11: + return mgl_window_x11_init(self, title, params, existing_window) ? 0 : -1; + case MGL_WINDOW_SYSTEM_WAYLAND: + return mgl_window_wayland_init(self, title, params, existing_window) ? 0 : -1; + } + return -1; } int mgl_window_create(mgl_window *self, const char *title, const mgl_window_create_params *params) { @@ -25,10 +36,12 @@ int mgl_window_init_from_existing_window(mgl_window *self, mgl_window_handle exi } void mgl_window_deinit(mgl_window *self) { - mgl_x11_window_deinit(self); + if(self->deinit) + self->deinit(self); } void mgl_window_clear(mgl_window *self, mgl_color color) { + (void)self; mgl_context *context = mgl_get_context(); context->gl.glClearColor((float)color.r / 255.0f, (float)color.g / 255.0f, (float)color.b / 255.0f, (float)color.a / 255.0f); context->gl.glClear(GL_COLOR_BUFFER_BIT); -- cgit v1.2.3-70-g09d2