]> git.tdb.fi Git - libs/gl.git/blob - source/extension.h
Add a function to determine the active GL profile
[libs/gl.git] / source / extension.h
1 #ifndef MSP_GL_EXTENSION_H_
2 #define MSP_GL_EXTENSION_H_
3
4 #include <string>
5
6 namespace Msp {
7 namespace GL {
8
9 enum GLApi
10 {
11         OPENGL,
12         OPENGL_ES2
13 };
14
15 enum GLProfile
16 {
17         CORE_PROFILE,
18         COMPATIBILITY_PROFILE
19 };
20
21
22 struct Version
23 {
24         unsigned short major;
25         unsigned short minor;
26
27         Version();
28         Version(unsigned short, unsigned short);
29         Version(const std::string &);
30
31         bool operator>=(const Version &) const;
32 };
33
34
35 class Extension
36 {
37 public:
38         enum SupportLevel
39         {
40                 UNSUPPORTED,
41                 EXTENSION,
42                 CORE
43         };
44
45         typedef SupportLevel (*InitFunc)();
46
47 private:
48         const char *name;
49         InitFunc init_func;
50         mutable bool init_done;
51         mutable SupportLevel support;
52
53 public:
54         Extension(const char *, InitFunc);
55
56         const char *get_name() const { return name; }
57         operator bool() const;
58 };
59
60
61 struct Require
62 {
63         Require(const Extension &);
64 };
65
66
67 typedef void ExtFunc();
68
69 /** Indicates whether an extension is supported. */
70 bool is_supported(const std::string &);
71
72 /** Returns the API for which the library was compiled. */
73 GLApi get_gl_api();
74
75 /** Returns the OpenGL profile for the active context. */
76 GLProfile get_gl_profile();
77
78 /** Returns the OpenGL version number, as reported by the implementation. */
79 const Version &get_gl_version();
80
81 /** Returns the GLSL version number, as reported by the implementation. */
82 const Version &get_glsl_version();
83
84 /** Indicates whether the OpenGL version is at least a.b. */
85 bool is_version_at_least(unsigned a, unsigned b);
86
87 /** Returns the address of an extension function.  Only indended for internal
88 use. */
89 ExtFunc *get_proc_address(const std::string &);
90
91 } // namespace GL
92 } // namespace Msp
93
94 #endif