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