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