]> git.tdb.fi Git - libs/gui.git/blob - source/graphics/glcontext.cpp
Add support for using the latest available OpenGL version
[libs/gui.git] / source / graphics / glcontext.cpp
1 #include <stdexcept>
2 #include <msp/strings/format.h>
3 #include "glcontext.h"
4 #include "window.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace Graphics {
10
11 GLOptions::GLOptions():
12         alpha(false),
13         stencil(false),
14         doublebuffer(true),
15         multisample(0),
16         forward_compatible(false),
17         core_profile(false),
18         gl_version_major(DEFAULT_VERSION),
19         gl_version_minor(DEFAULT_VERSION)
20 { }
21
22
23 unsupported_gl_mode::unsupported_gl_mode(const GLOptions &opts):
24         runtime_error(format("{ .alpha=%s, .stencil=%s, .doublebuffer=%s, .multisample=%d, .forward_compatible=%s, .core_profile=%s, .gl_version=%s }",
25                 opts.alpha, opts.stencil, opts.doublebuffer, opts.multisample, opts.forward_compatible, opts.core_profile, format_version(opts)))
26 { }
27
28 string unsupported_gl_mode::format_version(const GLOptions &opts)
29 {
30         if(opts.gl_version_major==GLOptions::LATEST_VERSION)
31                 return "LATEST";
32         else if(opts.gl_version_major==GLOptions::DEFAULT_VERSION)
33                 return "DEFAULT";
34         else
35                 return format("%d.%d", opts.gl_version_major, opts.gl_version_minor);
36 }
37
38
39
40 GLContext::GLContext(Window &wnd, const GLOptions &opts):
41         display(wnd.get_display()),
42         window(wnd)
43 {
44         platform_init(opts);
45
46         window.signal_resize.connect(sigc::mem_fun(this, &GLContext::window_resized));
47 }
48
49 #ifndef WITH_OPENGL
50 void GLContext::platform_init(const GLOptions &)
51 {
52         throw runtime_error("no OpenGL support");
53 }
54
55 GLContext::~GLContext()
56 { }
57
58 void GLContext::set_swap_interval(unsigned)
59 { }
60
61 void GLContext::swap_buffers()
62 { }
63
64 void GLContext::window_resized(unsigned, unsigned)
65 { }
66 #endif
67
68 } // namespace Graphics
69 } // namespace Msp