2 #if !defined(WIN32) && !defined(__APPLE__)
3 #define GLX_GLXEXT_PROTOTYPES
6 #include <msp/strings/format.h>
7 #include <msp/strings/utils.h>
23 Version::Version(unsigned short a, unsigned short i)
29 Version::Version(const string &s)
31 vector<string> parts = split(s, '.');
32 major = lexical_cast<unsigned>(parts[0]);
33 minor = lexical_cast<unsigned>(parts[1]);
36 bool Version::operator>=(const Version &other) const
38 return major>other.major || (major==other.major && minor>=other.minor);
42 Extension::Extension(const char *n, InitFunc f):
49 Extension::operator bool() const
53 support = init_func();
57 return support>UNSUPPORTED;
61 Require::Require(const Extension &ext)
64 throw unsupported_extension(ext.get_name());
68 bool is_supported(const string &ext)
70 static set<string> extensions;
71 static bool init_done = false;
75 if(const char *gl_ext = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
77 vector<string> exts = split(gl_ext);
78 extensions.insert(exts.begin(), exts.end());
81 string renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
82 if(renderer.find("Radeon")!=string::npos)
83 /* Radeon doesn't process NV_primitive_restart correctly and treats
84 the restart index as a normal element if the indices are stored in a
86 extensions.erase("GL_NV_primitive_restart");
91 return extensions.count(ext);
94 inline Version _get_gl_version()
96 string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
97 return Version(gl_ver.substr(0, gl_ver.find(' ')));
100 const Version &get_gl_version()
102 static Version version = _get_gl_version();
106 inline Version _get_glsl_version()
108 string glsl_ver = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
109 return Version(glsl_ver.substr(0, glsl_ver.find(' ')));
112 const Version &get_glsl_version()
114 static Version version = _get_glsl_version();
118 bool is_version_at_least(unsigned a, unsigned b)
120 return get_gl_version()>=Version(a, b);
123 ExtFunc *get_proc_address(const string &name)
126 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));
127 #elif defined(__APPLE__)
129 return 0; // Not supported
131 return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));