shaders using wayland time instead of stdtime

This commit is contained in:
Rakarake 2026-02-07 16:20:19 +01:00
parent bb63b49155
commit 859025a4a3
3 changed files with 14 additions and 31 deletions

View file

@ -2,7 +2,6 @@
#include <stdlib.h>
#include <stdbool.h>
#include <signal.h>
#include <time.h>
#include <stdint.h>
#include <wayland-client.h>
#include <wayland-util.h>
@ -12,20 +11,6 @@
#include "wayland.h"
#include <string.h>
struct timespec program_start;
void init_timer() {
clock_gettime(CLOCK_MONOTONIC, &program_start);
}
double time_since_start() {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return (now.tv_sec - program_start.tv_sec) +
(now.tv_nsec - program_start.tv_nsec) / 1e9;
}
int main(int argc, char *argv[]) {
char *shader_path = NULL;
int output_type = OUTPUT_WINDOW;
@ -51,27 +36,21 @@ int main(int argc, char *argv[]) {
return 1;
}
struct client_state state;
wayland_init(&state, output_type);
struct client_state *state = wayland_init(output_type);
Renderer renderer = new_renderer();
bool running = true;
while (running) {
double time = time_since_start();
struct event event = wait_for_event(&state);
struct event event = wait_for_event(state);
if (event.type == EVENT_DRAW) {
printf("drawing!!!! %p\n", event.data.draw.surface);
int width = event.data.draw.width;
int height = event.data.draw.height;
double time = event.data.draw.time / 1000.0;
render(&renderer, width, height, time, shader_path, 0);
printf("about to 🦬 swap buf %p\n", event.data.draw.surface);
swap_buffers(&state, event.data.draw.surface);
printf("🦬🦬🦬 swaped a buffalo\n");
swap_buffers(state, event.data.draw.surface);
}
if (event.type == EVENT_NONE) {
printf("nothing, absolutely nothing\n");
}
if (event.type == EVENT_EXIT) {
running = false;

View file

@ -16,6 +16,7 @@ struct surface {
/// Wating to be redrawn.
bool dirty;
uint32_t time;
struct wl_surface *wl_surface;
struct xdg_surface *xdg_surface;
@ -25,9 +26,6 @@ struct surface {
struct wl_output *wl_output;
EGLSurface egl_surface;
/// We need a back-pointer for callbacks.
struct client_state *state;
};
struct surface_list {
@ -156,7 +154,7 @@ static const struct wl_callback_listener wl_surface_frame_listener;
static void
wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t time) {
struct surface *surface = data;
struct client_state *state = surface->state;
surface->time = time;
/* Destroy this callback */
wl_callback_destroy(cb);
@ -455,7 +453,8 @@ static void egl_init(struct client_state *state) {
}
/// Initializes wayland and creates an opengl context
void wayland_init(struct client_state *state, int output_type) {
struct client_state* wayland_init(int output_type) {
struct client_state *state = malloc(sizeof(struct client_state));
state->running = 1;
state->output_type = output_type;
state->wl_display = wl_display_connect(NULL);
@ -474,6 +473,7 @@ void wayland_init(struct client_state *state, int output_type) {
}
egl_init(state);
return state;
}
struct event wait_for_event(struct client_state *state) {
@ -507,6 +507,7 @@ struct event wait_for_event(struct client_state *state) {
.draw = {
.width = next->data.width,
.height = next->data.height,
.time = next->data.time,
.surface = &next->data,
}
}

View file

@ -1,3 +1,5 @@
#include <stdint.h>
/// A normal window
#define OUTPUT_WINDOW 0
/// A desktop layer (wallpaper)
@ -23,12 +25,13 @@ struct event {
/// EVENT_DRAW
struct {
int width, height;
uint32_t time;
struct surface *surface;
} draw;
} data;
};
void wayland_init(struct client_state *state, int output_type);
struct client_state* wayland_init(int output_type);
void commit(struct client_state *state);
struct event wait_for_event(struct client_state *state);
void swap_buffers(struct client_state *state, struct surface *surface);