removed comments
This commit is contained in:
parent
c039ddba14
commit
77d6df8970
1 changed files with 1 additions and 137 deletions
138
glonkers.c
138
glonkers.c
|
|
@ -9,7 +9,6 @@
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "shm.h"
|
|
||||||
#include "xdg-shell-protocol.h"
|
#include "xdg-shell-protocol.h"
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <wayland-egl.h>
|
#include <wayland-egl.h>
|
||||||
|
|
@ -33,7 +32,6 @@ struct client_state {
|
||||||
/* Globals */
|
/* Globals */
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
struct wl_registry *wl_registry;
|
struct wl_registry *wl_registry;
|
||||||
struct wl_shm *wl_shm;
|
|
||||||
struct wl_compositor *wl_compositor;
|
struct wl_compositor *wl_compositor;
|
||||||
struct xdg_wm_base *xdg_wm_base;
|
struct xdg_wm_base *xdg_wm_base;
|
||||||
/* Objects */
|
/* Objects */
|
||||||
|
|
@ -60,57 +58,12 @@ static const struct wl_buffer_listener wl_buffer_listener = {
|
||||||
.release = wl_buffer_release,
|
.release = wl_buffer_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct wl_buffer *
|
|
||||||
draw_frame(struct client_state *state)
|
|
||||||
{
|
|
||||||
int stride = state->width * 4;
|
|
||||||
int size = stride * state->height;
|
|
||||||
|
|
||||||
int fd = allocate_shm_file(size);
|
|
||||||
if (fd == -1) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t *data = mmap(NULL, size,
|
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
||||||
if (data == MAP_FAILED) {
|
|
||||||
close(fd);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct wl_shm_pool *pool = wl_shm_create_pool(state->wl_shm, fd, size);
|
|
||||||
struct wl_buffer *buffer = wl_shm_pool_create_buffer(pool, 0,
|
|
||||||
state->width, state->height, stride, WL_SHM_FORMAT_XRGB8888);
|
|
||||||
wl_shm_pool_destroy(pool);
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
/* Draw checkerboxed background */
|
|
||||||
for (int y = 0; y < state->height; ++y) {
|
|
||||||
for (int x = 0; x < state->width; ++x) {
|
|
||||||
if ((x + y / 8 * 8) % 16 < 8)
|
|
||||||
data[y * state->width + x] = 0xFF666666;
|
|
||||||
else
|
|
||||||
data[y * state->width + x] = 0xFFEEEEEE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
munmap(data, size);
|
|
||||||
wl_buffer_add_listener(buffer, &wl_buffer_listener, NULL);
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xdg_surface_configure(void *data,
|
xdg_surface_configure(void *data,
|
||||||
struct xdg_surface *xdg_surface, uint32_t serial)
|
struct xdg_surface *xdg_surface, uint32_t serial)
|
||||||
{
|
{
|
||||||
struct client_state *state = data;
|
struct client_state *state = data;
|
||||||
xdg_surface_ack_configure(xdg_surface, serial);
|
xdg_surface_ack_configure(xdg_surface, serial);
|
||||||
|
|
||||||
// TODO do egl stuff here instead?
|
|
||||||
//struct wl_buffer *buffer = draw_frame(state);
|
|
||||||
//wl_surface_attach(state->wl_surface, buffer, 0, 0);
|
|
||||||
wl_surface_commit(state->wl_surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct xdg_surface_listener xdg_surface_listener = {
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
||||||
|
|
@ -136,10 +89,6 @@ registry_handle_global(void *data, struct wl_registry *registry,
|
||||||
|
|
||||||
struct client_state *state = data;
|
struct client_state *state = data;
|
||||||
|
|
||||||
//if (strcmp(interface, wl_shm_interface.name) == 0) {
|
|
||||||
// state->wl_shm = wl_registry_bind(
|
|
||||||
// registry, name, &wl_shm_interface, 1);
|
|
||||||
//}
|
|
||||||
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
||||||
state->wl_compositor = wl_registry_bind(
|
state->wl_compositor = wl_registry_bind(
|
||||||
registry, name, &wl_compositor_interface, 4);
|
registry, name, &wl_compositor_interface, 4);
|
||||||
|
|
@ -259,7 +208,7 @@ main(int argc, char *argv[])
|
||||||
printf("need to supply path to shader\n");
|
printf("need to supply path to shader\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
int width = 700, height = 450;
|
int width = 700, height = 700;
|
||||||
struct client_state state = { width, height, 0 };
|
struct client_state state = { width, height, 0 };
|
||||||
state.wl_display = wl_display_connect(NULL);
|
state.wl_display = wl_display_connect(NULL);
|
||||||
state.wl_registry = wl_display_get_registry(state.wl_display);
|
state.wl_registry = wl_display_get_registry(state.wl_display);
|
||||||
|
|
@ -287,88 +236,3 @@ main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
//_Atomic bool running = true;
|
|
||||||
//
|
|
||||||
//void intHandler(int dummy) {
|
|
||||||
// printf("exiting\n");
|
|
||||||
// running = false;
|
|
||||||
// fclose(stdin);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//bool reload_shader = false;
|
|
||||||
//
|
|
||||||
///// reads stdin on a separate thread.
|
|
||||||
//void *read_stdin(void *ptr) {
|
|
||||||
// char buff[10];
|
|
||||||
// while (running) {
|
|
||||||
// fgets(buff, 10, stdin);
|
|
||||||
// if (strcmp(buff, "r\n") == 0) {
|
|
||||||
// printf("reloading shader\n");
|
|
||||||
// reload_shader = true;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return NULL;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//int main(int argc, char *argv[]) {
|
|
||||||
// signal(SIGINT, intHandler);
|
|
||||||
// pthread_t stdin_thread;
|
|
||||||
// pthread_create( &stdin_thread, NULL, read_stdin, NULL);
|
|
||||||
//
|
|
||||||
// init_timer();
|
|
||||||
//
|
|
||||||
// printf("Good Morning 🍵\n");
|
|
||||||
// SDL_Init(SDL_INIT_VIDEO);
|
|
||||||
// SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "1");
|
|
||||||
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
|
||||||
// SDL_GL_CONTEXT_PROFILE_ES);
|
|
||||||
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
||||||
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
||||||
// SDL_Window* window = SDL_CreateWindow("SDL3 OpenGL Cube",
|
|
||||||
// 800, 600, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
|
||||||
// if (!window) {
|
|
||||||
// printf("CreateWindow Error: %s\n", SDL_GetError());
|
|
||||||
// SDL_Quit();
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// SDL_GLContext glContext = SDL_GL_CreateContext(window);
|
|
||||||
//
|
|
||||||
// if (!glContext) {
|
|
||||||
// printf("GL Context Error: %s\n", SDL_GetError());
|
|
||||||
// SDL_DestroyWindow(window);
|
|
||||||
// SDL_Quit();
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Renderer renderer = new_renderer();
|
|
||||||
//
|
|
||||||
// SDL_Event e;
|
|
||||||
// int w, h;
|
|
||||||
// while (running) {
|
|
||||||
// while (SDL_PollEvent(&e)) {
|
|
||||||
// if (e.type == SDL_EVENT_QUIT) running = false;
|
|
||||||
// if (e.type == SDL_EVENT_WINDOW_RESIZED) {
|
|
||||||
// SDL_GetWindowSize(window, &w, &h);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// char *shader_path = NULL;
|
|
||||||
// if (argc >= 2) {
|
|
||||||
// shader_path = argv[1];
|
|
||||||
// } else {
|
|
||||||
// printf("need to supply path to shader\n");
|
|
||||||
// exit(1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// double time = time_since_start();
|
|
||||||
// render(&renderer, w, h, time, shader_path, reload_shader);
|
|
||||||
// if (reload_shader) reload_shader = false;
|
|
||||||
//
|
|
||||||
// SDL_GL_SwapWindow(window);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// pthread_join(stdin_thread, NULL);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue