blob: 64ea360eb34ba5e27c76ff08faa26923b99448f9 [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é Fonsecac6b49ce2010-11-28 16:43:04 +000032import stdapi
José Fonseca669b2002011-02-20 13:32:19 +000033from dispatch import Dispatcher
José Fonsecac6b49ce2010-11-28 16:43:04 +000034from glapi import glapi
35from glxapi import glxapi
36from wglapi import wglapi
José Fonseca43648602011-05-15 12:56:59 +010037from 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([
42 "glAccum",
43 "glAlphaFunc",
44 "glAreTexturesResident",
45 "glArrayElement",
46 "glBegin",
47 "glBindTexture",
48 "glBitmap",
49 "glBlendFunc",
50 "glCallList",
51 "glCallLists",
52 "glClear",
53 "glClearAccum",
54 "glClearColor",
55 "glClearDepth",
56 "glClearIndex",
57 "glClearStencil",
58 "glClipPlane",
59 "glColor3b",
60 "glColor3bv",
61 "glColor3d",
62 "glColor3dv",
63 "glColor3f",
64 "glColor3fv",
65 "glColor3i",
66 "glColor3iv",
67 "glColor3s",
68 "glColor3sv",
69 "glColor3ub",
70 "glColor3ubv",
71 "glColor3ui",
72 "glColor3uiv",
73 "glColor3us",
74 "glColor3usv",
75 "glColor4b",
76 "glColor4bv",
77 "glColor4d",
78 "glColor4dv",
79 "glColor4f",
80 "glColor4fv",
81 "glColor4i",
82 "glColor4iv",
83 "glColor4s",
84 "glColor4sv",
85 "glColor4ub",
86 "glColor4ubv",
87 "glColor4ui",
88 "glColor4uiv",
89 "glColor4us",
90 "glColor4usv",
91 "glColorMask",
92 "glColorMaterial",
93 "glColorPointer",
94 "glCopyPixels",
95 "glCopyTexImage1D",
96 "glCopyTexImage2D",
97 "glCopyTexSubImage1D",
98 "glCopyTexSubImage2D",
99 "glCullFace",
100# "glDebugEntry",
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",
379 "wglChoosePixelFormat",
380 "wglCopyContext",
381 "wglCreateContext",
382 "wglCreateLayerContext",
383 "wglDeleteContext",
384 "wglDescribeLayerPlane",
385 "wglDescribePixelFormat",
386 "wglGetCurrentContext",
387 "wglGetCurrentDC",
388 "wglGetDefaultProcAddress",
389 "wglGetLayerPaletteEntries",
390 "wglGetPixelFormat",
391 "wglGetProcAddress",
392 "wglMakeCurrent",
393 "wglRealizeLayerPalette",
394 "wglSetLayerPaletteEntries",
395 "wglSetPixelFormat",
396 "wglShareLists",
397 "wglSwapBuffers",
398 "wglSwapLayerBuffers",
399 "wglSwapMultipleBuffers",
400 "wglUseFontBitmapsA",
401 "wglUseFontBitmapsW",
402 "wglUseFontOutlinesA",
403 "wglUseFontOutlinesW",
José Fonseca68ec4122011-02-20 11:25:25 +0000404
405 "glXGetProcAddressARB",
406 "glXGetProcAddress",
José Fonsecac6b49ce2010-11-28 16:43:04 +0000407])
408
409
José Fonseca68ec4122011-02-20 11:25:25 +0000410class GlDispatcher(Dispatcher):
411
412 def header(self):
José Fonseca68ec4122011-02-20 11:25:25 +0000413 print '#ifdef RETRACE'
José Fonseca3dabe542011-05-19 17:57:18 +0100414 print '# if defined(_WIN32)'
José Fonseca68ec4122011-02-20 11:25:25 +0000415 print '# define __getPrivateProcAddress(name) wglGetProcAddress(name)'
José Fonseca3dabe542011-05-19 17:57:18 +0100416 print '# elif defined(__APPLE__)'
417 print '# include <dlfcn.h>'
418 print '# define __getPrivateProcAddress(name) dlsym(RTLD_DEFAULT, name)'
José Fonseca68ec4122011-02-20 11:25:25 +0000419 print '# else'
420 print '# define __getPrivateProcAddress(name) glXGetProcAddressARB((const GLubyte *)(name))'
421 print '# endif'
422 print '# define __abort() OS::Abort()'
423 print '#else /* !RETRACE */'
José Fonseca9a3984e2011-04-18 07:49:39 +0100424 print '# ifdef _WIN32'
José Fonseca68ec4122011-02-20 11:25:25 +0000425 print '# define __getPrivateProcAddress(name) __wglGetProcAddress(name)'
426 print ' static inline PROC __stdcall __wglGetProcAddress(const char * lpszProc);'
427 print '# else'
José Fonseca68b14052011-04-21 10:32:45 +0100428 print '# define __getPublicProcAddress(name) __dlsym(name)'
José Fonseca68b14052011-04-21 10:32:45 +0100429 print ' static void * __dlsym(const char *symbol);'
José Fonseca43648602011-05-15 12:56:59 +0100430 print '# ifdef __APPLE__'
431 print '# define __getPrivateProcAddress(name) __getPublicProcAddress(name)'
432 print '# else'
433 print '# define __getPrivateProcAddress(name) __glXGetProcAddressARB((const GLubyte *)(name))'
434 print ' static inline __GLXextFuncPtr __glXGetProcAddressARB(const GLubyte * procName);'
435 print '# endif'
José Fonseca68ec4122011-02-20 11:25:25 +0000436 print '# endif'
437 print '# define __abort() Trace::Abort()'
438 print '#endif /* !RETRACE */'
439 print
440
441 def is_public_function(self, function):
José Fonseca3bcb33c2011-05-27 20:14:31 +0100442 return function.name in public_symbols or function.name.startswith('CGL')
José Fonsecac6b49ce2010-11-28 16:43:04 +0000443
444
445if __name__ == '__main__':
446 print
José Fonseca669b2002011-02-20 13:32:19 +0000447 print '#ifndef _GLPROC_HPP_'
448 print '#define _GLPROC_HPP_'
449 print
José Fonsecac6b49ce2010-11-28 16:43:04 +0000450 print '#include "glimports.hpp"'
451 print '#include "os.hpp"'
452 print
José Fonsecac6b49ce2010-11-28 16:43:04 +0000453 print
José Fonseca68ec4122011-02-20 11:25:25 +0000454 dispatcher = GlDispatcher()
455 dispatcher.header()
José Fonseca3dabe542011-05-19 17:57:18 +0100456 print '#if defined(_WIN32)'
José Fonseca68ec4122011-02-20 11:25:25 +0000457 print
458 dispatcher.dispatch_api(wglapi)
José Fonseca3dabe542011-05-19 17:57:18 +0100459 print '#elif defined(__APPLE__)'
460 dispatcher.dispatch_api(cglapi)
461 print '#else'
José Fonseca68ec4122011-02-20 11:25:25 +0000462 print
463 dispatcher.dispatch_api(glxapi)
José Fonseca3dabe542011-05-19 17:57:18 +0100464 print '#endif'
José Fonseca43648602011-05-15 12:56:59 +0100465 print
José Fonseca68ec4122011-02-20 11:25:25 +0000466 dispatcher.dispatch_api(glapi)
José Fonsecac6b49ce2010-11-28 16:43:04 +0000467 print
José Fonseca669b2002011-02-20 13:32:19 +0000468 print '#endif /* !_GLPROC_HPP_ */'
469 print