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