kusano 7d535a
/*
kusano 7d535a
** The OpenGL Extension Wrangler Library
kusano 7d535a
** Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee="" org=""></milan>
kusano 7d535a
** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org=""></mmagallo[]debian>
kusano 7d535a
** Copyright (C) 2002, Lev Povalahev
kusano 7d535a
** All rights reserved.
kusano 7d535a
** 
kusano 7d535a
** Redistribution and use in source and binary forms, with or without 
kusano 7d535a
** modification, are permitted provided that the following conditions are met:
kusano 7d535a
** 
kusano 7d535a
** * Redistributions of source code must retain the above copyright notice, 
kusano 7d535a
**   this list of conditions and the following disclaimer.
kusano 7d535a
** * Redistributions in binary form must reproduce the above copyright notice, 
kusano 7d535a
**   this list of conditions and the following disclaimer in the documentation 
kusano 7d535a
**   and/or other materials provided with the distribution.
kusano 7d535a
** * The name of the author may be used to endorse or promote products 
kusano 7d535a
**   derived from this software without specific prior written permission.
kusano 7d535a
**
kusano 7d535a
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
kusano 7d535a
** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
kusano 7d535a
** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
kusano 7d535a
** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
kusano 7d535a
** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
kusano 7d535a
** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
kusano 7d535a
** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
kusano 7d535a
** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
kusano 7d535a
** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
kusano 7d535a
** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
kusano 7d535a
** THE POSSIBILITY OF SUCH DAMAGE.
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
#include <gl glew.h=""></gl>
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
#include "glew_utils.h"
kusano 7d535a
kusano 7d535a
#if defined(__APPLE__)
kusano 7d535a
#include <mach-o dyld.h=""></mach-o>
kusano 7d535a
#include <stdlib.h></stdlib.h>
kusano 7d535a
#include <string.h></string.h>
kusano 7d535a
kusano 7d535a
void* NSGLGetProcAddress (const GLubyte *name)
kusano 7d535a
{
kusano 7d535a
  NSSymbol symbol;
kusano 7d535a
  char* symbolName;
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
  free(symbolName);
kusano 7d535a
  return symbol ? NSAddressOfSymbol(symbol) : NULL;
kusano 7d535a
}
kusano 7d535a
#endif /* __APPLE__ */
kusano 7d535a
kusano 7d535a
#if defined(__sgi) || defined (__sun)
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 */
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
kusano 7d535a
GLuint _glewStrLen (const GLubyte* s)
kusano 7d535a
{
kusano 7d535a
  GLuint i=0;
kusano 7d535a
  while (s+i != NULL && s[i] != '\0') i++;
kusano 7d535a
  return i;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
kusano 7d535a
{
kusano 7d535a
  GLuint i=0;
kusano 7d535a
  while (s+i != NULL && s[i] != '\0' && s[i] != c) i++;
kusano 7d535a
  return i;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
kusano 7d535a
{
kusano 7d535a
  GLuint i=0;
kusano 7d535a
  while (i < n && a+i != NULL && b+i != NULL && a[i] == b[i]) i++;
kusano 7d535a
  return i == n ? GL_TRUE : GL_FALSE;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
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
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
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
}