2003-07-06 15:01:13 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2016-02-05 07:53:25 +00:00
|
|
|
static int _glewExtensionCompare(const char *s1, const char *s2)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
2016-01-07 11:58:20 +00:00
|
|
|
/* http://www.chanduthedev.com/2012/07/strcmp-implementation-in-c.html */
|
|
|
|
while (*s1 || *s2)
|
|
|
|
{
|
|
|
|
if (*s1 > *s2)
|
|
|
|
return 1;
|
|
|
|
if (*s1 < *s2)
|
|
|
|
return -1;
|
|
|
|
s1++;
|
|
|
|
s2++;
|
|
|
|
}
|
|
|
|
return 0;
|
2015-02-21 04:09:39 +00:00
|
|
|
}
|
|
|
|
|
2016-02-05 07:53:25 +00:00
|
|
|
static ptrdiff_t _glewBsearchExtension(const char* name)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
2016-02-05 07:53:25 +00:00
|
|
|
ptrdiff_t lo = 0, hi = sizeof(_glewExtensionLookup) / sizeof(char*) - 2;
|
2015-02-21 04:09:39 +00:00
|
|
|
|
2016-02-05 07:53:25 +00:00
|
|
|
while (lo <= hi)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
2016-02-05 07:53:25 +00:00
|
|
|
ptrdiff_t mid = (lo + hi) / 2;
|
|
|
|
const int cmp = _glewExtensionCompare(name, _glewExtensionLookup[mid]);
|
|
|
|
if (cmp < 0) hi = mid - 1;
|
|
|
|
else if (cmp > 0) lo = mid + 1;
|
|
|
|
else return mid;
|
2015-02-21 04:09:39 +00:00
|
|
|
}
|
2016-02-05 07:53:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-02-21 04:09:39 +00:00
|
|
|
|
2016-02-05 07:53:25 +00:00
|
|
|
static GLboolean *_glewGetExtensionString(const char *name)
|
|
|
|
{
|
|
|
|
ptrdiff_t n = _glewBsearchExtension(name);
|
|
|
|
if (n >= 0) return &_glewExtensionString[n];
|
2015-02-21 04:09:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GLboolean *_glewGetExtensionEnable(const char *name)
|
|
|
|
{
|
2016-02-05 07:53:25 +00:00
|
|
|
ptrdiff_t n = _glewBsearchExtension(name);
|
|
|
|
if (n >= 0) return _glewExtensionEnabled[n];
|
2015-02-21 04:09:39 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-07 11:28:01 +00:00
|
|
|
static const char *_glewNextSpace(const char *i)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
2016-01-07 11:28:01 +00:00
|
|
|
const char *j = i;
|
2015-02-21 04:09:39 +00:00
|
|
|
if (j)
|
|
|
|
while (*j!=' ' && *j) ++j;
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
2016-01-07 11:28:01 +00:00
|
|
|
static const char *_glewNextNonSpace(const char *i)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
2016-01-07 11:28:01 +00:00
|
|
|
const char *j = i;
|
2015-02-21 04:09:39 +00:00
|
|
|
if (j)
|
|
|
|
while (*j==' ') ++j;
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
2012-05-07 14:05:12 +00:00
|
|
|
GLboolean GLEWAPIENTRY glewGetExtension (const char* name)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
|
|
|
GLboolean *enable = _glewGetExtensionString(name);
|
|
|
|
if (enable)
|
|
|
|
return *enable;
|
|
|
|
return GL_FALSE;
|
2003-07-06 15:01:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2016-01-27 12:15:49 +00:00
|
|
|
typedef const GLubyte* (GLAPIENTRY * PFNGLGETSTRINGPROC) (GLenum name);
|
|
|
|
typedef void (GLAPIENTRY * PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
|
|
|
|
|
2015-11-19 11:12:48 +00:00
|
|
|
static GLenum GLEWAPIENTRY glewContextInit ()
|
2003-07-06 15:01:13 +00:00
|
|
|
{
|
2016-01-27 12:15:49 +00:00
|
|
|
PFNGLGETSTRINGPROC getString;
|
2003-09-15 17:01:44 +00:00
|
|
|
const GLubyte* s;
|
2009-03-31 21:16:33 +00:00
|
|
|
GLuint dot;
|
|
|
|
GLint major, minor;
|
2016-02-06 18:30:15 +00:00
|
|
|
size_t n;
|
2015-02-21 04:09:39 +00:00
|
|
|
|
2016-04-02 03:19:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
getString = glGetString;
|
|
|
|
#else
|
|
|
|
getString = (PFNGLGETSTRINGPROC) glewGetProcAddress((const GLubyte*)"glGetString");
|
2016-01-27 12:15:49 +00:00
|
|
|
if (!getString)
|
|
|
|
return GLEW_ERROR_NO_GL_VERSION;
|
2016-04-02 03:19:57 +00:00
|
|
|
#endif
|
2016-01-27 12:15:49 +00:00
|
|
|
|
2016-04-02 03:19:57 +00:00
|
|
|
/* query opengl version */
|
2016-01-27 12:15:49 +00:00
|
|
|
s = getString(GL_VERSION);
|
2005-04-05 03:49:48 +00:00
|
|
|
dot = _glewStrCLen(s, '.');
|
2009-03-31 21:16:33 +00:00
|
|
|
if (dot == 0)
|
2005-04-05 03:49:48 +00:00
|
|
|
return GLEW_ERROR_NO_GL_VERSION;
|
2016-01-07 11:28:01 +00:00
|
|
|
|
2009-03-31 21:16:33 +00:00
|
|
|
major = s[dot-1]-'0';
|
|
|
|
minor = s[dot+1]-'0';
|
|
|
|
|
|
|
|
if (minor < 0 || minor > 9)
|
|
|
|
minor = 0;
|
|
|
|
if (major<0 || major>9)
|
|
|
|
return GLEW_ERROR_NO_GL_VERSION;
|
2016-01-07 11:28:01 +00:00
|
|
|
|
2009-03-31 21:16:33 +00:00
|
|
|
if (major == 1 && minor == 0)
|
2003-07-06 15:01:13 +00:00
|
|
|
{
|
2009-03-31 21:16:33 +00:00
|
|
|
return GLEW_ERROR_GL_VERSION_10_ONLY;
|
2003-07-06 15:01:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-30 10:49:24 +00:00
|
|
|
GLEW_VERSION_4_6 = ( major > 4 ) || ( major == 4 && minor >= 6 ) ? GL_TRUE : GL_FALSE;
|
2017-12-01 23:16:46 +00:00
|
|
|
GLEW_VERSION_4_5 = GLEW_VERSION_4_6 == GL_TRUE || ( major == 4 && minor >= 5 ) ? GL_TRUE : GL_FALSE;
|
2014-08-11 14:06:56 +00:00
|
|
|
GLEW_VERSION_4_4 = GLEW_VERSION_4_5 == GL_TRUE || ( major == 4 && minor >= 4 ) ? GL_TRUE : GL_FALSE;
|
2014-07-14 07:53:21 +00:00
|
|
|
GLEW_VERSION_4_3 = GLEW_VERSION_4_4 == GL_TRUE || ( major == 4 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_4_2 = GLEW_VERSION_4_3 == GL_TRUE || ( major == 4 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_4_1 = GLEW_VERSION_4_2 == GL_TRUE || ( major == 4 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_4_0 = GLEW_VERSION_4_1 == GL_TRUE || ( major == 4 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_3_3 = GLEW_VERSION_4_0 == GL_TRUE || ( major == 3 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_3_2 = GLEW_VERSION_3_3 == GL_TRUE || ( major == 3 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_3_1 = GLEW_VERSION_3_2 == GL_TRUE || ( major == 3 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_3_0 = GLEW_VERSION_3_1 == GL_TRUE || ( major == 3 ) ? GL_TRUE : GL_FALSE;
|
2016-01-07 11:28:01 +00:00
|
|
|
GLEW_VERSION_2_1 = GLEW_VERSION_3_0 == GL_TRUE || ( major == 2 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
2014-07-14 07:53:21 +00:00
|
|
|
GLEW_VERSION_2_0 = GLEW_VERSION_2_1 == GL_TRUE || ( major == 2 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_1_5 = GLEW_VERSION_2_0 == GL_TRUE || ( major == 1 && minor >= 5 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_1_4 = GLEW_VERSION_1_5 == GL_TRUE || ( major == 1 && minor >= 4 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_1_3 = GLEW_VERSION_1_4 == GL_TRUE || ( major == 1 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
|
2016-01-07 11:28:01 +00:00
|
|
|
GLEW_VERSION_1_2_1 = GLEW_VERSION_1_3 == GL_TRUE ? GL_TRUE : GL_FALSE;
|
2014-07-14 07:53:21 +00:00
|
|
|
GLEW_VERSION_1_2 = GLEW_VERSION_1_2_1 == GL_TRUE || ( major == 1 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
|
|
|
GLEW_VERSION_1_1 = GLEW_VERSION_1_2 == GL_TRUE || ( major == 1 && minor >= 1 ) ? GL_TRUE : GL_FALSE;
|
2003-07-06 15:01:13 +00:00
|
|
|
}
|
2011-03-30 16:38:25 +00:00
|
|
|
|
2016-02-06 18:10:02 +00:00
|
|
|
for (n = 0; n < sizeof(_glewExtensionString) / sizeof(_glewExtensionString[0]); ++n)
|
|
|
|
_glewExtensionString[n] = GL_FALSE;
|
2015-02-21 04:09:39 +00:00
|
|
|
|
|
|
|
if (GLEW_VERSION_3_0)
|
|
|
|
{
|
2015-02-21 09:42:42 +00:00
|
|
|
GLint n = 0;
|
|
|
|
GLint i;
|
2016-01-27 12:15:49 +00:00
|
|
|
PFNGLGETINTEGERVPROC getIntegerv;
|
2015-02-21 09:42:42 +00:00
|
|
|
PFNGLGETSTRINGIPROC getStringi;
|
|
|
|
const char *ext;
|
2015-02-21 13:29:40 +00:00
|
|
|
GLboolean *enable;
|
2015-02-21 09:42:42 +00:00
|
|
|
|
2016-04-02 03:19:57 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
getIntegerv = glGetIntegerv;
|
|
|
|
#else
|
2016-01-27 12:15:49 +00:00
|
|
|
getIntegerv = (PFNGLGETINTEGERVPROC) glewGetProcAddress((const GLubyte*)"glGetIntegerv");
|
2016-04-02 03:19:57 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-27 12:15:49 +00:00
|
|
|
if (getIntegerv)
|
|
|
|
getIntegerv(GL_NUM_EXTENSIONS, &n);
|
2015-02-21 09:42:42 +00:00
|
|
|
|
|
|
|
/* glGetStringi is OpenGL 3.0 */
|
|
|
|
getStringi = (PFNGLGETSTRINGIPROC) glewGetProcAddress((const GLubyte*)"glGetStringi");
|
2015-02-21 14:37:29 +00:00
|
|
|
if (getStringi)
|
2015-02-21 09:42:42 +00:00
|
|
|
for (i = 0; i<n; ++i)
|
|
|
|
{
|
|
|
|
ext = (const char *) getStringi(GL_EXTENSIONS, i);
|
|
|
|
|
|
|
|
/* Based on extension string(s), glewGetExtension purposes */
|
|
|
|
enable = _glewGetExtensionString(ext);
|
|
|
|
if (enable)
|
|
|
|
*enable = GL_TRUE;
|
|
|
|
|
|
|
|
/* Based on extension string(s), experimental mode, glewIsSupported purposes */
|
|
|
|
enable = _glewGetExtensionEnable(ext);
|
|
|
|
if (enable)
|
|
|
|
*enable = GL_TRUE;
|
|
|
|
}
|
2015-02-21 04:09:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-01-07 11:28:01 +00:00
|
|
|
const char *extensions;
|
|
|
|
const char *end;
|
|
|
|
const char *i;
|
|
|
|
const char *j;
|
|
|
|
char ext[128];
|
2015-02-21 13:29:40 +00:00
|
|
|
GLboolean *enable;
|
|
|
|
|
2016-01-27 12:15:49 +00:00
|
|
|
extensions = (const char *) getString(GL_EXTENSIONS);
|
2015-02-21 13:29:40 +00:00
|
|
|
|
2016-01-07 11:28:01 +00:00
|
|
|
if (extensions)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
2016-01-07 11:28:01 +00:00
|
|
|
end = extensions + _glewStrLen((const GLubyte *) extensions);
|
|
|
|
for (i=extensions; i<end; i = j + 1)
|
2015-02-21 04:09:39 +00:00
|
|
|
{
|
|
|
|
i = _glewNextNonSpace(i);
|
|
|
|
j = _glewNextSpace(i);
|
2016-01-07 11:28:01 +00:00
|
|
|
|
|
|
|
/* Copy extension into NUL terminated string */
|
|
|
|
if (j-i >= (ptrdiff_t) sizeof(ext))
|
|
|
|
continue;
|
|
|
|
_glewStrCopy(ext, i, ' ');
|
2015-02-21 04:09:39 +00:00
|
|
|
|
|
|
|
/* Based on extension string(s), glewGetExtension purposes */
|
2016-01-07 11:28:01 +00:00
|
|
|
enable = _glewGetExtensionString(ext);
|
2015-02-21 04:09:39 +00:00
|
|
|
if (enable)
|
|
|
|
*enable = GL_TRUE;
|
2013-07-21 03:06:29 +00:00
|
|
|
|
2015-02-21 04:09:39 +00:00
|
|
|
/* Based on extension string(s), experimental mode, glewIsSupported purposes */
|
2016-01-07 11:28:01 +00:00
|
|
|
enable = _glewGetExtensionEnable(ext);
|
2015-02-21 04:09:39 +00:00
|
|
|
if (enable)
|
|
|
|
*enable = GL_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|