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)
84 /* Radeon doesn't process NV_primitive_restart correctly and treats
85 the restart index as a normal element if the indices are stored in a
87 extensions.erase("GL_NV_primitive_restart");
89 /* AMD's uniform buffer objects only work with the core version of
91 if(!(get_gl_version()>=Version(2, 0)))
92 extensions.erase("GL_ARB_uniform_buffer_object");
95 if(const char *disable_ptr = getenv("MSPGL_DISABLE_EXTENSIONS"))
97 vector<string> disable = split(disable_ptr);
98 for(vector<string>::const_iterator i=disable.begin(); i!=disable.end(); ++i)
105 return extensions.count(ext);
108 inline Version _get_gl_version()
110 string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
111 Version ver(gl_ver.substr(0, gl_ver.find(' ')));
113 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
115 Version force_ver(force_ver_ptr);
116 if(!(force_ver>=ver))
123 const Version &get_gl_version()
125 static Version version = _get_gl_version();
129 inline Version _get_glsl_version()
131 string glsl_ver = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
132 Version ver(glsl_ver.substr(0, glsl_ver.find(' ')));
134 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_GLSL_VERSION"))
136 Version force_ver(force_ver_ptr);
137 if(!(force_ver>=ver))
144 const Version &get_glsl_version()
146 static Version version = _get_glsl_version();
150 bool is_version_at_least(unsigned a, unsigned b)
152 return get_gl_version()>=Version(a, b);
155 ExtFunc *get_proc_address(const string &name)
158 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));
159 #elif defined(__APPLE__)
161 return 0; // Not supported
163 return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));