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