3 #if defined(__ANDROID__)
5 #elif !defined(WIN32) && !defined(__APPLE__)
6 #define GLX_GLXEXT_PROTOTYPES
9 #include <msp/strings/format.h>
10 #include <msp/strings/utils.h>
12 #include "extension.h"
26 Version::Version(unsigned short a, unsigned short i)
32 Version::Version(const string &s)
34 vector<string> parts = split(s, '.');
35 major = lexical_cast<unsigned>(parts[0]);
36 minor = lexical_cast<unsigned>(parts[1]);
39 bool Version::operator>=(const Version &other) const
41 return major>other.major || (major==other.major && minor>=other.minor);
45 Extension::Extension(const char *n, InitFunc f):
52 Extension::operator bool() const
56 support = init_func();
60 return support>UNSUPPORTED;
64 Require::Require(const Extension &ext)
67 throw unsupported_extension(ext.get_name());
71 bool is_supported(const string &ext)
73 static set<string> extensions;
74 static bool init_done = false;
78 if(const char *gl_ext = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)))
80 vector<string> exts = split(gl_ext);
81 extensions.insert(exts.begin(), exts.end());
84 string renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
85 if(renderer.find("Radeon")!=string::npos)
87 /* Radeon doesn't process NV_primitive_restart correctly and treats
88 the restart index as a normal element if the indices are stored in a
90 extensions.erase("GL_NV_primitive_restart");
92 /* AMD's uniform buffer objects only work with the core version of
94 if(!(get_gl_version()>=Version(2, 0)))
95 extensions.erase("GL_ARB_uniform_buffer_object");
98 if(const char *disable_ptr = getenv("MSPGL_DISABLE_EXTENSIONS"))
100 vector<string> disable = split(disable_ptr);
101 for(vector<string>::const_iterator i=disable.begin(); i!=disable.end(); ++i)
102 extensions.erase(*i);
108 return extensions.count(ext);
113 #ifdef GL_ES_VERSION_2_0
120 inline Version _get_gl_version()
122 string gl_ver = reinterpret_cast<const char *>(glGetString(GL_VERSION));
123 if(!gl_ver.compare(0, 10, "OpenGL ES "))
126 Version ver(gl_ver.substr(0, gl_ver.find(' ')));
128 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
130 Version force_ver(force_ver_ptr);
131 if(!(force_ver>=ver))
138 const Version &get_gl_version()
140 static Version version = _get_gl_version();
144 inline Version _get_glsl_version()
146 string glsl_ver = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
147 if(!glsl_ver.compare(0, 18, "OpenGL ES GLSL ES "))
148 glsl_ver.erase(0, 18);
150 Version ver(glsl_ver.substr(0, glsl_ver.find(' ')));
152 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_GLSL_VERSION"))
154 Version force_ver(force_ver_ptr);
155 if(!(force_ver>=ver))
162 const Version &get_glsl_version()
164 static Version version = _get_glsl_version();
168 bool is_version_at_least(unsigned a, unsigned b)
170 return get_gl_version()>=Version(a, b);
173 ExtFunc *get_proc_address(const string &name)
176 return reinterpret_cast<ExtFunc *>(wglGetProcAddress(name.c_str()));
177 #elif defined(__APPLE__)
179 return 0; // Not supported
180 #elif defined(__ANDROID__)
181 return eglGetProcAddress(name.c_str());
183 return glXGetProcAddressARB(reinterpret_cast<const unsigned char *>(name.c_str()));