Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
context.hpp
Go to the documentation of this file.
1
3#pragma once
4
7#include <aegis2d/render/export.hpp>
8
9#include <cstddef>
10#include <cstdint>
11#include <memory>
12#include <stdexcept>
13#include <string>
14
19
22class AEGIS2D_RENDER_EXPORT ContextError : public std::runtime_error {
23public:
24 using std::runtime_error::runtime_error;
25};
26
28struct Version {
30 int major = 0;
32 int minor = 0;
33};
34
36enum class DebugOutput : std::uint8_t {
38 Off,
44 Polling,
45};
46
49[[nodiscard]] AEGIS2D_RENDER_EXPORT bool debug_build() noexcept;
50
54 bool vsync = true;
57 bool debug = debug_build();
58};
59
61struct DriverInfo {
63 std::string vendor;
65 std::string renderer;
67 std::string version;
68};
69
77class AEGIS2D_RENDER_EXPORT Context {
78public:
85 explicit Context(const platform::Window& window, const ContextConfig& config = {});
86
87 Context(const Context&) = delete;
88 Context& operator=(const Context&) = delete;
90 Context(Context&& other) noexcept;
93 Context& operator=(Context&& other) noexcept;
96
100
105 void clear(Color color);
106
110
114 [[nodiscard]] DebugOutput debug_output() const noexcept;
115
121 std::size_t check_errors();
122
125 [[nodiscard]] Version version() const noexcept;
126
129 [[nodiscard]] static Version required_version() noexcept;
130
133 [[nodiscard]] const DriverInfo& info() const noexcept;
134
135private:
136 struct Impl;
137 std::unique_ptr<Impl> impl_;
138};
139
140} // namespace aegis2d::render::opengl
Desktop window: creation, size and events. Drawing is left to a render backend.
Definition window.hpp:61
Thrown when the OpenGL context cannot be created or is too old.
Definition context.hpp:22
OpenGL core profile context of a window, with every OpenGL function loaded.
Definition context.hpp:77
~Context()
Destroys the context.
DebugOutput debug_output() const noexcept
How OpenGL errors are reported for this context.
Context(Context &&other) noexcept
Takes over the context of other, which must not be used afterwards.
void swap_buffers()
Shows the frame drawn since the previous call.
Context & operator=(Context &&other) noexcept
Destroys this context and takes over the context of other.
Context & operator=(const Context &)=delete
Context(const Context &)=delete
void clear(Color color)
Fills the whole framebuffer with one color.
void make_current()
Makes the context current on the calling thread.
Context(const platform::Window &window, const ContextConfig &config={})
Creates the context, makes it current and loads the OpenGL functions.
RGBA color used by the renderer.
OpenGL backend of the renderer.
Definition context.hpp:18
bool debug_build() noexcept
Whether the engine was built for debugging.
DebugOutput
How a context reports OpenGL errors.
Definition context.hpp:36
@ Callback
The driver reports each error, warning and hint as it happens (KHR_debug, OpenGL 4....
@ Off
Errors are not reported (release builds by default).
@ Polling
Errors are read with glGetError by each swap_buffers() and check_errors() call (macOS,...
Definition endpoint.hpp:85
RGBA color with components in [0, 1].
Definition color.hpp:10
Settings of a new context.
Definition context.hpp:52
Driver strings of a context.
Definition context.hpp:61
std::string version
Full version string (GL_VERSION).
Definition context.hpp:67
std::string vendor
Company behind the driver (GL_VENDOR).
Definition context.hpp:63
std::string renderer
GPU or software renderer (GL_RENDERER).
Definition context.hpp:65
Version of an OpenGL context.
Definition context.hpp:28
int minor
Minor version, e.g. 5.
Definition context.hpp:32
int major
Major version, e.g. 4.
Definition context.hpp:30
SDL3 desktop window with its events, keyboard, mouse and gamepads, independent of the graphics API.