]> git.tdb.fi Git - libs/gl.git/blob - source/extension.h
Add a class to unify loading coordinate transforms
[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         bool operator<(const Version &o) const { return !(*this>=o); }
33         operator bool() const { return major || minor; }
34 };
35
36
37 /**
38 Holds metadata about an extension.  Evaluates to true if the extension is
39 supported.
40 */
41 class Extension
42 {
43 public:
44         enum SupportLevel
45         {
46                 UNSUPPORTED,
47                 EXTENSION,
48                 CORE
49         };
50
51         typedef SupportLevel (*InitFunc)();
52
53 private:
54         const char *name;
55         InitFunc init_func;
56         mutable bool init_done;
57         mutable SupportLevel support;
58
59 public:
60         Extension(const char *, InitFunc);
61
62         const char *get_name() const { return name; }
63         operator bool() const;
64 };
65
66
67 struct Require
68 {
69         Require(const Extension &);
70 };
71
72
73 typedef void ExtFunc();
74
75 /** Checks for extension support.  Only intended for internal use. */
76 bool is_supported(const std::string &);
77
78 /** Checks for OpenGL version support.  Only intended for internal use. */
79 bool is_supported(const Version &, const Version & = Version());
80
81 /** Indicates whether an extension has been disabled, either explicitly through
82 the MSPGL_DISABLE_EXTENSIONS environment variable or implicitly as a workaround
83 for a driver bug.  Only intended for internal use. */
84 bool is_disabled(const std::string &);
85
86 /** Returns the API for which the library was compiled. */
87 GLApi get_gl_api();
88
89 /** Returns the OpenGL profile for the active context. */
90 GLProfile get_gl_profile();
91
92 /** Returns the OpenGL version number, as reported by the implementation. */
93 const Version &get_gl_version();
94
95 /** Returns the GLSL version number, as reported by the implementation. */
96 const Version &get_glsl_version();
97
98 /** Returns the address of an extension function.  Only indended for internal
99 use. */
100 ExtFunc *get_proc_address(const std::string &);
101
102 } // namespace GL
103 } // namespace Msp
104
105 #endif