#include <set>
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__APPLE__)
#define GLX_GLXEXT_PROTOTYPES
#include <GL/glx.h>
#endif
namespace Msp {
namespace GL {
+Version::Version()
+{
+ major = 0;
+ minor = 0;
+}
+
+Version::Version(unsigned short a, unsigned short i)
+{
+ major = a;
+ minor = i;
+}
+
+Version::Version(const string &s)
+{
+ vector<string> parts = split(s, '.');
+ major = lexical_cast<unsigned>(parts[0]);
+ minor = lexical_cast<unsigned>(parts[1]);
+}
+
+bool Version::operator>=(const Version &other) const
+{
+ return major>other.major || (major==other.major && minor>=other.minor);
+}
+
+
Extension::Extension(const char *n, InitFunc f):
name(n),
init_func(f),
return extensions.count(ext);
}
-const Version &get_gl_version()
+inline Version _get_gl_version()
{
- static Version version;
- static bool init_done = false;
+ string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
+ return Version(gl_ver.substr(0, gl_ver.find(' ')));
+}
- if(!init_done)
- {
- string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
- vector<string> parts = split(gl_ver.substr(0, gl_ver.find(' ')), '.');
- version.major = lexical_cast<unsigned>(parts[0]);
- version.minor = lexical_cast<unsigned>(parts[1]);
+const Version &get_gl_version()
+{
+ static Version version = _get_gl_version();
+ return version;
+}
- init_done = true;
- }
+inline Version _get_glsl_version()
+{
+ string glsl_ver = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
+ return Version(glsl_ver.substr(0, glsl_ver.find(' ')));
+}
+const Version &get_glsl_version()
+{
+ static Version version = _get_glsl_version();
return version;
}
bool is_version_at_least(unsigned a, unsigned b)
{
- const Version &ver = get_gl_version();
- return (ver.major>a || (ver.major==a && ver.minor>=b));
+ return get_gl_version()>=Version(a, b);
}
ExtFunc *get_proc_address(const string &name)
{
-#ifndef WIN32
- return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));
-#else
+#if defined(WIN32)
return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));
+#elif defined(__APPLE__)
+ (void)name;
+ return 0; // Not supported
+#else
+ return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));
#endif
}