From c039ddba14b1bd656255bcfb76dd74059b8a0e78 Mon Sep 17 00:00:00 2001 From: Rakarake Date: Thu, 18 Dec 2025 03:45:35 +0100 Subject: [PATCH] egl working with shader! --- glonkers.c | 114 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 41 deletions(-) diff --git a/glonkers.c b/glonkers.c index 9df3978..54c71d9 100644 --- a/glonkers.c +++ b/glonkers.c @@ -167,54 +167,86 @@ wl_registry_listener = { }; 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 - }; + EGLint major, minor, count, n, size; + EGLConfig *configs; + int i; + EGLint config_attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; - state->egl_window = wl_egl_window_create(state->wl_surface, state->width, - state->height); + static const EGLint context_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; - state->egl_display = eglGetDisplay((EGLNativeDisplayType) state->wl_display); - if(state->wl_display == EGL_NO_DISPLAY) { - fprintf(stderr, "Couldn't get EGL display\n"); - exit(EXIT_FAILURE); - } + + state->egl_display = eglGetDisplay((EGLNativeDisplayType) state->wl_display); + if (state->egl_display == EGL_NO_DISPLAY) { + fprintf(stderr, "Can't create egl display\n"); + exit(1); + } else { + fprintf(stderr, "Created egl display\n"); + } - if(eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) { - fprintf(stderr, "Couldnt initialize EGL\n"); - exit(EXIT_FAILURE); - } + if (eglInitialize(state->egl_display, &major, &minor) != EGL_TRUE) { + fprintf(stderr, "Can't initialise egl display\n"); + exit(1); + } + printf("EGL major: %d, minor %d\n", major, minor); - 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); - } + eglGetConfigs(state->egl_display, NULL, 0, &count); + printf("EGL has %d configs\n", count); - 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); - } + configs = calloc(count, sizeof *configs); + + eglChooseConfig(state->egl_display, config_attribs, + configs, count, &n); + + for (i = 0; i < n; i++) { + eglGetConfigAttrib(state->egl_display, + configs[i], EGL_BUFFER_SIZE, &size); + printf("Buffer size for config %d is %d\n", i, size); + eglGetConfigAttrib(state->egl_display, + configs[i], EGL_RED_SIZE, &size); + printf("Red size for config %d is %d\n", i, size); + + // just choose the first one + state->egl_config = configs[i]; + break; + } - 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); - } + state->egl_context = + eglCreateContext(state->egl_display, + state->egl_config, + EGL_NO_CONTEXT, context_attribs); - 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); - } + + // EGL window + state->egl_window = wl_egl_window_create(state->wl_surface, + state->width, state->height); + if (state->egl_window == EGL_NO_SURFACE) { + fprintf(stderr, "Can't create egl window\n"); + exit(1); + } else { + fprintf(stderr, "Created egl window\n"); + } + + state->egl_surface = + eglCreateWindowSurface(state->egl_display, + state->egl_config, + (unsigned long) state->egl_window, NULL); + + if (eglMakeCurrent(state->egl_display, state->egl_surface, + state->egl_surface, state->egl_context)) { + fprintf(stderr, "Made current\n"); + } else { + fprintf(stderr, "Made current failed\n"); + } } int