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");
88 if(const char *disable_ptr = getenv("MSPGL_DISABLE_EXTENSIONS"))
90 vector<string> disable = split(disable_ptr);
91 for(vector<string>::const_iterator i=disable.begin(); i!=disable.end(); ++i)
98 return extensions.count(ext);
101 inline Version _get_gl_version()
103 string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
104 Version ver(gl_ver.substr(0, gl_ver.find(' ')));
106 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
108 Version force_ver(force_ver_ptr);
109 if(!(force_ver>=ver))
116 const Version &get_gl_version()
118 static Version version = _get_gl_version();
122 inline Version _get_glsl_version()
124 string glsl_ver = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
125 Version ver(glsl_ver.substr(0, glsl_ver.find(' ')));
127 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_GLSL_VERSION"))
129 Version force_ver(force_ver_ptr);
130 if(!(force_ver>=ver))
137 const Version &get_glsl_version()
139 static Version version = _get_glsl_version();
143 bool is_version_at_least(unsigned a, unsigned b)
145 return get_gl_version()>=Version(a, b);
148 ExtFunc *get_proc_address(const string &name)
151 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));
152 #elif defined(__APPLE__)
154 return 0; // Not supported
156 return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));