/external/glew-1.9.0/auto/src/glew_head.c

https://gitlab.com/dannywillems/mass_collide · C · 247 lines · 204 code · 21 blank · 22 comment · 103 complexity · 8a5473ae4878b48927990f791c7f4796 MD5 · raw file

  1. #include <GL/glew.h>
  2. #if defined(_WIN32)
  3. # include <GL/wglew.h>
  4. #elif !defined(__ANDROID__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))
  5. # include <GL/glxew.h>
  6. #endif
  7. /*
  8. * Define glewGetContext and related helper macros.
  9. */
  10. #ifdef GLEW_MX
  11. # define glewGetContext() ctx
  12. # ifdef _WIN32
  13. # define GLEW_CONTEXT_ARG_DEF_INIT GLEWContext* ctx
  14. # define GLEW_CONTEXT_ARG_VAR_INIT ctx
  15. # define wglewGetContext() ctx
  16. # define WGLEW_CONTEXT_ARG_DEF_INIT WGLEWContext* ctx
  17. # define WGLEW_CONTEXT_ARG_DEF_LIST WGLEWContext* ctx
  18. # else /* _WIN32 */
  19. # define GLEW_CONTEXT_ARG_DEF_INIT void
  20. # define GLEW_CONTEXT_ARG_VAR_INIT
  21. # define glxewGetContext() ctx
  22. # define GLXEW_CONTEXT_ARG_DEF_INIT void
  23. # define GLXEW_CONTEXT_ARG_DEF_LIST GLXEWContext* ctx
  24. # endif /* _WIN32 */
  25. # define GLEW_CONTEXT_ARG_DEF_LIST GLEWContext* ctx
  26. #else /* GLEW_MX */
  27. # define GLEW_CONTEXT_ARG_DEF_INIT void
  28. # define GLEW_CONTEXT_ARG_VAR_INIT
  29. # define GLEW_CONTEXT_ARG_DEF_LIST void
  30. # define WGLEW_CONTEXT_ARG_DEF_INIT void
  31. # define WGLEW_CONTEXT_ARG_DEF_LIST void
  32. # define GLXEW_CONTEXT_ARG_DEF_INIT void
  33. # define GLXEW_CONTEXT_ARG_DEF_LIST void
  34. #endif /* GLEW_MX */
  35. #if defined(__sgi) || defined (__sun) || defined(GLEW_APPLE_GLX)
  36. #include <dlfcn.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. void* dlGetProcAddress (const GLubyte* name)
  40. {
  41. static void* h = NULL;
  42. static void* gpa;
  43. if (h == NULL)
  44. {
  45. if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL;
  46. gpa = dlsym(h, "glXGetProcAddress");
  47. }
  48. if (gpa != NULL)
  49. return ((void*(*)(const GLubyte*))gpa)(name);
  50. else
  51. return dlsym(h, (const char*)name);
  52. }
  53. #endif /* __sgi || __sun || GLEW_APPLE_GLX */
  54. #if defined(__APPLE__)
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <AvailabilityMacros.h>
  58. #ifdef MAC_OS_X_VERSION_10_3
  59. #include <dlfcn.h>
  60. void* NSGLGetProcAddress (const GLubyte *name)
  61. {
  62. static void* image = NULL;
  63. void* addr;
  64. if (NULL == image)
  65. {
  66. #ifdef GLEW_REGAL
  67. image = dlopen("libRegal.dylib", RTLD_LAZY);
  68. #else
  69. image = dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", RTLD_LAZY);
  70. #endif
  71. }
  72. if( !image ) return NULL;
  73. addr = dlsym(image, (const char*)name);
  74. if( addr ) return addr;
  75. #ifdef GLEW_APPLE_GLX
  76. return dlGetProcAddress( name ); // try next for glx symbols
  77. #else
  78. return NULL;
  79. #endif
  80. }
  81. #else
  82. #include <mach-o/dyld.h>
  83. void* NSGLGetProcAddress (const GLubyte *name)
  84. {
  85. static const struct mach_header* image = NULL;
  86. NSSymbol symbol;
  87. char* symbolName;
  88. if (NULL == image)
  89. {
  90. #ifdef GLEW_REGAL
  91. image = NSAddImage("libRegal.dylib", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
  92. #else
  93. image = NSAddImage("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", NSADDIMAGE_OPTION_RETURN_ON_ERROR);
  94. #endif
  95. }
  96. /* prepend a '_' for the Unix C symbol mangling convention */
  97. symbolName = malloc(strlen((const char*)name) + 2);
  98. strcpy(symbolName+1, (const char*)name);
  99. symbolName[0] = '_';
  100. symbol = NULL;
  101. /* if (NSIsSymbolNameDefined(symbolName))
  102. symbol = NSLookupAndBindSymbol(symbolName); */
  103. symbol = image ? NSLookupSymbolInImage(image, symbolName, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR) : NULL;
  104. free(symbolName);
  105. if( symbol ) return NSAddressOfSymbol(symbol);
  106. #ifdef GLEW_APPLE_GLX
  107. return dlGetProcAddress( name ); // try next for glx symbols
  108. #else
  109. return NULL;
  110. #endif
  111. }
  112. #endif /* MAC_OS_X_VERSION_10_3 */
  113. #endif /* __APPLE__ */
  114. /*
  115. * Define glewGetProcAddress.
  116. */
  117. #if defined(_WIN32)
  118. # define glewGetProcAddress(name) wglGetProcAddress((LPCSTR)name)
  119. #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX)
  120. # define glewGetProcAddress(name) NSGLGetProcAddress(name)
  121. #elif defined(__sgi) || defined(__sun)
  122. # define glewGetProcAddress(name) dlGetProcAddress(name)
  123. #elif defined(__ANDROID__)
  124. # define glewGetProcAddress(name) NULL /* TODO */
  125. #else /* __linux */
  126. # define glewGetProcAddress(name) (*glXGetProcAddressARB)(name)
  127. #endif
  128. /*
  129. * Define GLboolean const cast.
  130. */
  131. #define CONST_CAST(x) (*(GLboolean*)&x)
  132. /*
  133. * GLEW, just like OpenGL or GLU, does not rely on the standard C library.
  134. * These functions implement the functionality required in this file.
  135. */
  136. static GLuint _glewStrLen (const GLubyte* s)
  137. {
  138. GLuint i=0;
  139. if (s == NULL) return 0;
  140. while (s[i] != '\0') i++;
  141. return i;
  142. }
  143. static GLuint _glewStrCLen (const GLubyte* s, GLubyte c)
  144. {
  145. GLuint i=0;
  146. if (s == NULL) return 0;
  147. while (s[i] != '\0' && s[i] != c) i++;
  148. return (s[i] == '\0' || s[i] == c) ? i : 0;
  149. }
  150. static GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n)
  151. {
  152. GLuint i=0;
  153. if(a == NULL || b == NULL)
  154. return (a == NULL && b == NULL && n == 0) ? GL_TRUE : GL_FALSE;
  155. while (i < n && a[i] != '\0' && b[i] != '\0' && a[i] == b[i]) i++;
  156. return i == n ? GL_TRUE : GL_FALSE;
  157. }
  158. static GLboolean _glewStrSame1 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
  159. {
  160. while (*na > 0 && (**a == ' ' || **a == '\n' || **a == '\r' || **a == '\t'))
  161. {
  162. (*a)++;
  163. (*na)--;
  164. }
  165. if(*na >= nb)
  166. {
  167. GLuint i=0;
  168. while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
  169. if(i == nb)
  170. {
  171. *a = *a + nb;
  172. *na = *na - nb;
  173. return GL_TRUE;
  174. }
  175. }
  176. return GL_FALSE;
  177. }
  178. static GLboolean _glewStrSame2 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
  179. {
  180. if(*na >= nb)
  181. {
  182. GLuint i=0;
  183. while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
  184. if(i == nb)
  185. {
  186. *a = *a + nb;
  187. *na = *na - nb;
  188. return GL_TRUE;
  189. }
  190. }
  191. return GL_FALSE;
  192. }
  193. static GLboolean _glewStrSame3 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb)
  194. {
  195. if(*na >= nb)
  196. {
  197. GLuint i=0;
  198. while (i < nb && (*a)+i != NULL && b+i != NULL && (*a)[i] == b[i]) i++;
  199. if (i == nb && (*na == nb || (*a)[i] == ' ' || (*a)[i] == '\n' || (*a)[i] == '\r' || (*a)[i] == '\t'))
  200. {
  201. *a = *a + nb;
  202. *na = *na - nb;
  203. return GL_TRUE;
  204. }
  205. }
  206. return GL_FALSE;
  207. }
  208. /*
  209. * Search for name in the extensions string. Use of strstr()
  210. * is not sufficient because extension names can be prefixes of
  211. * other extension names. Could use strtok() but the constant
  212. * string returned by glGetString might be in read-only memory.
  213. */
  214. static GLboolean _glewSearchExtension (const char* name, const GLubyte *start, const GLubyte *end)
  215. {
  216. const GLubyte* p;
  217. GLuint len = _glewStrLen((const GLubyte*)name);
  218. p = start;
  219. while (p < end)
  220. {
  221. GLuint n = _glewStrCLen(p, ' ');
  222. if (len == n && _glewStrSame((const GLubyte*)name, p, n)) return GL_TRUE;
  223. p += n+1;
  224. }
  225. return GL_FALSE;
  226. }