From fd39a0aa1c5072de99f17fe5fd9b0cbaaffdb4e3 Mon Sep 17 00:00:00 2001 From: IoIxD Date: Sun, 7 Dec 2025 20:29:51 -0700 Subject: [PATCH] no more framebuffer --- src/backend/wayland.c | 170 ++---------------------------------------- 1 file changed, 6 insertions(+), 164 deletions(-) diff --git a/src/backend/wayland.c b/src/backend/wayland.c index d1130e6dc..e24267295 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -16,15 +16,6 @@ #else #include #endif - -PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers; -PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D; -PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers; -PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer; -PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer; -PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer; -PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatus; - /* callback todo: void (*up)(MwLL handle, void* data); @@ -272,36 +263,6 @@ static MwBool egl_setup(MwLL self, int width, int height) { return MwFALSE; } - glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)eglGetProcAddress("glGenFramebuffers"); - glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D"); - glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)eglGetProcAddress("glGenRenderbuffers"); - // glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)eglGetProcAddress("glRenderbufferStorage"); - glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)eglGetProcAddress("glFramebufferRenderbuffer"); - glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)eglGetProcAddress("glBindRenderbuffer"); - glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)eglGetProcAddress("glBindFramebuffer"); - glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC)eglGetProcAddress("glCheckFramebufferStatus"); - - glGenTextures(1, &self->wayland.fbo_texture); - glBindTexture(GL_TEXTURE_2D, self->wayland.fbo_texture); - - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - - glBindTexture(GL_TEXTURE_2D, 0); - - glGenFramebuffers(1, &self->wayland.fbo); - glBindFramebuffer(GL_FRAMEBUFFER_BINDING, self->wayland.fbo); - - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, self->wayland.fbo_texture, 0); - - if((err = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) { - printf("Error binding framebuffer: %0X\n", err); - // return MwFALSE; - } - - glBindFramebuffer(GL_FRAMEBUFFER_BINDING, 0); - glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, width, height, 0, -1, 1); @@ -323,30 +284,6 @@ static void egl_resetup(MwLL handle) { return; } - glDeleteTextures(1, &handle->wayland.fbo_texture); - glGenTextures(1, &handle->wayland.fbo_texture); - glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture); - - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, handle->wayland.ww, handle->wayland.wh, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); - - glGenFramebuffers(1, &handle->wayland.fbo); - glBindFramebuffer(GL_FRAMEBUFFER_BINDING, handle->wayland.fbo); - - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, handle->wayland.fbo_texture, 0); - - if((err = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) { - printf("Error binding framebuffer: %0X\n", err); - return; - } - - glBindFramebuffer(GL_FRAMEBUFFER_BINDING, 0); - - glBindTexture(GL_TEXTURE_2D, 0); - glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, handle->wayland.ww, handle->wayland.wh, 0, -1, 1); @@ -379,8 +316,7 @@ static void xdg_toplevel_configure(void* data, struct xdg_toplevel* xdg_toplevel, MwI32 width, MwI32 height, struct wl_array* states) { - MwLL self = data; - PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D"); + MwLL self = data; if(width == 0 || height == 0) { width = self->wayland.ww; @@ -472,24 +408,6 @@ static int event_loop(MwLL handle) { } } - /* - IOI: - I took this from ioilib which I in turn adapted from SDL. I think this is meant to be required? - But doing this on my main machine causes the decorations manager to be null...? This doesn't show up on the project currently using ioilib. - Race condition? Random KDE bug? Who knows, but it seems that not polling for this works anyways (possibly because we already flush events above and then cancel reads when we actually need to close). - */ - /* - - // Condition where no events are being sent. - if(!poll(&fd, 1, timeout)) { - wl_display_cancel_read(wayland->display); - // In this case, we need to commit the surface for any animations, etc. - wl_surface_commit(wayland->surface); - return 0; - } - - */ - if(fd.revents & POLLIN) { wl_display_read_events(wayland->display); if(wl_display_dispatch_pending(wayland->display) > 0) { @@ -657,16 +575,6 @@ static void setup_subsurface(MwLL parent, MwLL r, int x, int y) { arrpush(parent->wayland.subwidgets, r); } -static void framebuffer_action_begin(MwLL handle) { - glBindFramebuffer(GL_FRAMEBUFFER, handle->wayland.fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, handle->wayland.fbo_texture, 0); -} - -static void framebuffer_action_end(MwLL handle) { - glFinish(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); -} - static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { MwLL r; r = malloc(sizeof(*r)); @@ -745,40 +653,8 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL int i, n; float maxX = 0, maxY = 0; float centerX, centerY; - int doLoopback = MwFALSE; - if(points_count > 3) { - /* To avoid having to do a real triangulation algorithim: - 1.) loop through the points once to determine the bounds of the polygon - 2.) calculate the center of the polygon - - */ - for(i = 0; i < points_count; i++) { - float x = round(handle->wayland.x) + round(points[i].x); - float y = round(handle->wayland.y) + round(points[i].y); - if(x >= maxX) { - maxX = x; - } - if(y >= maxY) { - maxY = y; - } - } - } - centerX = (handle->wayland.x + maxX / 2); - centerY = (handle->wayland.y + maxY / 2); - - /* Efficient? No. But at the end of the day it's still not that many polygons, and if a computer can't handle 12 polygons over 6 then it should not be using Wayland anyways */ - - framebuffer_action_begin(handle); - - if(points_count == 3) { - glBegin(GL_TRIANGLES); - } else if((points_count % 3) == 0) { - glBegin(GL_POLYGON); - } else { - glBegin(GL_TRIANGLE_FAN); - doLoopback = MwTRUE; - } + glBegin(GL_POLYGON); for(i = 0; i < points_count; i++) { float x = round(handle->wayland.x) + round(points[i].x); @@ -787,15 +663,9 @@ static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLL glColor3f(color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0); glVertex2f(x, y); - if(doLoopback) { - glVertex2f(maxX, maxY); - glVertex2f(x, y); - } } glEnd(); glColor3f(0, 0, 0); - - framebuffer_action_end(handle); } static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { @@ -803,29 +673,17 @@ static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { glLineWidth(1); - framebuffer_action_begin(handle); - glBegin(GL_LINES); - for(i = 0; i < 2; i++) { - float x = round(handle->wayland.x) + round(points[i].x); - float y = round(handle->wayland.y) + round(points[i].y); - - glColor3f(color->common.red / 255.0, color->common.green / 255.0, color->common.blue / 255.0); - - glVertex2f(x, y); - } - glEnd(); glColor3f(0, 0, 0); - - framebuffer_action_end(handle); } static void MwLLBeginDrawImpl(MwLL handle) { - if(handle->wayland.parent == NULL) + if(handle->wayland.parent == NULL) { if(!eglMakeCurrent(handle->wayland.egl_display, handle->wayland.egl_surface, handle->wayland.egl_surface, handle->wayland.egl_context)) { printf("ERROR: eglMakeCurrent, %0X\n", eglGetError()); return; } + } } static void MwLLEndDrawImpl(MwLL handle) { @@ -842,32 +700,18 @@ static void MwLLEndDrawImpl(MwLL handle) { recursive_draw(handle); - glBindTexture(GL_TEXTURE_2D, handle->wayland.fbo_texture); // glClear(GL_COLOR_BUFFER_BIT); // glClearColor(1.0, 0, 0, 1); - glColor3f(1.0, 1.0, 1.0); - - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 1); - glVertex2f(0, 0); - glTexCoord2f(1, 1); - glVertex2f(w, 0); - glTexCoord2f(1, 0.0f); - glVertex2f(w, h); - glTexCoord2f(0.0f, 0.0f); - glVertex2f(0, h); - glEnd(); - glFinish(); - wl_surface_damage(handle->wayland.surface, 0, 0, handle->wayland.ww, handle->wayland.wh); - if(handle->wayland.parent == NULL) + if(handle->wayland.parent == NULL) { if(!eglSwapBuffers(handle->wayland.egl_display, handle->wayland.egl_surface)) { printf("error swapping buffers! %0X\n", eglGetError()); } else { wl_surface_commit(handle->wayland.surface); } + } } static MwLLColor MwLLAllocColorImpl(MwLL handle, int r, int g, int b) { @@ -953,7 +797,6 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { glBindTexture(GL_TEXTURE_2D, pixmap->wayland.texture); glActiveTexture(pixmap->wayland.texture); - framebuffer_action_begin(handle); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0); glVertex2f(x, y); @@ -965,7 +808,6 @@ static void MwLLDrawPixmapImpl(MwLL handle, MwRect* rect, MwLLPixmap pixmap) { glVertex2f(x, y + rect->height); glEnd(); glFinish(); - framebuffer_action_end(handle); } static void MwLLSetIconImpl(MwLL handle, MwLLPixmap pixmap) {