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 (*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);

View file

@ -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; \

View file

@ -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) {

View file

@ -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 {

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(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) {

View file

@ -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) {

View file

@ -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);