]> git.tdb.fi Git - libs/gui.git/blob - source/graphics/glcontext.h
ef374c1038efc6da274d5b62b370656a4b3fe2f7
[libs/gui.git] / source / graphics / glcontext.h
1 #ifndef MSP_GRAPHICS_GLCONTEXT_H_
2 #define MSP_GRAPHICS_GLCONTEXT_H_
3
4 #include <stdexcept>
5
6 namespace Msp {
7 namespace Graphics {
8
9 class Display;
10 class Window;
11
12 struct GLOptions
13 {
14         static constexpr unsigned DEFAULT_VERSION = 0;
15         static constexpr unsigned LATEST_VERSION = 0xFFFFFFFF;
16
17         bool alpha = false;
18         bool stencil = false;
19         bool doublebuffer = true;
20         unsigned multisample = 0;
21         bool forward_compatible = false;
22         bool core_profile = false;
23         unsigned gl_version_major = DEFAULT_VERSION;
24         unsigned gl_version_minor = DEFAULT_VERSION;
25 };
26
27
28 class unsupported_gl_mode: public std::runtime_error
29 {
30 public:
31         unsupported_gl_mode(const GLOptions &);
32
33 private:
34         static std::string format_version(const GLOptions &);
35 };
36
37
38 class GLContext
39 {
40 private:
41         struct Private;
42
43         Display &display;
44         Window &window;
45         Private *priv = nullptr;
46
47 public:
48         GLContext(Window &wnd, const GLOptions &opts = GLOptions());
49         GLContext(Window &wnd, unsigned, unsigned);
50 private:
51         void platform_init(const GLOptions &);
52 public:
53         ~GLContext();
54
55         void set_swap_interval(unsigned);
56
57         void swap_buffers();
58 private:
59         void window_resized(unsigned, unsigned);
60 };
61
62 } // namespace Graphics
63 } // namespace Msp
64
65 #endif