diff --git a/include/Mw/LowLevel.h b/include/Mw/LowLevel.h index 516b815..167785a 100644 --- a/include/Mw/LowLevel.h +++ b/include/Mw/LowLevel.h @@ -162,6 +162,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 (*MwLLBeginDraw)(MwLL handle); MWDECL void (*MwLLEndDraw)(MwLL handle); MWDECL MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b); diff --git a/src/backend/call.c b/src/backend/call.c index e97e28b..e2ce934 100644 --- a/src/backend/call.c +++ b/src/backend/call.c @@ -8,9 +8,10 @@ MwLLCreate = MwLLCreateImpl; \ MwLLDestroy = MwLLDestroyImpl; \ \ - MwLLPolygon = MwLLPolygonImpl; \ - MwLLLine = MwLLLineImpl; \ - MwLLEndDraw = MwLLEndDrawImpl; \ + MwLLPolygon = MwLLPolygonImpl; \ + MwLLLine = MwLLLineImpl; \ + MwLLBeginDraw = MwLLBeginDrawImpl; \ + MwLLEndDraw = MwLLEndDrawImpl; \ \ MwLLAllocColor = MwLLAllocColorImpl; \ MwLLColorUpdate = MwLLColorUpdateImpl; \ diff --git a/src/backend/gdi.c b/src/backend/gdi.c index 9d25fae..a527e09 100644 --- a/src/backend/gdi.c +++ b/src/backend/gdi.c @@ -277,6 +277,7 @@ static void MwLLDestroyImpl(MwLL handle) { free(handle); } +static void MwLLBeginDrawImpl(MwLL handle) {} static void MwLLEndDrawImpl(MwLL handle) {} static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { diff --git a/src/backend/wayland.c b/src/backend/wayland.c index 32f5c0b..cfd30f2 100644 --- a/src/backend/wayland.c +++ b/src/backend/wayland.c @@ -274,12 +274,6 @@ static MwBool egl_setup(MwLL self, int width, int height) { return MwFALSE; } - // Make the context current - if(!eglMakeCurrent(display, surface, surface, context)) { - printf("ERROR: eglMakeCurrent, %0X\n", eglGetError()); - return MwFALSE; - } - glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)eglGetProcAddress("glGenFramebuffers"); glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D"); glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)eglGetProcAddress("glGenRenderbuffers"); @@ -305,7 +299,7 @@ static MwBool egl_setup(MwLL self, int width, int height) { if((err = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) { printf("Error binding framebuffer: %0X\n", err); - return MwFALSE; + // return MwFALSE; } glBindFramebuffer(GL_FRAMEBUFFER_BINDING, 0); @@ -653,12 +647,10 @@ static void setup_subsurface(MwLL parent, MwLL r, int x, int y) { // arrpush(parent->wayland.subsurfaces, r); r->wayland.configured = MwTRUE; - - r->wayland.egl_context = topmost_parent->wayland.egl_context; - r->wayland.egl_display = topmost_parent->wayland.egl_display; - r->wayland.egl_surface = topmost_parent->wayland.egl_surface; - r->wayland.fbo = topmost_parent->wayland.fbo; - r->wayland.fbo_texture = topmost_parent->wayland.fbo_texture; + if(!r->wayland.egl_setup) { + r->wayland.egl_setup = egl_setup(r, r->wayland.ww, r->wayland.wh); + MwLLForceRender(r); + }; arrpush(parent->wayland.subwidgets, r); } @@ -826,6 +818,13 @@ static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) { framebuffer_action_end(handle); } +static void MwLLBeginDrawImpl(MwLL handle) { + 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) { int w, h; @@ -859,6 +858,7 @@ static void MwLLEndDrawImpl(MwLL handle) { 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 { diff --git a/src/backend/x11.c b/src/backend/x11.c index 44da549..3c54155 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -148,14 +148,14 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) { if(height < 2) height = 2; if(parent == NULL) { - r->x11.display = XOpenDisplay(NULL); - p = XRootWindow(r->x11.display, XDefaultScreen(r->x11.display)); - r->x11.top = 1; + r->x11.display = XOpenDisplay(NULL); + p = XRootWindow(r->x11.display, XDefaultScreen(r->x11.display)); + r->x11.top = 1; r->x11.toplevel = 1; } else { - r->x11.display = parent->x11.display; - p = parent->x11.window; - r->x11.top = 0; + r->x11.display = parent->x11.display; + p = parent->x11.window; + r->x11.top = 0; r->x11.toplevel = 0; } r->x11.window = XCreateSimpleWindow(r->x11.display, p, px, py, width, height, 0, 0, WhitePixel(r->x11.display, DefaultScreen(r->x11.display))); @@ -259,6 +259,7 @@ static void MwLLDestroyImpl(MwLL handle) { free(handle); } +static void MwLLBeginDrawImpl(MwLL handle) {} static void MwLLEndDrawImpl(MwLL handle) {} static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { diff --git a/src/core.c b/src/core.c index 696ed42..a734655 100644 --- a/src/core.c +++ b/src/core.c @@ -9,15 +9,16 @@ static void lldrawhandler(MwLL handle, void* data) { int ind; (void)data; + if(handle->wayland.parent == NULL) + MwLLBeginDraw(handle); h->bgcolor = NULL; MwDispatch(h, draw); if(h->draw_inject != NULL) h->draw_inject(h); MwDispatchUserHandler(h, MwNdrawHandler, NULL); - if(handle->wayland.parent == NULL) { + if(handle->wayland.parent == NULL) MwLLEndDraw(handle); - } } static void lluphandler(MwLL handle, void* data) { diff --git a/src/lowlevel.c b/src/lowlevel.c index 8e94790..96f6196 100644 --- a/src/lowlevel.c +++ b/src/lowlevel.c @@ -6,6 +6,7 @@ void (*MwLLDestroy)(MwLL handle); void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color); void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color); +void (*MwLLBeginDraw)(MwLL handle); void (*MwLLEndDraw)(MwLL handle); MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b);