mirror of
https://github.com/nigels-com/glew.git
synced 2024-11-15 02:24:41 +00:00
91 lines
2.1 KiB
C
91 lines
2.1 KiB
C
|
/* ------------------------------------------------------------------------- */
|
||
|
|
||
|
/*
|
||
|
* GLEW, just like OpenGL or GLU, does not rely on the standard C library.
|
||
|
* These functions implement the functionality required in this file.
|
||
|
*/
|
||
|
|
||
|
static int _glewStrLen (const char *s)
|
||
|
{
|
||
|
int i=0;
|
||
|
while (s+i != NULL && s[i] != '\0') i++;
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
static int _glewStrCLen (const char *s, char c)
|
||
|
{
|
||
|
int i=0;
|
||
|
while (s+i != NULL && s[i] != '\0' && s[i] != c) i++;
|
||
|
return i;
|
||
|
}
|
||
|
|
||
|
static int _glewStrSame (const char *a, const char *b, int n)
|
||
|
{
|
||
|
int i=0;
|
||
|
while (i < n && a+i != NULL && b+i != NULL && a[i] == b[i]) i++;
|
||
|
return i == n;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Search for name in the extensions string. Use of strstr()
|
||
|
* is not sufficient because extension names can be prefixes of
|
||
|
* other extension names. Could use strtok() but the constant
|
||
|
* string returned by glGetString might be in read-only memory.
|
||
|
*/
|
||
|
GLboolean glewGetExtension (const char *name)
|
||
|
{
|
||
|
char *p, *end;
|
||
|
int len = _glewStrLen(name);
|
||
|
p = (char*)glGetString(GL_EXTENSIONS);
|
||
|
if (0 == p) return GL_FALSE;
|
||
|
end = p + _glewStrLen(p);
|
||
|
while (p < end)
|
||
|
{
|
||
|
int n = _glewStrCLen(p, ' ');
|
||
|
if (len == n && _glewStrSame(name, p, n)) return GL_TRUE;
|
||
|
p += n+1;
|
||
|
}
|
||
|
return GL_FALSE;
|
||
|
}
|
||
|
|
||
|
/* ------------------------------------------------------------------------- */
|
||
|
|
||
|
static GLuint _glewInit ()
|
||
|
{
|
||
|
char* s;
|
||
|
int i;
|
||
|
/* query opengl version */
|
||
|
s = (char*)glGetString(GL_VERSION);
|
||
|
if (!s) return GLEW_ERROR_NO_GL_VERSION;
|
||
|
i=_glewStrCLen(s, '.')+1;
|
||
|
if (s+i == NULL || s[i] < '1')
|
||
|
{
|
||
|
return GLEW_ERROR_GL_VERSION_10_ONLY;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (s[2] == '4')
|
||
|
{
|
||
|
GLEW_VERSION_1_1 = GL_TRUE;
|
||
|
GLEW_VERSION_1_2 = GL_TRUE;
|
||
|
GLEW_VERSION_1_3 = GL_TRUE;
|
||
|
GLEW_VERSION_1_4 = GL_TRUE;
|
||
|
}
|
||
|
if (s[2] == '3')
|
||
|
{
|
||
|
GLEW_VERSION_1_1 = GL_TRUE;
|
||
|
GLEW_VERSION_1_2 = GL_TRUE;
|
||
|
GLEW_VERSION_1_3 = GL_TRUE;
|
||
|
}
|
||
|
if (s[2] == '2')
|
||
|
{
|
||
|
GLEW_VERSION_1_1 = GL_TRUE;
|
||
|
GLEW_VERSION_1_2 = GL_TRUE;
|
||
|
}
|
||
|
if (s[2] < '2')
|
||
|
{
|
||
|
GLEW_VERSION_1_1 = GL_TRUE;
|
||
|
}
|
||
|
}
|
||
|
/* initialize extensions */
|