]> git.cworth.org Git - apitrace/blob - glproc.py
More complete WGL enums.
[apitrace] / glproc.py
1 ##########################################################################
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
27 """Generated an header, glproc.hpp, which does pretty much what GLEW does, but
28 covers all the functions we support.
29 """ 
30
31
32 import stdapi
33 from glapi import glapi
34 from glxapi import glxapi
35 from wglapi import wglapi
36
37
38 public_symbols = set([
39         "glAccum",
40         "glAlphaFunc",
41         "glAreTexturesResident",
42         "glArrayElement",
43         "glBegin",
44         "glBindTexture",
45         "glBitmap",
46         "glBlendFunc",
47         "glCallList",
48         "glCallLists",
49         "glClear",
50         "glClearAccum",
51         "glClearColor",
52         "glClearDepth",
53         "glClearIndex",
54         "glClearStencil",
55         "glClipPlane",
56         "glColor3b",
57         "glColor3bv",
58         "glColor3d",
59         "glColor3dv",
60         "glColor3f",
61         "glColor3fv",
62         "glColor3i",
63         "glColor3iv",
64         "glColor3s",
65         "glColor3sv",
66         "glColor3ub",
67         "glColor3ubv",
68         "glColor3ui",
69         "glColor3uiv",
70         "glColor3us",
71         "glColor3usv",
72         "glColor4b",
73         "glColor4bv",
74         "glColor4d",
75         "glColor4dv",
76         "glColor4f",
77         "glColor4fv",
78         "glColor4i",
79         "glColor4iv",
80         "glColor4s",
81         "glColor4sv",
82         "glColor4ub",
83         "glColor4ubv",
84         "glColor4ui",
85         "glColor4uiv",
86         "glColor4us",
87         "glColor4usv",
88         "glColorMask",
89         "glColorMaterial",
90         "glColorPointer",
91         "glCopyPixels",
92         "glCopyTexImage1D",
93         "glCopyTexImage2D",
94         "glCopyTexSubImage1D",
95         "glCopyTexSubImage2D",
96         "glCullFace",
97 #       "glDebugEntry",
98         "glDeleteLists",
99         "glDeleteTextures",
100         "glDepthFunc",
101         "glDepthMask",
102         "glDepthRange",
103         "glDisable",
104         "glDisableClientState",
105         "glDrawArrays",
106         "glDrawBuffer",
107         "glDrawElements",
108         "glDrawPixels",
109         "glEdgeFlag",
110         "glEdgeFlagPointer",
111         "glEdgeFlagv",
112         "glEnable",
113         "glEnableClientState",
114         "glEnd",
115         "glEndList",
116         "glEvalCoord1d",
117         "glEvalCoord1dv",
118         "glEvalCoord1f",
119         "glEvalCoord1fv",
120         "glEvalCoord2d",
121         "glEvalCoord2dv",
122         "glEvalCoord2f",
123         "glEvalCoord2fv",
124         "glEvalMesh1",
125         "glEvalMesh2",
126         "glEvalPoint1",
127         "glEvalPoint2",
128         "glFeedbackBuffer",
129         "glFinish",
130         "glFlush",
131         "glFogf",
132         "glFogfv",
133         "glFogi",
134         "glFogiv",
135         "glFrontFace",
136         "glFrustum",
137         "glGenLists",
138         "glGenTextures",
139         "glGetBooleanv",
140         "glGetClipPlane",
141         "glGetDoublev",
142         "glGetError",
143         "glGetFloatv",
144         "glGetIntegerv",
145         "glGetLightfv",
146         "glGetLightiv",
147         "glGetMapdv",
148         "glGetMapfv",
149         "glGetMapiv",
150         "glGetMaterialfv",
151         "glGetMaterialiv",
152         "glGetPixelMapfv",
153         "glGetPixelMapuiv",
154         "glGetPixelMapusv",
155         "glGetPointerv",
156         "glGetPolygonStipple",
157         "glGetString",
158         "glGetTexEnvfv",
159         "glGetTexEnviv",
160         "glGetTexGendv",
161         "glGetTexGenfv",
162         "glGetTexGeniv",
163         "glGetTexImage",
164         "glGetTexLevelParameterfv",
165         "glGetTexLevelParameteriv",
166         "glGetTexParameterfv",
167         "glGetTexParameteriv",
168         "glHint",
169         "glIndexMask",
170         "glIndexPointer",
171         "glIndexd",
172         "glIndexdv",
173         "glIndexf",
174         "glIndexfv",
175         "glIndexi",
176         "glIndexiv",
177         "glIndexs",
178         "glIndexsv",
179         "glIndexub",
180         "glIndexubv",
181         "glInitNames",
182         "glInterleavedArrays",
183         "glIsEnabled",
184         "glIsList",
185         "glIsTexture",
186         "glLightModelf",
187         "glLightModelfv",
188         "glLightModeli",
189         "glLightModeliv",
190         "glLightf",
191         "glLightfv",
192         "glLighti",
193         "glLightiv",
194         "glLineStipple",
195         "glLineWidth",
196         "glListBase",
197         "glLoadIdentity",
198         "glLoadMatrixd",
199         "glLoadMatrixf",
200         "glLoadName",
201         "glLogicOp",
202         "glMap1d",
203         "glMap1f",
204         "glMap2d",
205         "glMap2f",
206         "glMapGrid1d",
207         "glMapGrid1f",
208         "glMapGrid2d",
209         "glMapGrid2f",
210         "glMaterialf",
211         "glMaterialfv",
212         "glMateriali",
213         "glMaterialiv",
214         "glMatrixMode",
215         "glMultMatrixd",
216         "glMultMatrixf",
217         "glNewList",
218         "glNormal3b",
219         "glNormal3bv",
220         "glNormal3d",
221         "glNormal3dv",
222         "glNormal3f",
223         "glNormal3fv",
224         "glNormal3i",
225         "glNormal3iv",
226         "glNormal3s",
227         "glNormal3sv",
228         "glNormalPointer",
229         "glOrtho",
230         "glPassThrough",
231         "glPixelMapfv",
232         "glPixelMapuiv",
233         "glPixelMapusv",
234         "glPixelStoref",
235         "glPixelStorei",
236         "glPixelTransferf",
237         "glPixelTransferi",
238         "glPixelZoom",
239         "glPointSize",
240         "glPolygonMode",
241         "glPolygonOffset",
242         "glPolygonStipple",
243         "glPopAttrib",
244         "glPopClientAttrib",
245         "glPopMatrix",
246         "glPopName",
247         "glPrioritizeTextures",
248         "glPushAttrib",
249         "glPushClientAttrib",
250         "glPushMatrix",
251         "glPushName",
252         "glRasterPos2d",
253         "glRasterPos2dv",
254         "glRasterPos2f",
255         "glRasterPos2fv",
256         "glRasterPos2i",
257         "glRasterPos2iv",
258         "glRasterPos2s",
259         "glRasterPos2sv",
260         "glRasterPos3d",
261         "glRasterPos3dv",
262         "glRasterPos3f",
263         "glRasterPos3fv",
264         "glRasterPos3i",
265         "glRasterPos3iv",
266         "glRasterPos3s",
267         "glRasterPos3sv",
268         "glRasterPos4d",
269         "glRasterPos4dv",
270         "glRasterPos4f",
271         "glRasterPos4fv",
272         "glRasterPos4i",
273         "glRasterPos4iv",
274         "glRasterPos4s",
275         "glRasterPos4sv",
276         "glReadBuffer",
277         "glReadPixels",
278         "glRectd",
279         "glRectdv",
280         "glRectf",
281         "glRectfv",
282         "glRecti",
283         "glRectiv",
284         "glRects",
285         "glRectsv",
286         "glRenderMode",
287         "glRotated",
288         "glRotatef",
289         "glScaled",
290         "glScalef",
291         "glScissor",
292         "glSelectBuffer",
293         "glShadeModel",
294         "glStencilFunc",
295         "glStencilMask",
296         "glStencilOp",
297         "glTexCoord1d",
298         "glTexCoord1dv",
299         "glTexCoord1f",
300         "glTexCoord1fv",
301         "glTexCoord1i",
302         "glTexCoord1iv",
303         "glTexCoord1s",
304         "glTexCoord1sv",
305         "glTexCoord2d",
306         "glTexCoord2dv",
307         "glTexCoord2f",
308         "glTexCoord2fv",
309         "glTexCoord2i",
310         "glTexCoord2iv",
311         "glTexCoord2s",
312         "glTexCoord2sv",
313         "glTexCoord3d",
314         "glTexCoord3dv",
315         "glTexCoord3f",
316         "glTexCoord3fv",
317         "glTexCoord3i",
318         "glTexCoord3iv",
319         "glTexCoord3s",
320         "glTexCoord3sv",
321         "glTexCoord4d",
322         "glTexCoord4dv",
323         "glTexCoord4f",
324         "glTexCoord4fv",
325         "glTexCoord4i",
326         "glTexCoord4iv",
327         "glTexCoord4s",
328         "glTexCoord4sv",
329         "glTexCoordPointer",
330         "glTexEnvf",
331         "glTexEnvfv",
332         "glTexEnvi",
333         "glTexEnviv",
334         "glTexGend",
335         "glTexGendv",
336         "glTexGenf",
337         "glTexGenfv",
338         "glTexGeni",
339         "glTexGeniv",
340         "glTexImage1D",
341         "glTexImage2D",
342         "glTexParameterf",
343         "glTexParameterfv",
344         "glTexParameteri",
345         "glTexParameteriv",
346         "glTexSubImage1D",
347         "glTexSubImage2D",
348         "glTranslated",
349         "glTranslatef",
350         "glVertex2d",
351         "glVertex2dv",
352         "glVertex2f",
353         "glVertex2fv",
354         "glVertex2i",
355         "glVertex2iv",
356         "glVertex2s",
357         "glVertex2sv",
358         "glVertex3d",
359         "glVertex3dv",
360         "glVertex3f",
361         "glVertex3fv",
362         "glVertex3i",
363         "glVertex3iv",
364         "glVertex3s",
365         "glVertex3sv",
366         "glVertex4d",
367         "glVertex4dv",
368         "glVertex4f",
369         "glVertex4fv",
370         "glVertex4i",
371         "glVertex4iv",
372         "glVertex4s",
373         "glVertex4sv",
374         "glVertexPointer",
375         "glViewport",
376         "wglChoosePixelFormat",
377         "wglCopyContext",
378         "wglCreateContext",
379         "wglCreateLayerContext",
380         "wglDeleteContext",
381         "wglDescribeLayerPlane",
382         "wglDescribePixelFormat",
383         "wglGetCurrentContext",
384         "wglGetCurrentDC",
385         "wglGetDefaultProcAddress",
386         "wglGetLayerPaletteEntries",
387         "wglGetPixelFormat",
388         "wglGetProcAddress",
389         "wglMakeCurrent",
390         "wglRealizeLayerPalette",
391         "wglSetLayerPaletteEntries",
392         "wglSetPixelFormat",
393         "wglShareLists",
394         "wglSwapBuffers",
395         "wglSwapLayerBuffers",
396         "wglSwapMultipleBuffers",
397         "wglUseFontBitmapsA",
398         "wglUseFontBitmapsW",
399         "wglUseFontOutlinesA",
400         "wglUseFontOutlinesW",
401 ])
402
403
404 class Dispatcher:
405
406     def function_pointer_type(self, function):
407         return '__PFN' + function.name.upper()
408
409     def function_pointer_value(self, function):
410         return '__' + function.name + '_ptr'
411
412     def dispatch_function(self, function):
413         if function.name in public_symbols:
414             return
415
416         ptype = self.function_pointer_type(function)
417         pvalue = self.function_pointer_value(function)
418         print 'typedef ' + function.prototype('* %s' % ptype) + ';'
419         print 'static %s %s = NULL;' % (ptype, pvalue)
420         print
421         print 'static inline ' + function.prototype('__' + function.name) + ' {'
422         if function.type is stdapi.Void:
423             ret = ''
424         else:
425             ret = 'return '
426         self.get_true_pointer(function)
427         pvalue = self.function_pointer_value(function)
428         print '    %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args]))
429         print '}'
430         print
431         print '#define %s __%s' % (function.name, function.name)
432
433     def get_true_pointer(self, function):
434         ptype = self.function_pointer_type(function)
435         pvalue = self.function_pointer_value(function)
436         if function.name in public_symbols:
437             get_proc_address = '__getProcAddress'
438         else:
439             get_proc_address = '__glGetProcAddress'
440         print '    if (!%s) {' % (pvalue,)
441         print '        %s = (%s)%s("%s");' % (pvalue, ptype, get_proc_address, function.name)
442         print '        if (!%s) {' % (pvalue,)
443         self.fail_function(function)
444         print '        }'
445         print '    }'
446
447     def fail_function(self, function):
448         print '    std::cerr << "error: unavailable function \\"%s\\"\\n";' % function.name
449         if function.fail is not None:
450             if function.type is stdapi.Void:
451                 assert function.fail == ''
452                 print '            return;' 
453             else:
454                 assert function.fail != ''
455                 print '            return %s;' % function.fail
456         else:
457             print '            abort();'
458
459
460 if __name__ == '__main__':
461     print
462     print '#include "glimports.hpp"'
463     print '#include "os.hpp"'
464     print
465     if 0:
466         print 'typedef void (*__PROC)(void);'
467         print
468         print 'static __PROC __getProcAddress(const char *name);'
469         print
470         print 'static __PROC __glGetProcAddress(const char *name);'
471     else:
472         print '#ifdef WIN32'
473         print '#define __glGetProcAddress wglGetProcAddress'
474         print '#else'
475         print '#define __glGetProcAddress(name) glXGetProcAddress((const GLubyte *)(name))'
476         print '#endif'
477     print
478     dispatcher = Dispatcher()
479     for function in glapi.functions:
480         dispatcher.dispatch_function(function)
481     print
482     if 0:
483         print '''
484
485 #ifdef WIN32
486
487 static HINSTANCE g_hDll = NULL;
488
489 static __PROC
490 __getProcAddress(const char *name)
491 {
492     if (!g_hDll) {
493         char szDll[MAX_PATH] = {0};
494         
495         if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
496             return NULL;
497         }
498         
499         strcat(szDll, "\\\\opengl32.dll");
500         
501         g_hDll = LoadLibraryA(szDll);
502         if (!g_hDll) {
503             return NULL;
504         }
505     }
506         
507     return GetProcAddress(g_hDll, name);
508 }
509
510 static inline __PROC
511 __glGetProcAddress(const char *name) {
512     return __wglGetProcAddress(name);
513 }
514
515 #else
516
517 static void g_module = NULL;
518
519 static __PROC
520 __getProcAddress(const char *name)
521 {
522     if (!g_module) {
523         g_module = dlopen("libGL.so", RTLD_LAZY);
524         if (!g_module) {
525             return NULL;
526         }
527     }
528         
529     return (__PROC)dlsym(g_module, name);
530 }
531
532 static inline __PROC
533 __glGetProcAddress(const char *name) {
534     return __glXGetProcAddress(name);
535 }
536
537 #endif
538
539     '''