2003-07-06 15:01:13 +00:00
|
|
|
#include <GL/glew.h>
|
2012-05-04 19:15:10 +00:00
|
|
|
|
2014-06-24 15:03:28 +00:00
|
|
|
#if defined(GLEW_OSMESA)
|
|
|
|
# define GLAPI extern
|
|
|
|
# include <GL/osmesa.h>
|
|
|
|
#elif defined(_WIN32)
|
2003-10-27 02:34:05 +00:00
|
|
|
# include <GL/wglew.h>
|
2013-12-09 21:20:56 +00:00
|
|
|
#elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))
|
2003-10-27 02:34:05 +00:00
|
|
|
# include <GL/glxew.h>
|
2003-09-19 23:39:22 +00:00
|
|
|
#endif
|
2003-07-06 15:01:13 +00:00
|
|
|
|
2014-07-14 07:02:27 +00:00
|
|
|
#include <stddef.h> /* For size_t */
|
2015-06-18 10:53:45 +00:00
|
|
|
#include <stdlib.h> /* For malloc, free */
|
|
|
|
#include <string.h> /* For memset */
|
2014-07-14 07:02:27 +00:00
|
|
|
|
2015-02-04 14:27:59 +00:00
|
|
|
extern int memcmp(const void *, const void *, size_t);
|
|
|
|
|
2014-01-14 20:16:04 +00:00
|
|
|
#if defined(GLEW_REGAL)
|
2014-01-14 21:33:06 +00:00
|
|
|
|
|
|
|
/* In GLEW_REGAL mode we call direcly into the linked
|
|
|
|
libRegal.so glGetProcAddressREGAL for looking up
|
|
|
|
the GL function pointers. */
|
|
|
|
|
2014-01-22 18:23:05 +00:00
|
|
|
# undef glGetProcAddressREGAL
|
|
|
|
# ifdef WIN32
|
|
|
|
extern void * __stdcall glGetProcAddressREGAL(const GLchar *name);
|
|
|
|
static void * (__stdcall * regalGetProcAddress) (const GLchar *) = glGetProcAddressREGAL;
|
|
|
|
# else
|
|
|
|
extern void * glGetProcAddressREGAL(const GLchar *name);
|
|
|
|
static void * (*regalGetProcAddress) (const GLchar *) = glGetProcAddressREGAL;
|
|
|
|
# endif
|
|
|
|
# define glGetProcAddressREGAL GLEW_GET_FUN(__glewGetProcAddressREGAL)
|
2014-01-14 21:33:06 +00:00
|
|
|
|
2014-01-14 20:16:04 +00:00
|
|
|
#elif defined(__sgi) || defined (__sun) || defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
|
2010-12-27 17:31:48 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
void* dlGetProcAddress (const GLubyte* name)
|
|
|
|
{
|
|
|
|
static void* h = NULL;
|
|
|
|
static void* gpa;
|
|
|
|
|
|
|
|
if (h == NULL)
|
|
|
|
{
|
|
|
|
if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
|
|
|
|
gpa = dlsym(h, "glXGetProcAddress");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpa != NULL)
|
|
|
|
return ((void*(*)(const GLubyte*))gpa)(name);
|
|
|
|
else
|
|
|
|
return dlsym(h, (const char*)name);
|
|
|
|
}
|
|
|
|
#endif /* __sgi || __sun || GLEW_APPLE_GLX */
|
|
|
|
|
2003-10-27 02:34:05 +00:00
|
|
|
#if defined(__APPLE__)
|
2003-09-19 23:39:22 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-03-23 18:43:36 +00:00
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
|
|
|
|
#ifdef MAC_OS_X_VERSION_10_3
|
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
void* NSGLGetProcAddress (const GLubyte *name)
|
|
|
|
{
|
|
|
|
static void* image = NULL;
|
2012-05-04 15:53:27 +00:00
|
|
|
void* addr;
|
2009-03-23 18:43:36 +00:00
|
|
|
if (NULL == image)
|
|
|
|
{
|
|
|
|
image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
|
|
|
}
|
2010-12-27 17:31:48 +00:00
|
|
|
if( !image ) return NULL;
|
2012-05-04 15:53:27 +00:00
|
|
|
addr = dlsym(image, (const char*)name);
|
2010-12-27 17:31:48 +00:00
|
|
|
if( addr ) return addr;
|
|
|
|
#ifdef GLEW_APPLE_GLX
|
|
|
|
return dlGetProcAddress( name ); // try next for glx symbols
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2009-03-23 18:43:36 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
#include <mach-o/dyld.h>
|
2003-09-19 23:39:22 +00:00
|
|
|
|
2004-12-29 05:43:35 +00:00
|
|
|
void* NSGLGetProcAddress (const GLubyte *name)
|
2003-09-19 23:39:22 +00:00
|
|
|
{
|
2006-03-08 03:40:18 +00:00
|
|
|
static const struct mach_header* image = NULL;
|
2003-09-19 23:39:22 +00:00
|
|
|
NSSymbol symbol;
|
2004-12-29 05:43:35 +00:00
|
|
|
char* symbolName;
|
2006-03-08 03:25:22 +00:00
|
|
|
if (NULL == image)
|
|
|
|
{
|
|
|
|
image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
|
|
|
}
|
2003-09-26 13:49:28 +00:00
|
|
|
/* prepend a '_' for the Unix C symbol mangling convention */
|
2004-12-29 05:43:35 +00:00
|
|
|
symbolName = malloc(strlen((const char*)name) + 2);
|
|
|
|
strcpy(symbolName+1, (const char*)name);
|
2003-09-19 23:39:22 +00:00
|
|
|
symbolName[0] = '_';
|
|
|
|
symbol = NULL;
|
2006-03-08 03:25:22 +00:00
|
|
|
/* if (NSIsSymbolNameDefined(symbolName))
|
|
|
|
symbol = NSLookupAndBindSymbol(symbolName); */
|
|
|
|
symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
|
2003-09-19 23:39:22 +00:00
|
|
|
free(symbolName);
|
2010-12-27 17:31:48 +00:00
|
|
|
if( symbol ) return NSAddressOfSymbol(symbol);
|
|
|
|
#ifdef GLEW_APPLE_GLX
|
|
|
|
return dlGetProcAddress( name ); // try next for glx symbols
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2003-09-19 23:39:22 +00:00
|
|
|
}
|
2009-03-23 18:43:36 +00:00
|
|
|
#endif /* MAC_OS_X_VERSION_10_3 */
|
2003-09-19 23:39:22 +00:00
|
|
|
#endif /* __APPLE__ */
|
2003-07-06 16:41:08 +00:00
|
|
|
|
2005-01-03 07:05:38 +00:00
|
|
|
/*
|
|
|
|
* Define glewGetProcAddress.
|
|
|
|
*/
|
2015-10-08 12:03:16 +00:00
|
|
|
#if defined(GLEW_REGAL)
|
|
|
|
# define glewGetProcAddress(name) regalGetProcAddress((const GLchar *)name)
|
|
|
|
#elif defined(GLEW_OSMESA)
|
2014-06-24 15:03:28 +00:00
|
|
|
# define glewGetProcAddress(name) OSMesaGetProcAddress((const char *)name)
|
2014-01-14 20:16:04 +00:00
|
|
|
#elif defined(_WIN32)
|
2005-01-03 07:05:38 +00:00
|
|
|
# define glewGetProcAddress(name) wglGetProcAddress((LPCSTR)name)
|
2012-05-04 19:15:10 +00:00
|
|
|
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
|
|
|
|
# define glewGetProcAddress(name) NSGLGetProcAddress(name)
|
2013-12-09 21:20:56 +00:00
|
|
|
#elif defined(__sgi) || defined(__sun) || defined(__HAIKU__)
|
2012-05-04 19:15:10 +00:00
|
|
|
# define glewGetProcAddress(name) dlGetProcAddress(name)
|
|
|
|
#elif defined(__ANDROID__)
|
|
|
|
# define glewGetProcAddress(name) NULL /* TODO */
|
2012-08-16 19:01:11 +00:00
|
|
|
#elif defined(__native_client__)
|
|
|
|
# define glewGetProcAddress(name) NULL /* TODO */
|
2012-05-04 19:15:10 +00:00
|
|
|
#else /* __linux */
|
|
|
|
# define glewGetProcAddress(name) (*glXGetProcAddressARB)(name)
|
2005-01-03 07:05:38 +00:00
|
|
|
#endif
|
|
|
|
|
2007-03-19 13:33:36 +00:00
|
|
|
/*
|
2014-07-14 07:53:21 +00:00
|
|
|
* Redefine GLEW_GET_VAR etc without const cast
|
2007-03-19 13:33:36 +00:00
|
|
|
*/
|
2014-07-14 07:53:21 +00:00
|
|
|
|
|
|
|
#undef GLEW_GET_VAR
|
|
|
|
# define GLEW_GET_VAR(x) (x)
|
|
|
|
|
|
|
|
#ifdef WGLEW_GET_VAR
|
|
|
|
# undef WGLEW_GET_VAR
|
2015-11-19 11:12:48 +00:00
|
|
|
# define WGLEW_GET_VAR(x) (x)
|
2014-07-14 07:53:21 +00:00
|
|
|
#endif /* WGLEW_GET_VAR */
|
|
|
|
|
|
|
|
#ifdef GLXEW_GET_VAR
|
|
|
|
# undef GLXEW_GET_VAR
|
2015-11-19 11:12:48 +00:00
|
|
|
# define GLXEW_GET_VAR(x) (x)
|
2014-07-14 07:53:21 +00:00
|
|
|
#endif /* GLXEW_GET_VAR */
|
2007-03-19 13:33:36 +00:00
|
|
|
|
2004-12-29 05:43:35 +00:00
|
|
|
/*
|
|
|
|
* GLEW, just like OpenGL or GLU, does not rely on the standard C library.
|
|
|
|
* These functions implement the functionality required in this file.
|
|
|
|
*/
|
2015-02-21 13:44:08 +00:00
|
|
|
|
2005-01-04 15:02:30 +00:00
|
|
|
static GLuint _glewStrLen (const GLubyte* s)
|
2004-12-29 05:43:35 +00:00
|
|
|
{
|
|
|
|
GLuint i=0;
|
2005-04-05 03:49:48 +00:00
|
|
|
if (s == NULL) return 0;
|
|
|
|
while (s[i] != '\0') i++;
|
2004-12-29 05:43:35 +00:00
|
|
|
return i;
|
|
|
|
}
|
2003-07-06 15:01:13 +00:00
|
|
|
|
2005-01-04 15:02:30 +00:00
|
|
|
static GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
|
2004-12-29 05:43:35 +00:00
|
|
|
{
|
|
|
|
GLuint i=0;
|
2005-04-05 03:49:48 +00:00
|
|
|
if (s == NULL) return 0;
|
|
|
|
while (s[i] != '\0' && s[i] != c) i++;
|
2008-10-27 01:00:33 +00:00
|
|
|
return (s[i] == '\0' || s[i] == c) ? i : 0;
|
2004-12-29 05:43:35 +00:00
|
|
|
}
|
2004-02-19 04:37:07 +00:00
|
|
|
|
2015-02-21 13:44:08 +00:00
|
|
|
static GLubyte *_glewStrDup (const GLubyte *s)
|
|
|
|
{
|
2015-02-27 11:06:55 +00:00
|
|
|
int n = _glewStrLen(s);
|
|
|
|
GLubyte *dup = malloc(n+1);
|
2015-02-21 13:44:08 +00:00
|
|
|
if (dup)
|
|
|
|
{
|
2015-02-27 11:06:55 +00:00
|
|
|
GLubyte *i = dup;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
*i = *s;
|
|
|
|
if (*i) { ++i; ++s; } else break;
|
|
|
|
}
|
2015-02-21 13:44:08 +00:00
|
|
|
}
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
2015-02-27 11:06:55 +00:00
|
|
|
#if !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
2005-01-04 15:02:30 +00:00
|
|
|
static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
|
2004-12-29 05:43:35 +00:00
|
|
|
{
|
|
|
|
GLuint i=0;
|
2005-04-05 03:49:48 +00:00
|
|
|
if(a == NULL || b == NULL)
|
|
|
|
return (a == NULL && b == NULL && n == 0) ? GL_TRUE : GL_FALSE;
|
|
|
|
while (i < n && a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) i++;
|
2004-12-29 05:43:35 +00:00
|
|
|
return i == n ? GL_TRUE : GL_FALSE;
|
|
|
|
}
|
2015-02-27 11:06:55 +00:00
|
|
|
#endif
|
2004-02-19 04:37:07 +00:00
|
|
|
|
2014-10-14 09:24:49 +00:00
|
|
|
static GLboolean _glewStrSame1 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
2005-01-04 05:31:44 +00:00
|
|
|
{
|
|
|
|
while (*na > 0 && (**a == ' ' || **a == '\n' || **a == '\r' || **a == '\t'))
|
|
|
|
{
|
2005-01-04 15:02:30 +00:00
|
|
|
(*a)++;
|
|
|
|
(*na)--;
|
2005-01-04 05:31:44 +00:00
|
|
|
}
|
|
|
|
if(*na >= nb)
|
|
|
|
{
|
|
|
|
GLuint i=0;
|
2005-01-04 15:02:30 +00:00
|
|
|
while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
|
2010-12-30 19:34:06 +00:00
|
|
|
if(i == nb)
|
|
|
|
{
|
|
|
|
*a = *a + nb;
|
|
|
|
*na = *na - nb;
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
2005-01-04 05:31:44 +00:00
|
|
|
}
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-10-14 09:24:49 +00:00
|
|
|
static GLboolean _glewStrSame2 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
2004-12-29 05:43:35 +00:00
|
|
|
{
|
|
|
|
if(*na >= nb)
|
|
|
|
{
|
|
|
|
GLuint i=0;
|
2005-01-04 15:02:30 +00:00
|
|
|
while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
|
2010-12-30 19:34:06 +00:00
|
|
|
if(i == nb)
|
|
|
|
{
|
|
|
|
*a = *a + nb;
|
|
|
|
*na = *na - nb;
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
2004-12-29 05:43:35 +00:00
|
|
|
}
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
2014-10-14 09:24:49 +00:00
|
|
|
static GLboolean _glewStrSame3 (const GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
2004-12-29 05:43:35 +00:00
|
|
|
{
|
2005-01-04 05:31:44 +00:00
|
|
|
if(*na >= nb)
|
2004-12-29 05:43:35 +00:00
|
|
|
{
|
|
|
|
GLuint i=0;
|
2005-01-04 15:02:30 +00:00
|
|
|
while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
|
|
|
|
if (i == nb && (*na == nb || (*a)[i] == ' ' || (*a)[i] == '\n' || (*a)[i] == '\r' || (*a)[i] == '\t'))
|
2005-01-04 05:31:44 +00:00
|
|
|
{
|
|
|
|
*a = *a + nb;
|
|
|
|
*na = *na - nb;
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
2004-12-29 05:43:35 +00:00
|
|
|
}
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2015-02-21 13:29:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-02-27 11:06:55 +00:00
|
|
|
#if !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
|
2015-02-21 13:29:40 +00:00
|
|
|
static GLboolean _glewSearchExtension (const char* name, const GLubyte *start, const GLubyte *end)
|
|
|
|
{
|
|
|
|
const GLubyte* p;
|
|
|
|
GLuint len = _glewStrLen((const GLubyte*)name);
|
|
|
|
p = start;
|
|
|
|
while (p < end)
|
|
|
|
{
|
|
|
|
GLuint n = _glewStrCLen(p, ' ');
|
|
|
|
if (len == n && _glewStrSame((const GLubyte*)name, p, n)) return GL_TRUE;
|
|
|
|
p += n+1;
|
|
|
|
}
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
2015-02-27 11:06:55 +00:00
|
|
|
#endif
|