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