From 247e0b361c6f3a731ba29f5e511a83cbe38c051d Mon Sep 17 00:00:00 2001 From: IoIxD Date: Wed, 3 Dec 2025 23:00:40 -0700 Subject: [PATCH] introduce MwLLEndDraw, which can be stubbed safely on any platforms and exists purely for wayland to be able to swap buffers at a better time --- include/Mw/LowLevel.h | 1 + src/backend/call.c | 1 + src/backend/gdi.c | 2 ++ src/backend/wayland.c | 49 +++++++++++++++++++------------------------ src/backend/x11.c | 2 ++ src/core.c | 2 ++ src/lowlevel.c | 2 ++ 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index 49c1cc7..2be5b26 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -164,6 +164,7 @@ MWDECL void (*MwLLDestroy)(MwLL handle); MWDECL void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color); MWDECL void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color); +MWDECL void (*MwLLEndDraw)(MwLL handle); MWDECL MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b); MWDECL void (*MwLLColorUpdate)(MwLL handle, MwLLColor c, int r, int g, int b); diff --git a/src/backend/call.c b/src/backend/call.c index de4b7f0..2c8f399 100644 --- a/src/backend/call.c +++ b/src/backend/call.c @@ -11,6 +11,7 @@ \ MwLLPolygon = MwLLPolygonImpl; \ MwLLLine = MwLLLineImpl; \ + MwLLEndDraw = MwLLEndDrawImpl; \ \ MwLLAllocColor = MwLLAllocColorImpl; \ MwLLColorUpdate = MwLLColorUpdateImpl; \ diff --git a/src/backend/gdi.c b/src/backend/gdi.c index b40c26e..23c2dd3 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -278,6 +278,8 @@ static void MwLLDestroyImpl(MwLL handle) { free(handle); } +static void MwLLEndDrawImpl(MwLL handle) {} + static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { POINT* p = malloc(sizeof(*p) * points_count); HPEN pen = CreatePen(PS_NULL, 0, RGB(0, 0, 0)); diff --git a/src/backend/wayland.c b/src/backend/wayland.c index bfedd17..fd8c6bc 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -255,6 +255,7 @@ static MwBool egl_setup(MwLL self, int width, int height) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, height, 0, -1, 1); + glEnable(GL_TEXTURE_2D); self->wayland.egl_display = display; self->wayland.egl_surface = surface; @@ -556,31 +557,11 @@ static void MwLLSetWHImpl(MwLL handle, int w, int h) { } static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { - /* - * TODO: this function sucks shit, ioi needs to make it not suck shit :) - */ - int i; - PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)eglGetProcAddress("glBindFramebuffer"); - PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)eglGetProcAddress("glBindRenderbuffer"); - int w, h; + int i; - if(handle->wayland.type == MWLL_WAYLAND_TOPLEVEL) { - w = handle->wayland.ww; - h = handle->wayland.wh; - } else { - MwLL parent = handle->wayland.parent; - while(parent->wayland.type != MWLL_WAYLAND_TOPLEVEL) { - parent = parent->wayland.parent; - } - w = parent->wayland.ww; - h = parent->wayland.wh; - } - - glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); glBindFramebuffer(GL_FRAMEBUFFER, handle->wayland.fbo); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, handle->wayland.fbo_texture, 0); - glLineWidth(1); if(points_count == 3) { glBegin(GL_TRIANGLES); @@ -598,9 +579,26 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL } glEnd(); glFinish(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); +} + +static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { + // +} + +static void MwLLEndDrawImpl(MwLL handle) { + int w, h; + + if(handle->wayland.type == MWLL_WAYLAND_TOPLEVEL) { + w = handle->wayland.ww; + h = handle->wayland.wh; + } else { + MwLL parent = handle->wayland.parent; + w = parent->wayland.ww; + h = parent->wayland.wh; + } glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture); - glBindFramebuffer(GL_FRAMEBUFFER, 0); glClear(GL_COLOR_BUFFER_BIT); glClearColor(0, 0, 0, 1); @@ -618,17 +616,12 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL glEnd(); glFinish(); + wl_surface_damage(handle->wayland.surface, 0, 0, handle->wayland.ww, handle->wayland.wh); if(!eglSwapBuffers(handle->wayland.egl_display, handle->wayland.egl_surface)) { printf("error swapping buffers! %0X\n", eglGetError()); } else { wl_surface_commit(handle->wayland.surface); } - glDisable(GL_TEXTURE_2D); - handle->wayland.do_clear = MwFALSE; -} - -static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { - // } static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) { diff --git a/src/backend/x11.c b/src/backend/x11.c index ec50ad2..6e2426a 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -256,6 +256,8 @@ static void MwLLDestroyImpl(MwLL handle) { free(handle); } +static void MwLLEndDrawImpl(MwLL handle) {} + static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { int i; XPoint* p = malloc(sizeof(*p) * points_count); diff --git a/src/core.c b/src/core.c index cb7c6fd..401600d 100644 --- a/src/core.c +++ b/src/core.c @@ -334,6 +334,8 @@ void MwLoop(MwWidget handle) { } if(v != 0) break; + MwLLEndDraw(handle->lowlevel); + for(i = 0; i < arrlen(handle->tick_list); i++) { MwDispatch(handle->tick_list[i], tick); MwDispatchUserHandler(handle->tick_list[i], MwNtickHandler, NULL); diff --git a/src/lowlevel.c b/src/lowlevel.c index f8a4cca..19445a4 100644 --- a/src/lowlevel.c +++ b/src/lowlevel.c @@ -7,6 +7,8 @@ void (*MwLLDestroy)(MwLL handle); void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color); void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color); +void (*MwLLEndDraw)(MwLL handle); + MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b); void (*MwLLColorUpdate)(MwLL handle, MwLLColor c, int r, int g, int b); void (*MwLLFreeColor)(MwLLColor color);