Unfinished Wayland PR #1

Merged
IoI_xD merged 55 commits from IoI_xD/milsko:wayland into master 2025-12-10 11:11:02 +09:00
7 changed files with 31 additions and 28 deletions
Showing only changes of commit 247e0b361c - Show all commits

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

IoIxD 2025-12-03 23:00:40 -07:00

View file

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

View file

@ -11,6 +11,7 @@
\
MwLLPolygon = MwLLPolygonImpl; \
MwLLLine = MwLLLineImpl; \
MwLLEndDraw = MwLLEndDrawImpl; \
\
MwLLAllocColor = MwLLAllocColorImpl; \
MwLLColorUpdate = MwLLColorUpdateImpl; \

View file

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

View file

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

View file

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

View file

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

View file

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