seperate opengl contexts

This commit is contained in:
IoIxD 2025-12-07 18:52:49 -07:00
commit 89ff065a71
7 changed files with 30 additions and 24 deletions

View file

@ -162,6 +162,7 @@ MWDECL void (*MwLLDestroy)(MwLL handle);
MWDECL void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color); MWDECL void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color);
MWDECL void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color); MWDECL void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color);
MWDECL void (*MwLLBeginDraw)(MwLL handle);
MWDECL void (*MwLLEndDraw)(MwLL handle); MWDECL void (*MwLLEndDraw)(MwLL handle);
MWDECL MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b); MWDECL MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b);

View file

@ -8,9 +8,10 @@
MwLLCreate = MwLLCreateImpl; \ MwLLCreate = MwLLCreateImpl; \
MwLLDestroy = MwLLDestroyImpl; \ MwLLDestroy = MwLLDestroyImpl; \
\ \
MwLLPolygon = MwLLPolygonImpl; \ MwLLPolygon = MwLLPolygonImpl; \
MwLLLine = MwLLLineImpl; \ MwLLLine = MwLLLineImpl; \
MwLLEndDraw = MwLLEndDrawImpl; \ MwLLBeginDraw = MwLLBeginDrawImpl; \
MwLLEndDraw = MwLLEndDrawImpl; \
\ \
MwLLAllocColor = MwLLAllocColorImpl; \ MwLLAllocColor = MwLLAllocColorImpl; \
MwLLColorUpdate = MwLLColorUpdateImpl; \ MwLLColorUpdate = MwLLColorUpdateImpl; \

View file

@ -277,6 +277,7 @@ static void MwLLDestroyImpl(MwLL handle) {
free(handle); free(handle);
} }
static void MwLLBeginDrawImpl(MwLL handle) {}
static void MwLLEndDrawImpl(MwLL handle) {} static void MwLLEndDrawImpl(MwLL handle) {}
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {

View file

@ -274,12 +274,6 @@ static MwBool egl_setup(MwLL self, int width, int height) {
return MwFALSE; return MwFALSE;
} }
// Make the context current
if(!eglMakeCurrent(display, surface, surface, context)) {
printf("ERROR: eglMakeCurrent, %0X\n", eglGetError());
return MwFALSE;
}
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)eglGetProcAddress("glGenFramebuffers"); glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)eglGetProcAddress("glGenFramebuffers");
glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D"); glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC)eglGetProcAddress("glFramebufferTexture2D");
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)eglGetProcAddress("glGenRenderbuffers"); 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) { if((err = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) {
printf("Error binding framebuffer: %0X\n", err); printf("Error binding framebuffer: %0X\n", err);
return MwFALSE; // return MwFALSE;
} }
glBindFramebuffer(GL_FRAMEBUFFER_BINDING, 0); 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); // arrpush(parent->wayland.subsurfaces, r);
r->wayland.configured = MwTRUE; r->wayland.configured = MwTRUE;
if(!r->wayland.egl_setup) {
r->wayland.egl_context = topmost_parent->wayland.egl_context; r->wayland.egl_setup = egl_setup(r, r->wayland.ww, r->wayland.wh);
r->wayland.egl_display = topmost_parent->wayland.egl_display; MwLLForceRender(r);
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;
arrpush(parent->wayland.subwidgets, r); arrpush(parent->wayland.subwidgets, r);
} }
@ -826,6 +818,13 @@ static void MwLLLineImpl(MwLL handle, MwPoint* points, MwLLColor color) {
framebuffer_action_end(handle); 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) { static void MwLLEndDrawImpl(MwLL handle) {
int w, h; int w, h;
@ -859,6 +858,7 @@ static void MwLLEndDrawImpl(MwLL handle) {
glFinish(); glFinish();
wl_surface_damage(handle->wayland.surface, 0, 0, handle->wayland.ww, handle->wayland.wh); wl_surface_damage(handle->wayland.surface, 0, 0, handle->wayland.ww, handle->wayland.wh);
if(!eglSwapBuffers(handle->wayland.egl_display, handle->wayland.egl_surface)) { if(!eglSwapBuffers(handle->wayland.egl_display, handle->wayland.egl_surface)) {
printf("error swapping buffers! %0X\n", eglGetError()); printf("error swapping buffers! %0X\n", eglGetError());
} else { } else {

View file

@ -148,14 +148,14 @@ static MwLL MwLLCreateImpl(MwLL parent, int x, int y, int width, int height) {
if(height < 2) height = 2; if(height < 2) height = 2;
if(parent == NULL) { if(parent == NULL) {
r->x11.display = XOpenDisplay(NULL); r->x11.display = XOpenDisplay(NULL);
p = XRootWindow(r->x11.display, XDefaultScreen(r->x11.display)); p = XRootWindow(r->x11.display, XDefaultScreen(r->x11.display));
r->x11.top = 1; r->x11.top = 1;
r->x11.toplevel = 1; r->x11.toplevel = 1;
} else { } else {
r->x11.display = parent->x11.display; r->x11.display = parent->x11.display;
p = parent->x11.window; p = parent->x11.window;
r->x11.top = 0; r->x11.top = 0;
r->x11.toplevel = 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))); 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); free(handle);
} }
static void MwLLBeginDrawImpl(MwLL handle) {}
static void MwLLEndDrawImpl(MwLL handle) {} static void MwLLEndDrawImpl(MwLL handle) {}
static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) { static void MwLLPolygonImpl(MwLL handle, MwPoint* points, int points_count, MwLLColor color) {

View file

@ -9,15 +9,16 @@ static void lldrawhandler(MwLL handle, void* data) {
int ind; int ind;
(void)data; (void)data;
if(handle->wayland.parent == NULL)
MwLLBeginDraw(handle);
h->bgcolor = NULL; h->bgcolor = NULL;
MwDispatch(h, draw); MwDispatch(h, draw);
if(h->draw_inject != NULL) h->draw_inject(h); if(h->draw_inject != NULL) h->draw_inject(h);
MwDispatchUserHandler(h, MwNdrawHandler, NULL); MwDispatchUserHandler(h, MwNdrawHandler, NULL);
if(handle->wayland.parent == NULL) { if(handle->wayland.parent == NULL)
MwLLEndDraw(handle); MwLLEndDraw(handle);
}
} }
static void lluphandler(MwLL handle, void* data) { static void lluphandler(MwLL handle, void* data) {

View file

@ -6,6 +6,7 @@ void (*MwLLDestroy)(MwLL handle);
void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color); void (*MwLLPolygon)(MwLL handle, MwPoint* points, int points_count, MwLLColor color);
void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color); void (*MwLLLine)(MwLL handle, MwPoint* points, MwLLColor color);
void (*MwLLBeginDraw)(MwLL handle);
void (*MwLLEndDraw)(MwLL handle); void (*MwLLEndDraw)(MwLL handle);
MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b); MwLLColor (*MwLLAllocColor)(MwLL handle, int r, int g, int b);