Hello everyone, I'm the developer of the ueberzugpp project, its main purpose is to enable users to view images inside any terminal. One of the latest features I'm working on is EGL support for both the X11 and wayland backend, I'm also using this as an opportunity to learn a how OpenGL works. Now, I've managed to make EGL work under X11 using an OpenGL 4.6 context. When I tried to do the same in wayland, it didn't work. I also have an SHM backend with wayland and that works fine, so I copied most of the code from the SHM backend and edited some stuff. to make it work with EGL. This is a snippet of my code, it initializes the required structs, and configures the listeners, but no window appears, but it kinda does? It's like it is invisible. If I click around where the window should be the previous window loses focus.

The full code is located here: https://github.com/jstkdng/ueberzugpp/blob/master/src/canvas/wayland/window/waylandegl.cpp

Am I doing something wrong? I tested some examples I found and they work but those use OpenGL ES 2 for some reason, does wayland not support regular OpenGL?

Link to the example I tested: https://gist.github.com/nikp123/bebe2d2dc9a8287efa9ba0a5b38ffab4

Any help would be appreciated.

WaylandEglWindow::WaylandEglWindow(struct wl_compositor *compositor, struct xdg_wm_base *xdg_base,
        EGLDisplay egl_display, std::unique_ptr<Image> new_image,
std::shared_ptr<WaylandConfig> new_config, struct XdgStructAgg& xdg_agg):
compositor(compositor),
xdg_base(xdg_base),
surface(wl_compositor_create_surface(compositor)),
xdg_surface(xdg_wm_base_get_xdg_surface(xdg_base, surface)),
xdg_toplevel(xdg_surface_get_toplevel(xdg_surface)),
image(std::move(new_image)),
config(std::move(new_config)),
egl_display(egl_display),
egl_util(egl_display),
appid(fmt::format("ueberzugpp_{}", util::generate_random_string(id_len))),
xdg_agg(xdg_agg)
{
    config->initial_setup(appid);
    xdg_setup();
}

void WaylandEglWindow::finish_init()
{
    auto xdg = std::make_unique<XdgStruct>();
    xdg->ptr = shared_from_this();
    this_ptr = xdg.get();
    xdg_agg.ptrs.push_back(std::move(xdg));
    setup_listeners();

egl_window = wl_egl_window_create(surface, image->width(), image->height()); egl_surface = eglCreatePlatformWindowSurface(egl_display, egl_util.config, egl_window, nullptr);

    if (egl_surface == EGL_NO_SURFACE) {
        std::cout << "Could not create surface" << std::endl;
    }

eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_util.context);
    eglSwapInterval(egl_display, 0);

    glGenFramebuffers(1, &fbo);
    glGenTextures(1, &texture);
#ifdef DEBUG
    glDebugMessageCallback(EGLUtil::debug_callback, nullptr);
    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
#endif

eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

    visible = true;
}

void WaylandEglWindow::setup_listeners()
{
xdg_surface_add_listener(xdg_surface, &xdg_surface_listener_egl, this_ptr);
    wl_surface_commit(surface);

    if (image->is_animated()) {
        callback = wl_surface_frame(surface);
        wl_callback_add_listener(callback, &frame_listener_egl, this_ptr);
    }
}

void WaylandEglWindow::xdg_setup()
{
    xdg_toplevel_set_app_id(xdg_toplevel, appid.c_str());
    xdg_toplevel_set_title(xdg_toplevel, appid.c_str());
}

Reply via email to