- Setup EGL context for Wayland. Test window now opens as black rectangle.

This commit is contained in:
2025-12-15 13:20:08 -05:00
parent 5dcb58f53c
commit 1acf00138a
36 changed files with 992 additions and 80 deletions

View File

@@ -0,0 +1,38 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#include <fennec/platform/linux/wayland/window.h>
#include <fennec/platform/linux/wayland/egl/context.h>
#include <fennec/platform/linux/wayland/egl/surface.h>
namespace fennec
{
wayland_eglcontext::wayland_eglcontext(display_server* display)
: eglcontext(display) {
}
wayland_eglcontext::~wayland_eglcontext() {
}
gfxsurface* wayland_eglcontext::create_surface(window* window) {
return new wayland_eglsurface(static_cast<wayland_window*>(window), this);
}
}

View File

@@ -0,0 +1,46 @@
// =====================================================================================================================
// fennec, a free and open source game engine
// Copyright © 2025 Medusa Slockbower
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
#include <fennec/platform/linux/wayland/window.h>
#include <fennec/platform/linux/wayland/egl/surface.h>
#include <fennec/platform/linux/wayland/lib/wayland.h>
namespace fennec
{
wayland_eglsurface::wayland_eglsurface(wayland_window* win, eglcontext* ctx)
: eglsurface(win, ctx,
reinterpret_cast<EGLNativeWindowType>(
wl_egl_window_create(
static_cast<wl_surface*>(win->get_native_handle()), win->get_size().x, win->get_size().y
)
)
) {
}
wayland_eglsurface::~wayland_eglsurface() {
wl_egl_window_destroy(reinterpret_cast<wl_egl_window*>(_eglwindow));
}
void wayland_eglsurface::resize(const ivec2& size) {
wl_egl_window_resize(reinterpret_cast<wl_egl_window*>(_eglwindow), size.x, size.y, 0, 0);
}
}

View File

@@ -16,30 +16,19 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file wayland_server.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#include <fennec/core/logger.h>
#include <fennec/platform/linux/wayland/server.h>
#include <fennec/platform/linux/wayland/window.h>
#include <fennec/platform/linux/wayland/lib/loader.h>
#include <fennec/platform/linux/wayland/lib/wayland.h>
#include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.h>
#include <fennec/renderers/interface/gfxcontext.h>
namespace fennec
{
wayland_server::wayland_server(fennec::platform* p)
: display_server(p)
: display_server_base(p)
, display(nullptr), registry(nullptr), compositor(nullptr), seat(nullptr), fifo(false) {
// load shared lib
@@ -91,6 +80,22 @@ void wayland_server::connect() {
disconnect();
return;
}
auto contexts = ctx_registry::get_type_list();
while (not contexts.empty()) {
const auto& ctx = contexts.front();
gfx_context = ctx.ctor(this);
if (gfx_context->is_valid()) {
break;
} else {
delete gfx_context;
gfx_context = nullptr;
contexts.pop();
}
}
assertf(gfx_context != nullptr, "Failed to create graphics context.");
}
void wayland_server::disconnect() {
@@ -100,6 +105,10 @@ void wayland_server::disconnect() {
return;
}
// delete the gfx context
delete gfx_context;
// check compositor
if (compositor) {
wl_compositor_destroy(compositor);
@@ -115,7 +124,8 @@ void wayland_server::disconnect() {
wl_display_disconnect(display);
// clear vars
display = nullptr;
gfx_context = nullptr;
display = nullptr;
registry = nullptr;
compositor = nullptr;
seat = nullptr;
@@ -126,6 +136,10 @@ bool wayland_server::connected() const {
return display != nullptr;
}
void wayland_server::dispatch() {
wl_display_dispatch_pending(display);
}
window* wayland_server::create_window(const window::config& conf) {
size_t id = windows.insert(new wayland_window(this, windows.next_id(), conf));
return windows[id];

View File

@@ -16,29 +16,18 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================
///
/// \file window.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#include <fennec/platform/interface/display_server.h>
#include <fennec/platform/linux/wayland/server.h>
#include <fennec/platform/linux/wayland/window.h>
#include <fennec/platform/linux/wayland/lib/wayland.h>
#include <fennec/platform/linux/wayland/lib/headers/xdg-shell-client-protocols.h>
#include <fennec/renderers/interface/gfxcontext.h>
using namespace fennec;
wayland_window::wayland_window(display_server* server, uint32_t id, const config& cfg)
: window(server, id, cfg)
: window_base(server, id, cfg)
, surface(nullptr)
, xdgsurface(nullptr) {
@@ -99,10 +88,12 @@ void wayland_window::show() {
cfg.flags.set(flag_visible);
cfg.flags.set(flag_running);
gfx_surface = wl_server->get_gfx_context()->create_surface(this);
}
void wayland_window::hide() {
if (not is_visible()) {
if (not is_running()) {
return;
}
@@ -134,9 +125,8 @@ void wayland_window::hide() {
cfg.flags.clear(flag_running);
}
void wayland_window::dispatch() {
wayland_server* wl_server = static_cast<wayland_server*>(server);
wl_display_dispatch(wl_server->display);
void* wayland_window::get_native_handle() {
return surface;
}
bool wayland_window::set_flag(uint8_t, bool) {
@@ -156,5 +146,11 @@ void wayland_window::listen_xdg_surface_configure(void*, xdg_surface* xdg, uint3
void wayland_window::listen_xdg_toplevel_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*) {}
void wayland_window::listen_xdg_toplevel_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t) {}
void wayland_window::listen_xdg_toplevel_close(void*, xdg_toplevel*) {}
void wayland_window::listen_xdg_toplevel_close(void* data, xdg_toplevel*) {
wayland_window* window = static_cast<wayland_window*>(data);
window->hide();
}
void wayland_window::listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*) {}