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