blob: 6a44917d6c1816e278dff522886083814ad03ed7 [file] [log] [blame]
José Fonsecac6b49ce2010-11-28 16:43:04 +00001##########################################################################
2#
3# Copyright 2010 VMware, Inc.
4# All Rights Reserved.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23#
24##########################################################################/
25
26
José Fonseca4a826ed2010-11-30 16:58:22 +000027"""Generated an header, glproc.hpp, which does pretty much what GLEW does, but
28covers all the functions we support.
29"""
30
31
José Fonsecabd86a222011-09-27 09:21:38 +010032import specs.stdapi as stdapi
José Fonseca669b2002011-02-20 13:32:19 +000033from dispatch import Dispatcher
José Fonsecabd86a222011-09-27 09:21:38 +010034from specs.glapi import glapi
35from specs.glxapi import glxapi
36from specs.wglapi import wglapi
37from specs.cglapi import cglapi
José Fonsecac6b49ce2010-11-28 16:43:04 +000038
39
José Fonseca68ec4122011-02-20 11:25:25 +000040# See http://www.opengl.org/registry/ABI/
José Fonsecac6b49ce2010-11-28 16:43:04 +000041public_symbols = set([
José Fonsecab87c2292011-10-09 14:56:16 +010042 # GL 1.2 and ARB_multitexture
43 "glAccum",
44 "glAlphaFunc",
45 "glAreTexturesResident",
46 "glArrayElement",
47 "glBegin",
48 "glBindTexture",
49 "glBitmap",
50 "glBlendFunc",
51 "glCallList",
52 "glCallLists",
53 "glClear",
54 "glClearAccum",
55 "glClearColor",
56 "glClearDepth",
57 "glClearIndex",
58 "glClearStencil",
59 "glClipPlane",
60 "glColor3b",
61 "glColor3bv",
62 "glColor3d",
63 "glColor3dv",
64 "glColor3f",
65 "glColor3fv",
66 "glColor3i",
67 "glColor3iv",
68 "glColor3s",
69 "glColor3sv",
70 "glColor3ub",
71 "glColor3ubv",
72 "glColor3ui",
73 "glColor3uiv",
74 "glColor3us",
75 "glColor3usv",
76 "glColor4b",
77 "glColor4bv",
78 "glColor4d",
79 "glColor4dv",
80 "glColor4f",
81 "glColor4fv",
82 "glColor4i",
83 "glColor4iv",
84 "glColor4s",
85 "glColor4sv",
86 "glColor4ub",
87 "glColor4ubv",
88 "glColor4ui",
89 "glColor4uiv",
90 "glColor4us",
91 "glColor4usv",
92 "glColorMask",
93 "glColorMaterial",
94 "glColorPointer",
95 "glCopyPixels",
96 "glCopyTexImage1D",
97 "glCopyTexImage2D",
98 "glCopyTexSubImage1D",
99 "glCopyTexSubImage2D",
100 "glCullFace",
101 "glDeleteLists",
102 "glDeleteTextures",
103 "glDepthFunc",
104 "glDepthMask",
105 "glDepthRange",
106 "glDisable",
107 "glDisableClientState",
108 "glDrawArrays",
109 "glDrawBuffer",
110 "glDrawElements",
111 "glDrawPixels",
112 "glEdgeFlag",
113 "glEdgeFlagPointer",
114 "glEdgeFlagv",
115 "glEnable",
116 "glEnableClientState",
117 "glEnd",
118 "glEndList",
119 "glEvalCoord1d",
120 "glEvalCoord1dv",
121 "glEvalCoord1f",
122 "glEvalCoord1fv",
123 "glEvalCoord2d",
124 "glEvalCoord2dv",
125 "glEvalCoord2f",
126 "glEvalCoord2fv",
127 "glEvalMesh1",
128 "glEvalMesh2",
129 "glEvalPoint1",
130 "glEvalPoint2",
131 "glFeedbackBuffer",
132 "glFinish",
133 "glFlush",
134 "glFogf",
135 "glFogfv",
136 "glFogi",
137 "glFogiv",
138 "glFrontFace",
139 "glFrustum",
140 "glGenLists",
141 "glGenTextures",
142 "glGetBooleanv",
143 "glGetClipPlane",
144 "glGetDoublev",
145 "glGetError",
146 "glGetFloatv",
147 "glGetIntegerv",
148 "glGetLightfv",
149 "glGetLightiv",
150 "glGetMapdv",
151 "glGetMapfv",
152 "glGetMapiv",
153 "glGetMaterialfv",
154 "glGetMaterialiv",
155 "glGetPixelMapfv",
156 "glGetPixelMapuiv",
157 "glGetPixelMapusv",
158 "glGetPointerv",
159 "glGetPolygonStipple",
160 "glGetString",
161 "glGetTexEnvfv",
162 "glGetTexEnviv",
163 "glGetTexGendv",
164 "glGetTexGenfv",
165 "glGetTexGeniv",
166 "glGetTexImage",
167 "glGetTexLevelParameterfv",
168 "glGetTexLevelParameteriv",
169 "glGetTexParameterfv",
170 "glGetTexParameteriv",
171 "glHint",
172 "glIndexMask",
173 "glIndexPointer",
174 "glIndexd",
175 "glIndexdv",
176 "glIndexf",
177 "glIndexfv",
178 "glIndexi",
179 "glIndexiv",
180 "glIndexs",
181 "glIndexsv",
182 "glIndexub",
183 "glIndexubv",
184 "glInitNames",
185 "glInterleavedArrays",
186 "glIsEnabled",
187 "glIsList",
188 "glIsTexture",
189 "glLightModelf",
190 "glLightModelfv",
191 "glLightModeli",
192 "glLightModeliv",
193 "glLightf",
194 "glLightfv",
195 "glLighti",
196 "glLightiv",
197 "glLineStipple",
198 "glLineWidth",
199 "glListBase",
200 "glLoadIdentity",
201 "glLoadMatrixd",
202 "glLoadMatrixf",
203 "glLoadName",
204 "glLogicOp",
205 "glMap1d",
206 "glMap1f",
207 "glMap2d",
208 "glMap2f",
209 "glMapGrid1d",
210 "glMapGrid1f",
211 "glMapGrid2d",
212 "glMapGrid2f",
213 "glMaterialf",
214 "glMaterialfv",
215 "glMateriali",
216 "glMaterialiv",
217 "glMatrixMode",
218 "glMultMatrixd",
219 "glMultMatrixf",
220 "glNewList",
221 "glNormal3b",
222 "glNormal3bv",
223 "glNormal3d",
224 "glNormal3dv",
225 "glNormal3f",
226 "glNormal3fv",
227 "glNormal3i",
228 "glNormal3iv",
229 "glNormal3s",
230 "glNormal3sv",
231 "glNormalPointer",
232 "glOrtho",
233 "glPassThrough",
234 "glPixelMapfv",
235 "glPixelMapuiv",
236 "glPixelMapusv",
237 "glPixelStoref",
238 "glPixelStorei",
239 "glPixelTransferf",
240 "glPixelTransferi",
241 "glPixelZoom",
242 "glPointSize",
243 "glPolygonMode",
244 "glPolygonOffset",
245 "glPolygonStipple",
246 "glPopAttrib",
247 "glPopClientAttrib",
248 "glPopMatrix",
249 "glPopName",
250 "glPrioritizeTextures",
251 "glPushAttrib",
252 "glPushClientAttrib",
253 "glPushMatrix",
254 "glPushName",
255 "glRasterPos2d",
256 "glRasterPos2dv",
257 "glRasterPos2f",
258 "glRasterPos2fv",
259 "glRasterPos2i",
260 "glRasterPos2iv",
261 "glRasterPos2s",
262 "glRasterPos2sv",
263 "glRasterPos3d",
264 "glRasterPos3dv",
265 "glRasterPos3f",
266 "glRasterPos3fv",
267 "glRasterPos3i",
268 "glRasterPos3iv",
269 "glRasterPos3s",
270 "glRasterPos3sv",
271 "glRasterPos4d",
272 "glRasterPos4dv",
273 "glRasterPos4f",
274 "glRasterPos4fv",
275 "glRasterPos4i",
276 "glRasterPos4iv",
277 "glRasterPos4s",
278 "glRasterPos4sv",
279 "glReadBuffer",
280 "glReadPixels",
281 "glRectd",
282 "glRectdv",
283 "glRectf",
284 "glRectfv",
285 "glRecti",
286 "glRectiv",
287 "glRects",
288 "glRectsv",
289 "glRenderMode",
290 "glRotated",
291 "glRotatef",
292 "glScaled",
293 "glScalef",
294 "glScissor",
295 "glSelectBuffer",
296 "glShadeModel",
297 "glStencilFunc",
298 "glStencilMask",
299 "glStencilOp",
300 "glTexCoord1d",
301 "glTexCoord1dv",
302 "glTexCoord1f",
303 "glTexCoord1fv",
304 "glTexCoord1i",
305 "glTexCoord1iv",
306 "glTexCoord1s",
307 "glTexCoord1sv",
308 "glTexCoord2d",
309 "glTexCoord2dv",
310 "glTexCoord2f",
311 "glTexCoord2fv",
312 "glTexCoord2i",
313 "glTexCoord2iv",
314 "glTexCoord2s",
315 "glTexCoord2sv",
316 "glTexCoord3d",
317 "glTexCoord3dv",
318 "glTexCoord3f",
319 "glTexCoord3fv",
320 "glTexCoord3i",
321 "glTexCoord3iv",
322 "glTexCoord3s",
323 "glTexCoord3sv",
324 "glTexCoord4d",
325 "glTexCoord4dv",
326 "glTexCoord4f",
327 "glTexCoord4fv",
328 "glTexCoord4i",
329 "glTexCoord4iv",
330 "glTexCoord4s",
331 "glTexCoord4sv",
332 "glTexCoordPointer",
333 "glTexEnvf",
334 "glTexEnvfv",
335 "glTexEnvi",
336 "glTexEnviv",
337 "glTexGend",
338 "glTexGendv",
339 "glTexGenf",
340 "glTexGenfv",
341 "glTexGeni",
342 "glTexGeniv",
343 "glTexImage1D",
344 "glTexImage2D",
345 "glTexParameterf",
346 "glTexParameterfv",
347 "glTexParameteri",
348 "glTexParameteriv",
349 "glTexSubImage1D",
350 "glTexSubImage2D",
351 "glTranslated",
352 "glTranslatef",
353 "glVertex2d",
354 "glVertex2dv",
355 "glVertex2f",
356 "glVertex2fv",
357 "glVertex2i",
358 "glVertex2iv",
359 "glVertex2s",
360 "glVertex2sv",
361 "glVertex3d",
362 "glVertex3dv",
363 "glVertex3f",
364 "glVertex3fv",
365 "glVertex3i",
366 "glVertex3iv",
367 "glVertex3s",
368 "glVertex3sv",
369 "glVertex4d",
370 "glVertex4dv",
371 "glVertex4f",
372 "glVertex4fv",
373 "glVertex4i",
374 "glVertex4iv",
375 "glVertex4s",
376 "glVertex4sv",
377 "glVertexPointer",
378 "glViewport",
José Fonseca68ec4122011-02-20 11:25:25 +0000379
José Fonsecab87c2292011-10-09 14:56:16 +0100380 # GLX 1.3 and GLX_ARB_get_proc_address
381 "glXChooseVisual",
382 "glXCreateContext",
383 "glXDestroyContext",
384 "glXMakeCurrent",
385 "glXCopyContext",
386 "glXSwapBuffers",
387 "glXCreateGLXPixmap",
388 "glXDestroyGLXPixmap",
389 "glXQueryExtension",
390 "glXQueryVersion",
391 "glXIsDirect",
392 "glXGetConfig",
393 "glXGetCurrentContext",
394 "glXGetCurrentDrawable",
395 "glXWaitGL",
396 "glXWaitX",
397 "glXUseXFont",
398 "glXQueryExtensionsString",
399 "glXQueryServerString",
400 "glXGetClientString",
401 "glXGetCurrentDisplay",
402 "glXChooseFBConfig",
403 "glXGetFBConfigAttrib",
404 "glXGetFBConfigs",
405 "glXGetVisualFromFBConfig",
406 "glXCreateWindow",
407 "glXDestroyWindow",
408 "glXCreatePixmap",
409 "glXDestroyPixmap",
410 "glXCreatePbuffer",
411 "glXDestroyPbuffer",
412 "glXQueryDrawable",
413 "glXCreateNewContext",
414 "glXMakeContextCurrent",
415 "glXGetCurrentReadDrawable",
416 "glXQueryContext",
417 "glXSelectEvent",
418 "glXGetSelectedEvent",
José Fonseca68ec4122011-02-20 11:25:25 +0000419 "glXGetProcAddressARB",
420 "glXGetProcAddress",
José Fonsecab87c2292011-10-09 14:56:16 +0100421
422 # WGL
423 #"glDebugEntry",
424 "wglChoosePixelFormat",
425 "wglCopyContext",
426 "wglCreateContext",
427 "wglCreateLayerContext",
428 "wglDeleteContext",
429 "wglDescribeLayerPlane",
430 "wglDescribePixelFormat",
431 "wglGetCurrentContext",
432 "wglGetCurrentDC",
433 "wglGetDefaultProcAddress",
434 "wglGetLayerPaletteEntries",
435 "wglGetPixelFormat",
436 "wglGetProcAddress",
437 "wglMakeCurrent",
438 "wglRealizeLayerPalette",
439 "wglSetLayerPaletteEntries",
440 "wglSetPixelFormat",
441 "wglShareLists",
442 "wglSwapBuffers",
443 "wglSwapLayerBuffers",
444 "wglSwapMultipleBuffers",
445 "wglUseFontBitmapsA",
446 "wglUseFontBitmapsW",
447 "wglUseFontOutlinesA",
448 "wglUseFontOutlinesW",
449
José Fonsecac6b49ce2010-11-28 16:43:04 +0000450])
451
452
José Fonseca68ec4122011-02-20 11:25:25 +0000453class GlDispatcher(Dispatcher):
454
455 def header(self):
José Fonseca68ec4122011-02-20 11:25:25 +0000456 print '#ifdef RETRACE'
José Fonseca3dabe542011-05-19 17:57:18 +0100457 print '# if defined(_WIN32)'
José Fonseca68ec4122011-02-20 11:25:25 +0000458 print '# define __getPrivateProcAddress(name) wglGetProcAddress(name)'
José Fonseca3dabe542011-05-19 17:57:18 +0100459 print '# elif defined(__APPLE__)'
460 print '# include <dlfcn.h>'
461 print '# define __getPrivateProcAddress(name) dlsym(RTLD_DEFAULT, name)'
José Fonseca68ec4122011-02-20 11:25:25 +0000462 print '# else'
463 print '# define __getPrivateProcAddress(name) glXGetProcAddressARB((const GLubyte *)(name))'
464 print '# endif'
José Fonseca68ec4122011-02-20 11:25:25 +0000465 print '#else /* !RETRACE */'
José Fonseca9a3984e2011-04-18 07:49:39 +0100466 print '# ifdef _WIN32'
José Fonseca64e265d2011-08-25 15:15:42 +0100467 print ' PROC __getPublicProcAddress(LPCSTR lpProcName);'
José Fonseca68ec4122011-02-20 11:25:25 +0000468 print '# define __getPrivateProcAddress(name) __wglGetProcAddress(name)'
469 print ' static inline PROC __stdcall __wglGetProcAddress(const char * lpszProc);'
470 print '# else'
José Fonsecac7b1c2a2011-06-11 12:26:39 +0100471 print '# define __getPublicProcAddress(name) __libgl_sym(name)'
472 print ' void * __libgl_sym(const char *symbol);'
José Fonseca43648602011-05-15 12:56:59 +0100473 print '# ifdef __APPLE__'
474 print '# define __getPrivateProcAddress(name) __getPublicProcAddress(name)'
475 print '# else'
476 print '# define __getPrivateProcAddress(name) __glXGetProcAddressARB((const GLubyte *)(name))'
477 print ' static inline __GLXextFuncPtr __glXGetProcAddressARB(const GLubyte * procName);'
478 print '# endif'
José Fonseca68ec4122011-02-20 11:25:25 +0000479 print '# endif'
José Fonseca68ec4122011-02-20 11:25:25 +0000480 print '#endif /* !RETRACE */'
481 print
482
483 def is_public_function(self, function):
José Fonseca3bcb33c2011-05-27 20:14:31 +0100484 return function.name in public_symbols or function.name.startswith('CGL')
José Fonsecac6b49ce2010-11-28 16:43:04 +0000485
486
487if __name__ == '__main__':
488 print
José Fonseca669b2002011-02-20 13:32:19 +0000489 print '#ifndef _GLPROC_HPP_'
490 print '#define _GLPROC_HPP_'
491 print
José Fonsecac6b49ce2010-11-28 16:43:04 +0000492 print '#include "glimports.hpp"'
493 print '#include "os.hpp"'
494 print
José Fonsecac6b49ce2010-11-28 16:43:04 +0000495 print
José Fonseca68ec4122011-02-20 11:25:25 +0000496 dispatcher = GlDispatcher()
497 dispatcher.header()
José Fonseca3dabe542011-05-19 17:57:18 +0100498 print '#if defined(_WIN32)'
José Fonseca68ec4122011-02-20 11:25:25 +0000499 print
500 dispatcher.dispatch_api(wglapi)
José Fonseca3dabe542011-05-19 17:57:18 +0100501 print '#elif defined(__APPLE__)'
502 dispatcher.dispatch_api(cglapi)
503 print '#else'
José Fonseca68ec4122011-02-20 11:25:25 +0000504 print
505 dispatcher.dispatch_api(glxapi)
José Fonseca3dabe542011-05-19 17:57:18 +0100506 print '#endif'
José Fonseca43648602011-05-15 12:56:59 +0100507 print
José Fonseca68ec4122011-02-20 11:25:25 +0000508 dispatcher.dispatch_api(glapi)
José Fonsecac6b49ce2010-11-28 16:43:04 +0000509 print
José Fonseca669b2002011-02-20 13:32:19 +0000510 print '#endif /* !_GLPROC_HPP_ */'
511 print