diff --git a/glonkers.c b/glonkers.c index ada49cf..3ad6a1a 100644 --- a/glonkers.c +++ b/glonkers.c @@ -66,6 +66,10 @@ int main(int argc, char *argv[]) { int width = event.data.draw.width; int height = event.data.draw.height; render(&renderer, width, height, time, shader_path, 0); + swap_buffers(&state, event.data.draw.surface); + } + if (event.type == EVENT_NONE) { + printf("nothing, absolutely nothing\n"); } } //while (state.running) { diff --git a/wayland.c b/wayland.c index 0e75104..9500847 100644 --- a/wayland.c +++ b/wayland.c @@ -50,6 +50,8 @@ static void xdg_toplevel_configure ( next->data.height = height; printf("🧟🧟🧟\n"); wl_egl_window_resize(next->data.egl_window, width, height, 0, 0); + // draw new frame! + next->data.dirty = true; } static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel) { @@ -381,16 +383,24 @@ struct event wait_for_event(struct client_state *state) { // before dispatch: check that there is nothing elese to do // check for dirty surface struct surface_list *next = state->surface_list; - printf("listtttt\n"); + printf("checking for events\n"); while (next != NULL) { if (next->data.dirty) { printf("dirty\n"); + + if (eglMakeCurrent(state->egl_display, next->data.egl_surface, + next->data.egl_surface, state->egl_context)) { + fprintf(stderr, "Made current\n"); + } else { + fprintf(stderr, "Made current failed\n"); + } struct event event = { .type = EVENT_DRAW, .data = { .draw = { .width = next->data.width, .height = next->data.height, + .surface = &next->data, } } }; @@ -402,3 +412,14 @@ struct event wait_for_event(struct client_state *state) { } } +void swap_buffers(struct client_state *state, struct surface *surface) { + struct surface_list *next = state->surface_list; + while (next != NULL) { + if (&next->data == surface) { + eglSwapBuffers(state->egl_display, next->data.egl_surface); + return; + } + } + fprintf(stderr, "didn't find surface for buffer swap\n"); +} + diff --git a/wayland.h b/wayland.h index da4cbdd..446baf8 100644 --- a/wayland.h +++ b/wayland.h @@ -58,6 +58,7 @@ struct event { /// EVENT_DRAW struct { int width, height; + struct surface *surface; } draw; } data; }; @@ -66,4 +67,5 @@ void wayland_init(struct client_state *state, int output_type); void commit(struct client_state *state); /// Provide pointer to be filled. struct event wait_for_event(struct client_state *state); +void swap_buffers(struct client_state *state, struct surface *surface);