fennec
Loading...
Searching...
No Matches
platform.h
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
19#ifndef FENNEC_PLATFORM_INTERFACE_PLATFORM_H
20#define FENNEC_PLATFORM_INTERFACE_PLATFORM_H
21
22#include <fennec/string/cstring.h>
23
25
26#include <fennec/rtti/enable.h>
28#include <fennec/rtti/detail/_this_t.h>
29
30/*
31 * This class should resemble the target platform as a whole. By itself, it will represent the OS, i.e. Linux, Windows,
32 * etc.
33 *
34 * We want everything to be type agnostic from the top level down
35 *
36 * The general structure is:
37 * Platform -> Display Protocol -> GFX Context -> GFX API
38 * -> Window -> GFX Surface
39 * -> Input Protocol
40 *
41 * For example, let's say we are on Linux, using Wayland and OpenGL with EGL
42 * EGL will know that we are using OpenGL, but won't know we are using Wayland
43 * OpenGL won't know or care that Linux, EGL, or Wayland is being used
44 * Wayland won't know or care that OpenGL or EGL is being used
45 * Linux won't know or care that OpenGL, Wayland, or EGL are in use
46 *
47 * Why do we want everything to be type agnostic?
48 * Let's say someone wants to add a DirectX extension for Windows. They shouldn't have to touch the
49 * Windows platform class or Win32 display manager class at all to write the implementation. This
50 * allows the extension to remain entirely independent of the engine which allows you to just drop
51 * it into your project, and it will work as expected. This should also keep version compatibility
52 * issues to the absolute minimum.
53 *
54 * We can allow this by notifying the platform of all available drivers at startup and give them priorities.
55 * Then, the platform will load the highest priority first, only falling back when a driver fails to load or is
56 * deemed incompatible for whatever reason.
57 *
58 *
59 */
60
61namespace fennec
62{
63
66class platform : public singleton<platform*> {
67public:
68 using shared_object = struct shared_object;
69 using symbol = void*;
70
71 platform();
72 virtual ~platform() = default;
73 platform(const platform&) = delete;
74
75 // Dynamically linked objects
76 virtual shared_object* load_object(const cstring& file) = 0;
77 virtual void unload_object(shared_object* obj) = 0;
78 virtual symbol find_symbol(shared_object* obj, const cstring& name) = 0;
79
80 virtual void initialize(); // Initialize Drivers and Contexts
81 virtual void shutdown(); // Close Drivers and Contexts
82
83protected:
85
86 FENNEC_RTTI_CLASS_ENABLE() {
87 }
88};
89
90}
91
92#endif // FENNEC_PLATFORM_INTERFACE_PLATFORM_H
Structure for handling streams of data.
Definition file.h:75
Main platform class.
Definition platform.h:66
Definition pointers.h:87
This struct wraps c-style strings.
Definition cstring.h:64