forked from pyland/pyland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics_context.hpp
91 lines (70 loc) · 1.82 KB
/
graphics_context.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef GRAPHICS_CONTEXT_H
#define GRAPHICS_CONTEXT_H
extern "C" {
#ifdef USE_GLES
#include <EGL/egl.h>
#include <EGL/eglext.h>
#endif
}
#include "callback.hpp"
#include "callback_registry.hpp"
class GameWindow;
///
/// Used to unambiguously distinguish between and manage GL contexts.
///
/// The implementation is simply a wrapper around GameWindow which hides
/// the user from the internals of graphics management, whilst also
/// providing a system for resource clean up.
///
class GraphicsContext {
private:
friend class GameWindow;
///
/// The currently active context.
///
/// This is nullptr when no context is active.
///
static GraphicsContext* current;
///
/// The window with the one-to-one mapping with the GL context.
///
GameWindow* window;
///
/// Meant only for creation in and for GameWindow.
///
GraphicsContext(GameWindow* window);
///
/// Will release resources which were registered to this context.
///
~GraphicsContext();
///
/// Callback functions for cleaning up resources when the context
/// is destroyed.
///
CallbackRegistry<void> resource_releasers;
public:
///
/// Return true if the contexts use the same GL context.
///
/// Never used.
///
bool operator==(GraphicsContext other);
///
/// Start using this GL context.
///
/// Note that GameWindow will set the current active context.
///
void use();
///
/// Register a resource releaser, which will run when the context
/// is destroyed.
///
void register_resource_releaser(Callback<void> callback);
///
/// Get the current active context.
///
/// @return The active context or nullptr when no context is active.
///
static GraphicsContext* get_current();
};
#endif