- Implemented EGL Context
This commit is contained in:
@@ -62,6 +62,7 @@ public:
|
||||
static constexpr size_t npos = -1;
|
||||
|
||||
class iterator;
|
||||
class const_iterator;
|
||||
|
||||
private:
|
||||
struct node;
|
||||
@@ -100,7 +101,7 @@ public:
|
||||
|
||||
size_t n = it._n;
|
||||
size_t p = _next_free();
|
||||
_table[p].data = fennec::forward<value_t>(x);
|
||||
fennec::construct(&_table[p].data, fennec::forward<value_t>(x));
|
||||
if (n == npos) {
|
||||
if (empty()) {
|
||||
_root = p;
|
||||
@@ -256,6 +257,54 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class const_iterator {
|
||||
public:
|
||||
~const_iterator() {
|
||||
_list = nullptr;
|
||||
}
|
||||
|
||||
// prefix operator
|
||||
constexpr friend const_iterator& operator++(const_iterator& rhs) {
|
||||
if (rhs._list->_next(rhs._n) < rhs._list->capacity()) {
|
||||
return rhs;
|
||||
}
|
||||
rhs._n = npos;
|
||||
return rhs;
|
||||
}
|
||||
|
||||
constexpr friend const_iterator operator++(const_iterator& lhs, int) {
|
||||
const_iterator prev = lhs;
|
||||
++lhs;
|
||||
return prev;
|
||||
}
|
||||
|
||||
constexpr const value_t& operator*() {
|
||||
return *(_list->_table[_n].data);
|
||||
}
|
||||
|
||||
constexpr const value_t* operator->() {
|
||||
return &*(_list->_table[_n].data);
|
||||
}
|
||||
|
||||
constexpr bool operator==(const const_iterator& it) {
|
||||
return _list == it._list and _n == it._n;
|
||||
}
|
||||
|
||||
constexpr bool operator!=(const const_iterator& it) {
|
||||
return _list != it._list or _n != it._n;
|
||||
}
|
||||
|
||||
private:
|
||||
const list* _list;
|
||||
size_t _n;
|
||||
friend list;
|
||||
|
||||
const_iterator(const list* ls, size_t n)
|
||||
: _list(ls)
|
||||
, _n(n) {
|
||||
}
|
||||
};
|
||||
|
||||
constexpr iterator begin() {
|
||||
return iterator(this, _root);
|
||||
}
|
||||
@@ -264,6 +313,14 @@ public:
|
||||
return iterator(this, npos);
|
||||
}
|
||||
|
||||
constexpr const_iterator begin() const {
|
||||
return const_iterator(this, _root);
|
||||
}
|
||||
|
||||
constexpr const_iterator end() const {
|
||||
return const_iterator(this, npos);
|
||||
}
|
||||
|
||||
private:
|
||||
allocation<elem_t, alloc_t> _table;
|
||||
dynarray<size_t> _freed;
|
||||
@@ -306,15 +363,15 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
size_t _next(size_t n) {
|
||||
size_t _next(size_t n) const {
|
||||
return _table[n].next;
|
||||
}
|
||||
|
||||
size_t _prev(size_t n) {
|
||||
size_t _prev(size_t n) const {
|
||||
return _table[n].prev;
|
||||
}
|
||||
|
||||
size_t _walk(size_t i) {
|
||||
size_t _walk(size_t i) const {
|
||||
size_t n = _root;
|
||||
if (n == npos) return n;
|
||||
while (i > 0 && n != npos) {
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
#ifndef FENNEC_PLATFORM_INTERFACE_DISPLAY_H
|
||||
#define FENNEC_PLATFORM_INTERFACE_DISPLAY_H
|
||||
|
||||
#include <fennec/fproc/strings/string.h>
|
||||
#include <fennec/lang/types.h>
|
||||
#include <fennec/lang/typeuuid.h>
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
|
||||
namespace fennec
|
||||
@@ -38,7 +40,7 @@ public:
|
||||
};
|
||||
|
||||
virtual bool connected() const = 0;
|
||||
virtual ~display() = default;
|
||||
virtual ~display();
|
||||
|
||||
virtual window* create_window() = 0;
|
||||
|
||||
@@ -46,23 +48,25 @@ public:
|
||||
return _config.format;
|
||||
}
|
||||
|
||||
template<typename ContextT>
|
||||
ContextT* get_context() {
|
||||
return static_cast<ContextT*>(_context);
|
||||
}
|
||||
virtual void select_context();
|
||||
virtual void* get_native_handle() = 0;
|
||||
|
||||
template<typename PlatformT>
|
||||
PlatformT* get_platform() {
|
||||
return static_cast<PlatformT*>(_platform);
|
||||
}
|
||||
platform* get_platform() { return _platform; }
|
||||
gfxcontext* get_context() { return _context; }
|
||||
|
||||
const string name;
|
||||
const uint64_t uuid;
|
||||
|
||||
protected:
|
||||
platform* _platform;
|
||||
gfxcontext* _context;
|
||||
config _config;
|
||||
|
||||
explicit display(platform* platform)
|
||||
: _platform(platform)
|
||||
template<typename DisplayT>
|
||||
explicit display(platform* platform, const cstring& name, DisplayT*)
|
||||
: name(name)
|
||||
, uuid(typeuuid<DisplayT>())
|
||||
, _platform(platform)
|
||||
, _context(nullptr)
|
||||
, _config {
|
||||
.format = {
|
||||
|
||||
@@ -27,7 +27,7 @@ class display; // Handles display protocols
|
||||
class window; // Handles window surfaces of the display protocol
|
||||
class inputdevice; // Handles input devices
|
||||
class gfxcontext; // Handle Driver Contexts, i.e. EGL, WGL, VkWayland, etc.
|
||||
class gfxsurface; // Handle
|
||||
class gfxsurface; // Handle surface targets for windows
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,34 @@
|
||||
#ifndef FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H
|
||||
#define FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H
|
||||
|
||||
#include <fennec/fproc/strings/string.h>
|
||||
#include <fennec/lang/typeuuid.h>
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class gfxcontext {
|
||||
public:
|
||||
const string name;
|
||||
const uint64_t uuid;
|
||||
|
||||
virtual bool connected() = 0;
|
||||
virtual void make_current(gfxsurface* surface) = 0;
|
||||
|
||||
virtual ~gfxcontext() = default;
|
||||
|
||||
protected:
|
||||
display* _display;
|
||||
|
||||
template<typename ContextT>
|
||||
gfxcontext(display* display, const cstring& name, ContextT*)
|
||||
: name(name)
|
||||
, uuid(typeuuid<ContextT>())
|
||||
, _display(display) {
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <fennec/containers/list.h>
|
||||
#include <fennec/fproc/strings/cstring.h>
|
||||
#include <fennec/fproc/strings/string.h>
|
||||
#include <fennec/lang/typeuuid.h>
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
|
||||
/*
|
||||
@@ -31,7 +32,7 @@
|
||||
* We want everything to be type agnostic from the top level down
|
||||
*
|
||||
* The general structure is:
|
||||
* Platform -> Display Protocol -> GFX API -> GFX Context
|
||||
* Platform -> Display Protocol -> GFX Context -> GFX API
|
||||
* -> Window -> GFX Surface
|
||||
* -> Input Protocol
|
||||
*
|
||||
@@ -64,6 +65,7 @@ public:
|
||||
using symbol = void*;
|
||||
|
||||
const string name;
|
||||
const uint64_t uuid;
|
||||
|
||||
virtual ~platform() = default;
|
||||
|
||||
@@ -78,8 +80,10 @@ public:
|
||||
display* get_display() { return _display; }
|
||||
|
||||
protected:
|
||||
explicit platform(const cstring& name)
|
||||
: name(name) {
|
||||
template<typename PlatformT>
|
||||
explicit platform(const cstring& name, PlatformT*)
|
||||
: name(name)
|
||||
, uuid(typeuuid<PlatformT>()) {
|
||||
auto& globals = _get_globals();
|
||||
assertf(globals.singleton == nullptr, "Conflicting Platform Definitions.");
|
||||
globals.singleton = this;
|
||||
@@ -105,11 +109,6 @@ public:
|
||||
ctor constructor;
|
||||
};
|
||||
|
||||
static void add_driver(display_ctor ctor, int priority);
|
||||
static void add_driver(input_ctor ctor, int priority);
|
||||
static void add_driver(gfxctx_ctor ctor, int priority);
|
||||
|
||||
private:
|
||||
struct global_context {
|
||||
platform* singleton;
|
||||
list<driver<display_ctor>> displays;
|
||||
@@ -121,6 +120,11 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
static void add_driver(display_ctor ctor, int priority);
|
||||
static void add_driver(input_ctor ctor, int priority);
|
||||
static void add_driver(gfxctx_ctor ctor, int priority);
|
||||
|
||||
private:
|
||||
static global_context& _get_globals();
|
||||
|
||||
public:
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace fennec
|
||||
class linux_platform : public unix_platform {
|
||||
public:
|
||||
linux_platform()
|
||||
: unix_platform("linux") {
|
||||
: unix_platform("linux", this) {
|
||||
}
|
||||
|
||||
void initialize() override;
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
~wayland_display() override;
|
||||
|
||||
bool connected() const override;
|
||||
void* get_native_handle() override { return _handle; }
|
||||
|
||||
window* create_window() override;
|
||||
|
||||
|
||||
49
include/fennec/platform/opengl/egl/context.h
Normal file
49
include/fennec/platform/opengl/egl/context.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// =====================================================================================================================
|
||||
// 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/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#ifndef FENNEC_PLATFORM_OPENGL_EGL_CONTEXT_H
|
||||
#define FENNEC_PLATFORM_OPENGL_EGL_CONTEXT_H
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <fennec/platform/interface/gfxcontext.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class eglcontext : public gfxcontext {
|
||||
public:
|
||||
eglcontext(display* display);
|
||||
|
||||
~eglcontext() override;
|
||||
|
||||
bool connected() override;
|
||||
|
||||
void make_current(gfxsurface* surface) override;
|
||||
|
||||
private:
|
||||
EGLDisplay _egldisplay;
|
||||
EGLContext _eglcontext;
|
||||
EGLConfig _eglconfig;
|
||||
EGLint _eglvmajor, _eglvminor;
|
||||
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_PLATFORM_OPENGL_EGL_CONTEXT_H
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#ifndef FENNEC_PLATFORM_UNIX_UNIX_PLATFORM_H
|
||||
#define FENNEC_PLATFORM_UNIX_UNIX_PLATFORM_H
|
||||
|
||||
#include <fennec/platform/interface/platform.h>
|
||||
|
||||
namespace fennec
|
||||
@@ -25,8 +26,9 @@ namespace fennec
|
||||
|
||||
class unix_platform : public platform {
|
||||
public:
|
||||
explicit unix_platform(const cstring& name)
|
||||
: platform(name) {
|
||||
template<typename PlatformT>
|
||||
explicit unix_platform(const cstring& name, PlatformT*)
|
||||
: platform(name, (PlatformT*)(nullptr)) {
|
||||
}
|
||||
|
||||
shared_object* load_object(const cstring& file) override;
|
||||
|
||||
Reference in New Issue
Block a user