3 #define GLX_GLXEXT_PROTOTYPES
6 #include <msp/strings/format.h>
7 #include <msp/strings/utils.h>
17 Extension::Extension(const char *n, InitFunc f):
24 Extension::operator bool() const
28 support = init_func();
32 return support>UNSUPPORTED;
36 Require::Require(const Extension &ext)
39 throw unsupported_extension(ext.get_name());
43 bool is_supported(const string &ext)
45 static set<string> extensions;
46 static bool init_done = false;
50 if(const char *gl_ext = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
52 vector<string> exts = split(gl_ext);
53 extensions.insert(exts.begin(), exts.end());
59 return extensions.count(ext);
62 const Version &get_gl_version()
64 static Version version;
65 static bool init_done = false;
69 string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
70 vector<string> parts = split(gl_ver.substr(0, gl_ver.find(' ')), '.');
71 version.major = lexical_cast<unsigned>(parts[0]);
72 version.minor = lexical_cast<unsigned>(parts[1]);
80 bool is_version_at_least(unsigned a, unsigned b)
82 const Version &ver = get_gl_version();
83 return (ver.major>a || (ver.major==a && ver.minor>=b));
86 ExtFunc *get_proc_address(const string &name)
89 return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));
91 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));