WIP getting egl to work
This commit is contained in:
parent
8f551459fe
commit
575e4ee54a
3 changed files with 67 additions and 133 deletions
2
Makefile
2
Makefile
|
|
@ -1,4 +1,4 @@
|
||||||
LIBS=sdl3 opengl wayland-client
|
LIBS=sdl3 opengl wayland-client egl wayland-egl
|
||||||
CFLAGS+=-g -Wall -Wextra $(shell pkg-config --cflags $(LIBS))
|
CFLAGS+=-g -Wall -Wextra $(shell pkg-config --cflags $(LIBS))
|
||||||
LDLIBS+=$(shell pkg-config --libs $(LIBS))
|
LDLIBS+=$(shell pkg-config --libs $(LIBS))
|
||||||
|
|
||||||
|
|
|
||||||
195
glonkers.c
195
glonkers.c
|
|
@ -11,22 +11,11 @@
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "shm.h"
|
#include "shm.h"
|
||||||
#include "xdg-shell-protocol.h"
|
#include "xdg-shell-protocol.h"
|
||||||
|
#include <EGL/egl.h>
|
||||||
//int main() {
|
#include <wayland-egl.h>
|
||||||
// struct wl_display *display = wl_display_connect(NULL);
|
|
||||||
// if (!display) {
|
|
||||||
// fprintf(stderr, "Failed to connect to Wayland display.\n");
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
// fprintf(stderr, "Connection established!\n");
|
|
||||||
//
|
|
||||||
// while (wl_display_dispatch(display) != -1) {
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// wl_display_disconnect(display);
|
|
||||||
//}
|
|
||||||
|
|
||||||
struct client_state {
|
struct client_state {
|
||||||
|
int width, height;
|
||||||
/* Globals */
|
/* Globals */
|
||||||
struct wl_display *wl_display;
|
struct wl_display *wl_display;
|
||||||
struct wl_registry *wl_registry;
|
struct wl_registry *wl_registry;
|
||||||
|
|
@ -37,6 +26,8 @@ struct client_state {
|
||||||
struct wl_surface *wl_surface;
|
struct wl_surface *wl_surface;
|
||||||
struct xdg_surface *xdg_surface;
|
struct xdg_surface *xdg_surface;
|
||||||
struct xdg_toplevel *xdg_toplevel;
|
struct xdg_toplevel *xdg_toplevel;
|
||||||
|
|
||||||
|
struct wl_egl_window *egl_window;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -54,9 +45,8 @@ static const struct wl_buffer_listener wl_buffer_listener = {
|
||||||
static struct wl_buffer *
|
static struct wl_buffer *
|
||||||
draw_frame(struct client_state *state)
|
draw_frame(struct client_state *state)
|
||||||
{
|
{
|
||||||
const int width = 640, height = 480;
|
int stride = state->width * 4;
|
||||||
int stride = width * 4;
|
int size = stride * state->height;
|
||||||
int size = stride * height;
|
|
||||||
|
|
||||||
int fd = allocate_shm_file(size);
|
int fd = allocate_shm_file(size);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
|
@ -72,17 +62,17 @@ draw_frame(struct client_state *state)
|
||||||
|
|
||||||
struct wl_shm_pool *pool = wl_shm_create_pool(state->wl_shm, fd, size);
|
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,
|
struct wl_buffer *buffer = wl_shm_pool_create_buffer(pool, 0,
|
||||||
width, height, stride, WL_SHM_FORMAT_XRGB8888);
|
state->width, state->height, stride, WL_SHM_FORMAT_XRGB8888);
|
||||||
wl_shm_pool_destroy(pool);
|
wl_shm_pool_destroy(pool);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
/* Draw checkerboxed background */
|
/* Draw checkerboxed background */
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < state->height; ++y) {
|
||||||
for (int x = 0; x < width; ++x) {
|
for (int x = 0; x < state->width; ++x) {
|
||||||
if ((x + y / 8 * 8) % 16 < 8)
|
if ((x + y / 8 * 8) % 16 < 8)
|
||||||
data[y * width + x] = 0xFF666666;
|
data[y * state->width + x] = 0xFF666666;
|
||||||
else
|
else
|
||||||
data[y * width + x] = 0xFFEEEEEE;
|
data[y * state->width + x] = 0xFFEEEEEE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,17 +144,61 @@ wl_registry_listener = {
|
||||||
.global_remove = registry_handle_global_remove,
|
.global_remove = registry_handle_global_remove,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//static void egl_init(struct client_state *state) {
|
||||||
|
// EGLint major;
|
||||||
|
// EGLint minor;
|
||||||
|
// EGLint num_configs;
|
||||||
|
// EGLint attribs[] = {
|
||||||
|
// EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||||
|
// EGL_NONE
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// state->egl_window = wl_egl_window_create(state->wl_surface, state->width,
|
||||||
|
// state->height);
|
||||||
|
//
|
||||||
|
// state->egl_display = eglGetDisplay((EGLNativeDisplayType) state->display);
|
||||||
|
// if(state->display == EGL_NO_DISPLAY) {
|
||||||
|
// fprintf(stderr, "Couldn't get EGL display\n");
|
||||||
|
// exit(EXIT_FAILURE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if(eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) {
|
||||||
|
// fprintf(stderr, "Couldnt initialize EGL\n");
|
||||||
|
// exit(EXIT_FAILURE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if(eglChooseConfig(state->egl_display, attribs, &state->egl_config, 1,
|
||||||
|
// &num_configs) != EGL_TRUE) {
|
||||||
|
// fprintf(stderr, "CouldnÄt find matching EGL config\n");
|
||||||
|
// exit(EXIT_FAILURE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// state->egl_surface = eglCreateWindowSurface(state->egl_display,
|
||||||
|
// state->egl_config,
|
||||||
|
// (EGLNativeWindowType) state->egl_window, NULL);
|
||||||
|
// if(state->egl_surface == EGL_NO_SURFACE) {
|
||||||
|
// fprintf(stderr, "Couldn't create EGL surface\n");
|
||||||
|
// exit(EXIT_FAILURE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// state->egl_context = eglCreateContext(state->egl_display, state->egl_config,
|
||||||
|
// EGL_NO_CONTEXT, NULL);
|
||||||
|
// if(state->egl_context == EGL_NO_CONTEXT) {
|
||||||
|
// fprintf(stderr, "Couldn't create EGL context\n");
|
||||||
|
// exit(EXIT_FAILURE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if(!eglMakeCurrent(state->egl_display, state->egl_surface,
|
||||||
|
// state->egl_surface, state->egl_context)) {
|
||||||
|
// fprintf(stderr, "Couldn't make EGL context current\n");
|
||||||
|
// exit(EXIT_FAILURE);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
//struct our_state state = { 0 };
|
struct client_state state = { 700, 450, 0 };
|
||||||
//struct wl_display *display = wl_display_connect(NULL);
|
|
||||||
//struct wl_registry *registry = wl_display_get_registry(display);
|
|
||||||
//wl_registry_add_listener(registry, ®istry_listener, &state);
|
|
||||||
//wl_display_roundtrip(display);
|
|
||||||
//return 0;
|
|
||||||
|
|
||||||
struct client_state state = { 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);
|
||||||
wl_registry_add_listener(state.wl_registry, &wl_registry_listener, &state);
|
wl_registry_add_listener(state.wl_registry, &wl_registry_listener, &state);
|
||||||
|
|
@ -175,7 +209,7 @@ main(int argc, char *argv[])
|
||||||
state.xdg_wm_base, state.wl_surface);
|
state.xdg_wm_base, state.wl_surface);
|
||||||
xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state);
|
xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state);
|
||||||
state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface);
|
state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface);
|
||||||
xdg_toplevel_set_title(state.xdg_toplevel, "Example client");
|
xdg_toplevel_set_title(state.xdg_toplevel, "GLONKERS!");
|
||||||
wl_surface_commit(state.wl_surface);
|
wl_surface_commit(state.wl_surface);
|
||||||
|
|
||||||
while (wl_display_dispatch(state.wl_display)) {
|
while (wl_display_dispatch(state.wl_display)) {
|
||||||
|
|
@ -184,102 +218,3 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//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;
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//_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);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
|
|
|
||||||
3
run.sh
3
run.sh
|
|
@ -1,3 +1,2 @@
|
||||||
make
|
make && SDL_VIDEODRIVER="wayland,x11" ./glonkers "$@"
|
||||||
SDL_VIDEODRIVER="wayland,x11" ./glonkers "$@"
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue