WIP testing non-callback

This commit is contained in:
Rakarake 2026-01-15 23:07:37 +01:00
parent 4806cff440
commit 33ceed2d22
3 changed files with 38 additions and 3 deletions

View file

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include <time.h>
#include <stdint.h>
@ -55,11 +56,23 @@ int main(int argc, char *argv[]) {
Renderer renderer = new_renderer();
while (state.running) {
bool running = true;
while (running) {
double time = time_since_start();
render(&renderer, state.width, state.height, time, shader_path, 0);
commit(&state);
struct event event;
wait_for_event(&state, &event);
if (event.type == EVENT_DRAW) {
int width = event.data.draw.width;
int height = event.data.draw.height;
render(&renderer, width, height, time, shader_path, 0);
}
}
//while (state.running) {
// double time = time_since_start();
// render(&renderer, state.width, state.height, time, shader_path, 0);
// commit(&state);
//}
return 0;
}

View file

@ -295,9 +295,13 @@ void wayland_init(struct client_state *state, int output_type) {
}
egl_init(state);
// TODO fix frame callbacks for all surfaces
}
/// Swaps front/backbuffers and dispatches pending wayland commands.
// TODO move logic to wait_for_event
void commit(struct client_state *state) {
struct surface_list *next = state->surface_list;
while (next != NULL) {
@ -316,3 +320,7 @@ void commit(struct client_state *state) {
}
}
void wait_for_event(struct client_state *state, struct event event) {
wl_display_dispatch(state->wl_display);
}

View file

@ -43,6 +43,20 @@ struct client_state {
EGLContext egl_context;
};
#define EVENT_DRAW 0
struct event {
int type;
union {
/// EVENT_DRAW
struct {
int width, height;
} draw;
} data;
};
void wayland_init(struct client_state *state, int output_type);
void commit(struct client_state *state);
/// Provide pointer to be filled.
void wait_for_event(struct client_state *state, struct event event);