|
kusano |
7d535a |
#include <gl glew.h=""></gl>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if defined(_WIN32)
|
|
kusano |
7d535a |
# include <gl wglew.h=""></gl>
|
|
kusano |
7d535a |
#elif !defined(__ANDROID__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))
|
|
kusano |
7d535a |
# include <gl glxew.h=""></gl>
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Define glewGetContext and related helper macros.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#ifdef GLEW_MX
|
|
kusano |
7d535a |
# define glewGetContext() ctx
|
|
kusano |
7d535a |
# ifdef _WIN32
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_DEF_INIT GLEWContext* ctx
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_VAR_INIT ctx
|
|
kusano |
7d535a |
# define wglewGetContext() ctx
|
|
kusano |
7d535a |
# define WGLEW_CONTEXT_ARG_DEF_INIT WGLEWContext* ctx
|
|
kusano |
7d535a |
# define WGLEW_CONTEXT_ARG_DEF_LIST WGLEWContext* ctx
|
|
kusano |
7d535a |
# else /* _WIN32 */
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_DEF_INIT void
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_VAR_INIT
|
|
kusano |
7d535a |
# define glxewGetContext() ctx
|
|
kusano |
7d535a |
# define GLXEW_CONTEXT_ARG_DEF_INIT void
|
|
kusano |
7d535a |
# define GLXEW_CONTEXT_ARG_DEF_LIST GLXEWContext* ctx
|
|
kusano |
7d535a |
# endif /* _WIN32 */
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_DEF_LIST GLEWContext* ctx
|
|
kusano |
7d535a |
#else /* GLEW_MX */
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_DEF_INIT void
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_VAR_INIT
|
|
kusano |
7d535a |
# define GLEW_CONTEXT_ARG_DEF_LIST void
|
|
kusano |
7d535a |
# define WGLEW_CONTEXT_ARG_DEF_INIT void
|
|
kusano |
7d535a |
# define WGLEW_CONTEXT_ARG_DEF_LIST void
|
|
kusano |
7d535a |
# define GLXEW_CONTEXT_ARG_DEF_INIT void
|
|
kusano |
7d535a |
# define GLXEW_CONTEXT_ARG_DEF_LIST void
|
|
kusano |
7d535a |
#endif /* GLEW_MX */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if defined(__sgi) || defined (__sun) || defined(GLEW_APPLE_GLX)
|
|
kusano |
7d535a |
#include <dlfcn.h></dlfcn.h>
|
|
kusano |
7d535a |
#include <stdio.h></stdio.h>
|
|
kusano |
7d535a |
#include <stdlib.h></stdlib.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void* dlGetProcAddress (const GLubyte* name)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
static void* h = NULL;
|
|
kusano |
7d535a |
static void* gpa;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (h == NULL)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
|
|
kusano |
7d535a |
gpa = dlsym(h, "glXGetProcAddress");
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (gpa != NULL)
|
|
kusano |
7d535a |
return ((void*(*)(const GLubyte*))gpa)(name);
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
return dlsym(h, (const char*)name);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
#endif /* __sgi || __sun || GLEW_APPLE_GLX */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#if defined(__APPLE__)
|
|
kusano |
7d535a |
#include <stdlib.h></stdlib.h>
|
|
kusano |
7d535a |
#include <string.h></string.h>
|
|
kusano |
7d535a |
#include <availabilitymacros.h></availabilitymacros.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef MAC_OS_X_VERSION_10_3
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include <dlfcn.h></dlfcn.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void* NSGLGetProcAddress (const GLubyte *name)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
static void* image = NULL;
|
|
kusano |
7d535a |
void* addr;
|
|
kusano |
7d535a |
if (NULL == image)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
#ifdef GLEW_REGAL
|
|
kusano |
7d535a |
image = dlopen("libRegal.dylib", RTLD_LAZY);
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if( !image ) return NULL;
|
|
kusano |
7d535a |
addr = dlsym(image, (const char*)name);
|
|
kusano |
7d535a |
if( addr ) return addr;
|
|
kusano |
7d535a |
#ifdef GLEW_APPLE_GLX
|
|
kusano |
7d535a |
return dlGetProcAddress( name ); // try next for glx symbols
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
return NULL;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include <mach-o dyld.h=""></mach-o>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void* NSGLGetProcAddress (const GLubyte *name)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
static const struct mach_header* image = NULL;
|
|
kusano |
7d535a |
NSSymbol symbol;
|
|
kusano |
7d535a |
char* symbolName;
|
|
kusano |
7d535a |
if (NULL == image)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
#ifdef GLEW_REGAL
|
|
kusano |
7d535a |
image = NSAddImage("libRegal.dylib", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
/* prepend a '_' for the Unix C symbol mangling convention */
|
|
kusano |
7d535a |
symbolName = malloc(strlen((const char*)name) + 2);
|
|
kusano |
7d535a |
strcpy(symbolName+1, (const char*)name);
|
|
kusano |
7d535a |
symbolName[0] = '_';
|
|
kusano |
7d535a |
symbol = NULL;
|
|
kusano |
7d535a |
/* if (NSIsSymbolNameDefined(symbolName))
|
|
kusano |
7d535a |
symbol = NSLookupAndBindSymbol(symbolName); */
|
|
kusano |
7d535a |
symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
|
|
kusano |
7d535a |
free(symbolName);
|
|
kusano |
7d535a |
if( symbol ) return NSAddressOfSymbol(symbol);
|
|
kusano |
7d535a |
#ifdef GLEW_APPLE_GLX
|
|
kusano |
7d535a |
return dlGetProcAddress( name ); // try next for glx symbols
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
return NULL;
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
#endif /* MAC_OS_X_VERSION_10_3 */
|
|
kusano |
7d535a |
#endif /* __APPLE__ */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Define glewGetProcAddress.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#if defined(_WIN32)
|
|
kusano |
7d535a |
# define glewGetProcAddress(name) wglGetProcAddress((LPCSTR)name)
|
|
kusano |
7d535a |
#elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
|
|
kusano |
7d535a |
# define glewGetProcAddress(name) NSGLGetProcAddress(name)
|
|
kusano |
7d535a |
#elif defined(__sgi) || defined(__sun)
|
|
kusano |
7d535a |
# define glewGetProcAddress(name) dlGetProcAddress(name)
|
|
kusano |
7d535a |
#elif defined(__ANDROID__)
|
|
kusano |
7d535a |
# define glewGetProcAddress(name) NULL /* TODO */
|
|
kusano |
7d535a |
#else /* __linux */
|
|
kusano |
7d535a |
# define glewGetProcAddress(name) (*glXGetProcAddressARB)(name)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Define GLboolean const cast.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
#define CONST_CAST(x) (*(GLboolean*)&x)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* GLEW, just like OpenGL or GLU, does not rely on the standard C library.
|
|
kusano |
7d535a |
* These functions implement the functionality required in this file.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
static GLuint _glewStrLen (const GLubyte* s)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
GLuint i=0;
|
|
kusano |
7d535a |
if (s == NULL) return 0;
|
|
kusano |
7d535a |
while (s[i] != '\0') i++;
|
|
kusano |
7d535a |
return i;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
GLuint i=0;
|
|
kusano |
7d535a |
if (s == NULL) return 0;
|
|
kusano |
7d535a |
while (s[i] != '\0' && s[i] != c) i++;
|
|
kusano |
7d535a |
return (s[i] == '\0' || s[i] == c) ? i : 0;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
GLuint i=0;
|
|
kusano |
7d535a |
if(a == NULL || b == NULL)
|
|
kusano |
7d535a |
return (a == NULL && b == NULL && n == 0) ? GL_TRUE : GL_FALSE;
|
|
kusano |
7d535a |
while (i < n && a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) i++;
|
|
kusano |
7d535a |
return i == n ? GL_TRUE : GL_FALSE;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static GLboolean _glewStrSame1 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
while (*na > 0 && (**a == ' ' || **a == '\n' || **a == '\r' || **a == '\t'))
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
(*a)++;
|
|
kusano |
7d535a |
(*na)--;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if(*na >= nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
GLuint i=0;
|
|
kusano |
7d535a |
while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
|
|
kusano |
7d535a |
if(i == nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
*a = *a + nb;
|
|
kusano |
7d535a |
*na = *na - nb;
|
|
kusano |
7d535a |
return GL_TRUE;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
return GL_FALSE;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static GLboolean _glewStrSame2 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if(*na >= nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
GLuint i=0;
|
|
kusano |
7d535a |
while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
|
|
kusano |
7d535a |
if(i == nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
*a = *a + nb;
|
|
kusano |
7d535a |
*na = *na - nb;
|
|
kusano |
7d535a |
return GL_TRUE;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
return GL_FALSE;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static GLboolean _glewStrSame3 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if(*na >= nb)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
GLuint i=0;
|
|
kusano |
7d535a |
while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
|
|
kusano |
7d535a |
if (i == nb && (*na == nb || (*a)[i] == ' ' || (*a)[i] == '\n' || (*a)[i] == '\r' || (*a)[i] == '\t'))
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
*a = *a + nb;
|
|
kusano |
7d535a |
*na = *na - nb;
|
|
kusano |
7d535a |
return GL_TRUE;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
return GL_FALSE;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Search for name in the extensions string. Use of strstr()
|
|
kusano |
7d535a |
* is not sufficient because extension names can be prefixes of
|
|
kusano |
7d535a |
* other extension names. Could use strtok() but the constant
|
|
kusano |
7d535a |
* string returned by glGetString might be in read-only memory.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
static GLboolean _glewSearchExtension (const char* name, const GLubyte *start, const GLubyte *end)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
const GLubyte* p;
|
|
kusano |
7d535a |
GLuint len = _glewStrLen((const GLubyte*)name);
|
|
kusano |
7d535a |
p = start;
|
|
kusano |
7d535a |
while (p < end)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
GLuint n = _glewStrCLen(p, ' ');
|
|
kusano |
7d535a |
if (len == n && _glewStrSame((const GLubyte*)name, p, n)) return GL_TRUE;
|
|
kusano |
7d535a |
p += n+1;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
return GL_FALSE;
|
|
kusano |
7d535a |
}
|