allocation of wayland state memory in main

This commit is contained in:
Rakarake 2025-12-24 17:33:17 +01:00
parent 92ce71b5f1
commit 09ac1a0559
3 changed files with 19 additions and 20 deletions

View file

@ -5,7 +5,6 @@
#include <stdint.h>
#include <wayland-client.h>
#include <wayland-util.h>
#include <SDL3/SDL.h>
#include <pthread.h>
#include <sys/mman.h>
#include "renderer.h"
@ -36,13 +35,14 @@ int main(int argc, char *argv[]) {
exit(1);
}
struct client_state state = wayland_init();
struct client_state state;
wayland_init(&state);
Renderer renderer = new_renderer();
while (running) {
double time = time_since_start();
render(&renderer, state.width, state.height, time, shader_path, false);
render(&renderer, state.width, state.height, time, shader_path, 0);
commit(&state);
}

View file

@ -156,25 +156,24 @@ static void egl_init(struct client_state *state) {
}
/// Initializes wayland and creates an opengl context
struct client_state wayland_init() {
void wayland_init(struct client_state *state) {
int width = 700, height = 700;
struct client_state state = { width, height, 0 };
state.wl_display = wl_display_connect(NULL);
state.wl_registry = wl_display_get_registry(state.wl_display);
wl_registry_add_listener(state.wl_registry, &wl_registry_listener, &state);
wl_display_roundtrip(state.wl_display);
state->width = width;
state->height = height;
state->wl_display = wl_display_connect(NULL);
state->wl_registry = wl_display_get_registry(state->wl_display);
wl_registry_add_listener(state->wl_registry, &wl_registry_listener, state);
wl_display_roundtrip(state->wl_display);
state.wl_surface = wl_compositor_create_surface(state.wl_compositor);
state.xdg_surface = xdg_wm_base_get_xdg_surface(
state.xdg_wm_base, state.wl_surface);
xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state);
state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface);
xdg_toplevel_set_title(state.xdg_toplevel, "GLONKERS!");
wl_surface_commit(state.wl_surface);
state->wl_surface = wl_compositor_create_surface(state->wl_compositor);
state->xdg_surface = xdg_wm_base_get_xdg_surface(
state->xdg_wm_base, state->wl_surface);
xdg_surface_add_listener(state->xdg_surface, &xdg_surface_listener, state);
state->xdg_toplevel = xdg_surface_get_toplevel(state->xdg_surface);
xdg_toplevel_set_title(state->xdg_toplevel, "GLONKERS!");
wl_surface_commit(state->wl_surface);
egl_init(&state);
return state;
egl_init(state);
}
/// Swaps front/backbuffers and dispatches pending wayland commands.

View file

@ -22,6 +22,6 @@ struct client_state {
EGLContext egl_context;
};
struct client_state wayland_init();
void wayland_init(struct client_state *state);
void commit(struct client_state *state);