]> git.tdb.fi Git - libs/gl.git/blobdiff - source/extension.cpp
Add facilities to disable extensions and force lower versions
[libs/gl.git] / source / extension.cpp
index 56f96d4ecee2136dcde2d42f5fbdfa7bbf8b421b..fdbefb5336407e402ba0985985804ba4d527c241 100644 (file)
@@ -14,6 +14,31 @@ using namespace std;
 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),
@@ -60,34 +85,64 @@ bool is_supported(const string &ext)
                        buffer. */
                        extensions.erase("GL_NV_primitive_restart");
 
+               if(const char *disable_ptr = getenv("MSPGL_DISABLE_EXTENSIONS"))
+               {
+                       vector<string> disable = split(disable_ptr);
+                       for(vector<string>::const_iterator i=disable.begin(); i!=disable.end(); ++i)
+                               extensions.erase(*i);
+               }
+
                init_done = true;
        }
 
        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));
+       Version ver(gl_ver.substr(0, gl_ver.find(' ')));
 
-       if(!init_done)
+       if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
        {
-               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]);
+               Version force_ver(force_ver_ptr);
+               if(!(force_ver>=ver))
+                       ver = force_ver;
+       }
 
-               init_done = true;
+       return ver;
+}
+
+const Version &get_gl_version()
+{
+       static Version version = _get_gl_version();
+       return version;
+}
+
+inline Version _get_glsl_version()
+{
+       string glsl_ver = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
+       Version ver(glsl_ver.substr(0, glsl_ver.find(' ')));
+
+       if(const char *force_ver_ptr = getenv("MSPGL_FORCE_GLSL_VERSION"))
+       {
+               Version force_ver(force_ver_ptr);
+               if(!(force_ver>=ver))
+                       ver = force_ver;
        }
 
+       return ver;
+}
+
+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)