- Switched to SDL for main branch, will revisit custom implementation later.
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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/interface/display.h>
|
||||
#include <fennec/platform/interface/gfxcontext.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
display::~display() {
|
||||
delete _context;
|
||||
}
|
||||
|
||||
void display::select_context() {
|
||||
if (_context != nullptr) return;
|
||||
|
||||
const platform::global_context& globals = platform::get_globals();
|
||||
for (const auto& ctx : globals.graphics) {
|
||||
_context = ctx.constructor(this);
|
||||
if (_context) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#include <fennec/platform/interface/display.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
|
||||
namespace fennec
|
||||
@@ -37,37 +36,9 @@ static constexpr void insert_driver(list<platform::driver<CtorT>>& drvrs, CtorT
|
||||
}
|
||||
|
||||
void platform::initialize() {
|
||||
load_display();
|
||||
_display->select_context();
|
||||
}
|
||||
|
||||
void platform::shutdown() {
|
||||
delete _display;
|
||||
}
|
||||
|
||||
void platform::load_display() {
|
||||
auto& globals = _get_globals();
|
||||
for (auto it : globals.displays) {
|
||||
_display = it.constructor(this);
|
||||
if (_display != nullptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void platform::add_driver(display_ctor ctor, int priority) {
|
||||
auto& globals = _get_globals();
|
||||
insert_driver(globals.displays, ctor, priority);
|
||||
}
|
||||
|
||||
void platform::add_driver(input_ctor ctor, int priority) {
|
||||
auto& globals = _get_globals();
|
||||
insert_driver(globals.inputs, ctor, priority);
|
||||
}
|
||||
|
||||
void platform::add_driver(gfxctx_ctor ctor, int priority) {
|
||||
auto& globals = _get_globals();
|
||||
insert_driver(globals.graphics, ctor, priority);
|
||||
}
|
||||
|
||||
platform::global_context& platform::_get_globals() {
|
||||
|
||||
@@ -29,11 +29,9 @@ STATIC_CONSTRUCTOR(_init_linux) {
|
||||
}
|
||||
|
||||
void linux_platform::initialize() {
|
||||
platform::initialize();
|
||||
}
|
||||
|
||||
void linux_platform::shutdown() {
|
||||
platform::shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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/display.h>
|
||||
#include <fennec/platform/linux/wayland/lib/loader.h>
|
||||
#include <fennec/platform/linux/wayland/lib/wayland.h>
|
||||
|
||||
#include <fennec/lang/startup.h>
|
||||
#include <fennec/platform/linux/wayland/window.h>
|
||||
#include <fennec/platform/linux/wayland/lib/headers/wayland-client-protocols.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
static display* _create_wayland_display(platform* platform) {
|
||||
wayland_display* display = new wayland_display(platform);
|
||||
if (not display->connected()) {
|
||||
delete display, display = nullptr;
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
STATIC_CONSTRUCTOR(_wayland_init) {
|
||||
platform::add_driver(_create_wayland_display, 1);
|
||||
}
|
||||
|
||||
wayland_display::wayland_display(platform* platform)
|
||||
: display(platform, "wayland", this)
|
||||
, _handle(nullptr)
|
||||
, _registry(nullptr)
|
||||
, _compositor(nullptr)
|
||||
, _seat(nullptr)
|
||||
, _shm(nullptr)
|
||||
, _fifo(false) {
|
||||
|
||||
static constexpr wl_registry_listener listener = {
|
||||
listen_global, listen_global_remove
|
||||
};
|
||||
|
||||
// Load libwayland.so
|
||||
libwayland::load_symbols(_platform);
|
||||
|
||||
// Get handles
|
||||
_handle = wl_display_connect(nullptr);
|
||||
if (not _handle) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the wayland registry
|
||||
_registry = wl_display_get_registry(_handle);
|
||||
if (not _registry) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// Add listener for interfaces
|
||||
wl_registry_add_listener(_registry, &listener, this);
|
||||
wl_display_roundtrip(_handle);
|
||||
|
||||
// Check for fifo v1, wayland's builtin fifo only allows one frame to be in flight at a time
|
||||
if (not _fifo) {
|
||||
assert(_fifo, "Compositor does not support fifo-v1 protocol, falling back to other display protocols.");
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
wayland_display::~wayland_display() {
|
||||
if (_handle) {
|
||||
cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
bool wayland_display::connected() const {
|
||||
return _handle != nullptr;
|
||||
}
|
||||
|
||||
window* wayland_display::create_window(window* parent) {
|
||||
return new wayland_window(this, static_cast<wayland_window*>(parent));
|
||||
}
|
||||
|
||||
void wayland_display::cleanup() {
|
||||
|
||||
// Cleanup members
|
||||
if (_compositor) wl_compositor_destroy(_compositor);
|
||||
if (_registry) wl_registry_destroy(_registry);
|
||||
if (_handle) {
|
||||
wl_display_flush(_handle);
|
||||
wl_display_disconnect(_handle);
|
||||
}
|
||||
|
||||
_compositor = nullptr;
|
||||
_registry = nullptr;
|
||||
_handle = nullptr;
|
||||
|
||||
libwayland::unload_symbols(_platform);
|
||||
}
|
||||
|
||||
void wayland_display::listen_global(void* data, wl_registry* registry, uint32_t name, const char* itfc, uint32_t version) {
|
||||
static constexpr wl_seat_listener seat_listener = {
|
||||
listen_seat, nullptr
|
||||
};
|
||||
|
||||
wayland_display* device = static_cast<wayland_display*>(data);
|
||||
const cstring interface = cstring(itfc, strlen(itfc) + 1);
|
||||
|
||||
if (interface == "wl_compositor") {
|
||||
device->_compositor = static_cast<wl_compositor*>(wl_registry_bind(registry, name, &wl_compositor_interface, version));
|
||||
} else if (interface == "wl_seat") {
|
||||
device->_seat = static_cast<wl_seat*>(wl_registry_bind(registry, name, &wl_seat_interface, version));
|
||||
wl_seat_add_listener(device->_seat, &seat_listener, device);
|
||||
} else if (interface == "wp_fifo_manager_v1") {
|
||||
device->_fifo = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void wayland_display::listen_global_remove(void*, wl_registry*, uint32_t) {
|
||||
}
|
||||
|
||||
void wayland_display::listen_seat(void*, wl_seat*, uint32_t) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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/lib/headers/wayland-client-protocols.h>
|
||||
#include <fennec/platform/linux/wayland/lib/loader.h>
|
||||
|
||||
#define FENNEC_LIB(name) bool FENNEC_HAS_LIB_##name;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) using WAYLAND_sym_##fn = ret(*)(__VA_ARGS__); \
|
||||
WAYLAND_sym_##fn WAYLAND_##fn;
|
||||
#define FENNEC_GLOBAL(type, name) type* WAYLAND_##name;
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
namespace libwayland
|
||||
{
|
||||
|
||||
using shared_object = platform::shared_object;
|
||||
|
||||
struct shared_lib {
|
||||
shared_object* obj;
|
||||
const cstring name;
|
||||
};
|
||||
|
||||
static int _load_count = 0;
|
||||
|
||||
// Create private variables
|
||||
#define FENNEC_LIB(lib) static shared_lib _FENNEC_LIB_##lib = { nullptr, FENNEC_LIB_##lib };
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
|
||||
bool load_symbols(platform* platform) {
|
||||
if (_load_count++ != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_lib* current_lib = nullptr;
|
||||
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib.obj = platform->load_object(_FENNEC_LIB_##lib.name); \
|
||||
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib.obj != nullptr; \
|
||||
if(not FENNEC_HAS_LIB_##lib) { \
|
||||
unload_symbols(platform); \
|
||||
return false; \
|
||||
} \
|
||||
current_lib = &_FENNEC_LIB_##lib;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) WAYLAND_##fn = (WAYLAND_sym_##fn)(platform->find_symbol(current_lib->obj, #fn)); \
|
||||
assertf(WAYLAND_##fn != nullptr, "Failed to find symbol: " #fn);
|
||||
#define FENNEC_GLOBAL(type, name) WAYLAND_##name = (type*)(platform->find_symbol(current_lib->obj, #name)); \
|
||||
assertf(WAYLAND_##name != nullptr, "Failed to find global: " #name);
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void unload_symbols(platform* platform) {
|
||||
if (--_load_count != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib.obj); \
|
||||
_FENNEC_LIB_##lib.obj = nullptr;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) WAYLAND_##fn = nullptr;
|
||||
#define FENNEC_GLOBAL(type, name) WAYLAND_##name = nullptr;
|
||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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/interface/gfxcontext.h>
|
||||
#include <fennec/platform/interface/gfxsurface.h>
|
||||
|
||||
#include <fennec/platform/linux/wayland/window.h>
|
||||
#include <fennec/platform/linux/wayland/lib/wayland.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
bool wayland_window::running() {
|
||||
return _surface != nullptr;
|
||||
}
|
||||
|
||||
void wayland_window::configure(const config& config) {
|
||||
_config = config;
|
||||
}
|
||||
|
||||
bool wayland_window::initialize(bool) {
|
||||
|
||||
wayland_display* display = static_cast<wayland_display*>(_display);
|
||||
|
||||
_handle = wl_compositor_create_surface(display->get_compositor());
|
||||
|
||||
_surface = display->get_context()->create_surface(this);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::shutdown() {
|
||||
delete _surface;
|
||||
wl_surface_destroy(_handle);
|
||||
_display = nullptr;
|
||||
_surface = nullptr;
|
||||
_shell = nullptr;
|
||||
_handle = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::set_title(const cstring& title) {
|
||||
if (not _config) {
|
||||
return true;
|
||||
}
|
||||
_config->title = title;
|
||||
wl_shell_surface_set_title(_shell, _config->title.cstr());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::set_title(const string& title) {
|
||||
if (not _config) {
|
||||
return true;
|
||||
}
|
||||
_config->title = title;
|
||||
wl_shell_surface_set_title(_shell, _config->title.cstr());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::set_width(size_t w) {
|
||||
if (not _config) {
|
||||
return true;
|
||||
}
|
||||
_config->width = w;
|
||||
_surface->resize(_config->width, _config->height);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::set_height(size_t h) {
|
||||
if (not _config) {
|
||||
return true;
|
||||
}
|
||||
_config->height = h;
|
||||
_surface->resize(_config->width, _config->height);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::resize(size_t w, size_t h) {
|
||||
if (not _config) {
|
||||
return true;
|
||||
}
|
||||
_config->width = w;
|
||||
_config->height = h;
|
||||
_surface->resize(_config->width, _config->height);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wayland_window::set_resizable(bool) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
bool wayland_window::set_fullscreen_mode(fullscreen_mode) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
bool wayland_window::grab_keyboard(bool) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
bool wayland_window::grab_mouse(bool) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
bool wayland_window::block_screensaver(bool) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
wayland_window::wayland_window(wayland_display* display, wayland_window* parent)
|
||||
: window(display, parent, this)
|
||||
, _handle()
|
||||
, _shell()
|
||||
, _nfs_width(0), _nfs_height(0) {
|
||||
}
|
||||
|
||||
wayland_window::~wayland_window() {
|
||||
wayland_window::shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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/xkb/lib/xkb.h>
|
||||
#include <fennec/platform/linux/xkb/lib/loader.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
|
||||
#define FENNEC_LIB(name) bool FENNEC_HAS_LIB_##name;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) using XKB_sym_##fn = ret(*)(__VA_ARGS__); \
|
||||
XKB_sym_##fn XKB_##fn;
|
||||
#define FENNEC_GLOBAL(type, name) type* XKB_##name;
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
namespace libxkbcommon
|
||||
{
|
||||
|
||||
using shared_object = platform::shared_object;
|
||||
|
||||
struct shared_lib {
|
||||
shared_object* obj;
|
||||
const cstring name;
|
||||
};
|
||||
|
||||
static int _load_count = 0;
|
||||
|
||||
// Create private variables
|
||||
#define FENNEC_LIB(lib) static shared_lib _FENNEC_LIB_##lib = { nullptr, FENNEC_LIB_##lib };
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
|
||||
bool load_symbols(platform* platform) {
|
||||
if (_load_count++ != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
shared_lib* current_lib = nullptr;
|
||||
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib.obj = platform->load_object(_FENNEC_LIB_##lib.name); \
|
||||
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib.obj != nullptr; \
|
||||
if(not FENNEC_HAS_LIB_##lib) { \
|
||||
unload_symbols(platform); \
|
||||
return false; \
|
||||
} \
|
||||
current_lib = &_FENNEC_LIB_##lib;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) XKB_##fn = (XKB_sym_##fn)(platform->find_symbol(current_lib->obj, #fn)); \
|
||||
assertf(XKB_##fn != nullptr, "Failed to find symbol: " #fn);
|
||||
#define FENNEC_GLOBAL(type, name) XKB_##name = (type*)(platform->find_symbol(current_lib->obj, #name)); \
|
||||
assertf(XKB_##name != nullptr, "Failed to find global: " #name);
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void unload_symbols(platform* platform) {
|
||||
if (--_load_count != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib.obj); \
|
||||
_FENNEC_LIB_##lib.obj = nullptr;
|
||||
#define FENNEC_SYMBOL(ret, fn, ...) XKB_##fn = nullptr;
|
||||
#define FENNEC_GLOBAL(type, name) XKB_##name = nullptr;
|
||||
#include <fennec/platform/linux/xkb/lib/sym.h>
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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/langproc/filesystem/file.h>
|
||||
#include <fennec/lang/startup.h>
|
||||
#include <fennec/platform/interface/display.h>
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
#include <fennec/platform/opengl/egl/context.h>
|
||||
#include <fennec/platform/opengl/egl/surface.h>
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
static gfxcontext* _create_egl_context(display* display) {
|
||||
eglcontext* ctx = new eglcontext(display);
|
||||
if (not ctx->connected()) {
|
||||
delete ctx, ctx = nullptr;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
||||
STATIC_CONSTRUCTOR(_egl_init) {
|
||||
platform::add_driver(_create_egl_context, 1);
|
||||
}
|
||||
|
||||
eglcontext::eglcontext(display* display)
|
||||
: gfxcontext(display, "EGL", this)
|
||||
, _egldisplay(nullptr), _eglcontext(nullptr)
|
||||
, _eglconfig(), _eglvmajor(0), _eglvminor(0)
|
||||
, _eglctype(0), _extensions(nullptr) {
|
||||
|
||||
// Get the display format
|
||||
const display::pixel_format& fmt = _display->get_color_format();
|
||||
|
||||
// Currently empty
|
||||
EGLint context_attrs[] = {
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
// Configure the depth and rgb bit-depth
|
||||
EGLint config_attrs[] = {
|
||||
EGL_SURFACE_TYPE,
|
||||
EGL_WINDOW_BIT,
|
||||
EGL_DEPTH_SIZE, fmt.depth,
|
||||
EGL_RED_SIZE, fmt.r,
|
||||
EGL_RED_SIZE, fmt.g,
|
||||
EGL_RED_SIZE, fmt.b,
|
||||
|
||||
EGL_RENDERABLE_TYPE,
|
||||
EGL_OPENGL_BIT, // 7
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
// Attempt to retrieve an egl display from the native display
|
||||
_egldisplay = eglGetDisplay(_display->get_native_handle());
|
||||
if (_egldisplay == nullptr) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// Attempt to initialize egl
|
||||
if (not eglInitialize(_egldisplay, nullptr, nullptr)) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// Attempt to bind to Core OpenGL, otherwise OpenGL ES
|
||||
if (not eglBindAPI(EGL_OPENGL_API)) {
|
||||
if (not eglBindAPI(EGL_OPENGL_ES_API)) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
config_attrs[7] = EGL_OPENGL_ES_BIT; // Change the support bit to OpenGL ES
|
||||
}
|
||||
|
||||
// Select a configuration
|
||||
EGLint n;
|
||||
if (not eglChooseConfig(_egldisplay, config_attrs, &_eglconfig, 1, &n)) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the context
|
||||
_eglcontext = eglCreateContext(_egldisplay, _eglconfig, EGL_NO_CONTEXT, context_attrs);
|
||||
if (_eglcontext == nullptr) {
|
||||
cleanup();
|
||||
return;
|
||||
}
|
||||
|
||||
// make this the current context so we can retrieve the information below
|
||||
eglMakeCurrent(_egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, _eglcontext);
|
||||
|
||||
// Query available extensions
|
||||
const char* ptr = eglQueryString(_egldisplay, EGL_EXTENSIONS);
|
||||
_extensions = { ptr, strlen(ptr) + 1 };
|
||||
|
||||
// Query the context and version
|
||||
eglQueryContext(_egldisplay, _eglcontext, EGL_CONTEXT_CLIENT_TYPE, &_eglctype);
|
||||
glGetIntegerv(GL_MAJOR_VERSION, &_eglvmajor);
|
||||
glGetIntegerv(GL_MINOR_VERSION, &_eglvminor);
|
||||
}
|
||||
|
||||
eglcontext::~eglcontext() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
bool eglcontext::connected() {
|
||||
return _eglcontext != nullptr;
|
||||
}
|
||||
|
||||
const cstring& eglcontext::get_name() {
|
||||
static constexpr cstring opengl = "OpenGL";
|
||||
static constexpr cstring gles = "GLES";
|
||||
static constexpr cstring openvg = "OpenVG"; // this should never be used
|
||||
switch (_eglctype) {
|
||||
default:
|
||||
case EGL_OPENGL_API: return opengl;
|
||||
case EGL_OPENGL_ES_API: return gles;
|
||||
case EGL_OPENVG_API: return openvg;
|
||||
}
|
||||
}
|
||||
|
||||
bool eglcontext::check_extension(const cstring& ext) {
|
||||
return _extensions.find(ext) != _extensions.size();
|
||||
}
|
||||
|
||||
gfxsurface* eglcontext::create_surface(window* window) {
|
||||
return new eglsurface(this, window);
|
||||
}
|
||||
|
||||
void eglcontext::make_current(gfxsurface* surface) {
|
||||
eglsurface* eglsurface = static_cast<fennec::eglsurface*>(surface);
|
||||
eglMakeCurrent(_egldisplay, eglsurface->get_egl_surface(), eglsurface->get_egl_surface(), _eglcontext);
|
||||
}
|
||||
|
||||
void eglcontext::cleanup() {
|
||||
eglMakeCurrent(_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||
eglDestroyContext(_display, _eglcontext);
|
||||
eglTerminate(_display);
|
||||
eglReleaseThread();
|
||||
|
||||
_egldisplay = nullptr;
|
||||
_eglconfig = nullptr;
|
||||
_eglcontext = nullptr;
|
||||
_eglvmajor = 0;
|
||||
_eglvminor = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// 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/opengl/egl/surface.h>
|
||||
#include <fennec/platform/linux/wayland/lib/wayland.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
eglsurface::~eglsurface() {
|
||||
if (_window->is_type<wayland_window>()) {
|
||||
wl_egl_window_destroy(static_cast<wl_egl_window*>(_handle));
|
||||
}
|
||||
}
|
||||
|
||||
void eglsurface::resize(size_t width, size_t height) {
|
||||
gfxsurface::resize(width, height);
|
||||
if (_window->is_type<wayland_window>()) {
|
||||
wl_egl_window_resize(static_cast<wl_egl_window*>(_handle), width, height, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
eglsurface::eglsurface(eglcontext* context, window* window)
|
||||
: gfxsurface(context, window, this)
|
||||
, _handle(nullptr)
|
||||
, _surface(nullptr) {
|
||||
|
||||
const window::config& config = window->get_config();
|
||||
if (window->is_type<wayland_window>()) {
|
||||
_handle = wl_egl_window_create(window->get_native_handle(), config.width, config.height);
|
||||
}
|
||||
|
||||
assert(
|
||||
_handle != nullptr,
|
||||
"Failed to create egl window!"
|
||||
);
|
||||
|
||||
eglCreateWindowSurface(
|
||||
context->get_egl_display(),
|
||||
context->get_egl_config(),
|
||||
reinterpret_cast<EGLNativeWindowType>(_handle),
|
||||
nullptr
|
||||
);
|
||||
|
||||
assert(
|
||||
EGL_TRUE == eglMakeCurrent(context->get_egl_display(), _surface, _surface, context->get_egl_context()),
|
||||
"Failed to create egl window!"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user