blob: 11da692dda9c3a9f6e11e1e678f4c47a0e55b4e0 [file] [log] [blame]
José Fonseca7ad40262009-09-30 17:17:12 +01001##########################################################################
José Fonseca36e25aa2009-04-13 14:08:08 +01002#
José Fonseca7ad40262009-09-30 17:17:12 +01003# Copyright 2008-2009 VMware, Inc.
4# All Rights Reserved.
José Fonseca36e25aa2009-04-13 14:08:08 +01005#
José Fonseca7ad40262009-09-30 17:17:12 +01006# 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:
José Fonseca36e25aa2009-04-13 14:08:08 +010012#
José Fonseca7ad40262009-09-30 17:17:12 +010013# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
José Fonseca36e25aa2009-04-13 14:08:08 +010015#
José Fonseca7ad40262009-09-30 17:17:12 +010016# 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.
José Fonseca36e25aa2009-04-13 14:08:08 +010023#
José Fonseca7ad40262009-09-30 17:17:12 +010024##########################################################################/
José Fonseca36e25aa2009-04-13 14:08:08 +010025
José Fonseca36e25aa2009-04-13 14:08:08 +010026
José Fonseca8fbdd3a2010-11-23 20:55:07 +000027from wglapi import wglapi
28from trace import Tracer
José Fonseca36e25aa2009-04-13 14:08:08 +010029
José Fonseca36e25aa2009-04-13 14:08:08 +010030
José Fonseca8fbdd3a2010-11-23 20:55:07 +000031public_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",
José Fonseca0fae9702009-04-30 12:42:36 +0100394])
395
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000396class WglTracer(Tracer):
José Fonseca36e25aa2009-04-13 14:08:08 +0100397
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000398 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)'
José Fonsecaf2efcea2010-11-26 11:35:54 +0000406 print ' Trace::Abort();'
José Fonseca355a8fa2009-05-04 22:34:38 +0100407 print ' }'
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000408 return 'pwglGetProcAddress("%s")' % (function.name,)
José Fonsecac77023d2009-05-04 12:53:50 +0100409
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000410 def wrap_ret(self, function, instance):
411 if function.name == "wglGetProcAddress":
412 print ' if (%s) {' % instance
José Fonseca76819862010-11-25 19:06:00 +0000413 else_ = ''
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000414 for f in wglapi.functions:
415 ptype = self.function_pointer_type(f)
416 pvalue = self.function_pointer_value(f)
José Fonseca76819862010-11-25 19:06:00 +0000417 print ' %sif (!strcmp("%s", lpszProc)) {' % (else_, f.name)
José Fonsecaf8f6e452010-11-23 21:35:30 +0000418 print ' %s = (%s)%s;' % (pvalue, ptype, instance)
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000419 print ' %s = (%s)&%s;' % (instance, function.type, f.name);
420 print ' }'
José Fonseca76819862010-11-25 19:06:00 +0000421 else_ = 'else '
422 print ' %s{' % (else_,)
423 print ' OS::DebugMessage("apitrace: unknown function \\"%s\\"\\n", lpszProc);'
424 print ' }'
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000425 print ' }'
José Fonsecac77023d2009-05-04 12:53:50 +0100426
José Fonsecac77023d2009-05-04 12:53:50 +0100427
José Fonseca36e25aa2009-04-13 14:08:08 +0100428if __name__ == '__main__':
429 print
430 print '#define _GDI32_'
431 print
José Fonseca89988612010-11-25 12:27:30 +0000432 print '#include "glimports.hpp"'
José Fonseca36e25aa2009-04-13 14:08:08 +0100433 print
José Fonsecaf2efcea2010-11-26 11:35:54 +0000434 print '#include "trace_write.hpp"'
José Fonseca76819862010-11-25 19:06:00 +0000435 print '#include "os.hpp"'
José Fonseca48e37fe2010-11-25 12:15:17 +0000436 print '#include "glsize.hpp"'
José Fonseca36e25aa2009-04-13 14:08:08 +0100437 print
José Fonseca2272ecd2009-05-04 10:24:12 +0100438 print 'extern "C" {'
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000439 print '''
440static HINSTANCE g_hDll = NULL;
441
442static PROC
443__GetProcAddress(LPCSTR lpProcName)
444{
445 if (!g_hDll) {
446 char szDll[MAX_PATH] = {0};
447
448 if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
449 return NULL;
450 }
451
452 strcat(szDll, "\\\\opengl32.dll");
453
454 g_hDll = LoadLibraryA(szDll);
455 if (!g_hDll) {
456 return NULL;
457 }
458 }
459
460 return GetProcAddress(g_hDll, lpProcName);
461}
462
463 '''
464 tracer = WglTracer()
465 tracer.trace_api(wglapi)
José Fonseca2272ecd2009-05-04 10:24:12 +0100466 print
José Fonseca8fbdd3a2010-11-23 20:55:07 +0000467 print '} /* extern "C" */'