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