1 ##########################################################################
3 # Copyright 2008-2009 VMware, Inc.
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:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
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
24 ##########################################################################/
27 from wglapi import wglapi
28 from trace import Tracer
32 public_symbols = set([
35 "glAreTexturesResident",
88 "glCopyTexSubImage1D",
89 "glCopyTexSubImage2D",
98 "glDisableClientState",
107 "glEnableClientState",
150 "glGetPolygonStipple",
158 "glGetTexLevelParameterfv",
159 "glGetTexLevelParameteriv",
160 "glGetTexParameterfv",
161 "glGetTexParameteriv",
176 "glInterleavedArrays",
241 "glPrioritizeTextures",
243 "glPushClientAttrib",
370 "wglChoosePixelFormat",
373 "wglCreateLayerContext",
375 "wglDescribeLayerPlane",
376 "wglDescribePixelFormat",
377 "wglGetCurrentContext",
379 "wglGetDefaultProcAddress",
380 "wglGetLayerPaletteEntries",
384 "wglRealizeLayerPalette",
385 "wglSetLayerPaletteEntries",
389 "wglSwapLayerBuffers",
390 "wglSwapMultipleBuffers",
391 "wglUseFontBitmapsA",
392 "wglUseFontBitmapsW",
393 "wglUseFontOutlinesA",
394 "wglUseFontOutlinesW",
397 class WglTracer(Tracer):
399 def get_function_address(self, function):
400 #print 'DebugBreak();'
401 if function.name in public_symbols:
402 return '__GetProcAddress("%s")' % (function.name,)
404 print ' if (!pwglGetProcAddress) {'
405 print ' pwglGetProcAddress = (PwglGetProcAddress)__GetProcAddress("wglGetProcAddress");'
406 print ' if (!pwglGetProcAddress)'
407 print ' Trace::Abort();'
409 return 'pwglGetProcAddress("%s")' % (function.name,)
411 def wrap_ret(self, function, instance):
412 if function.name == "wglGetProcAddress":
413 print ' if (%s) {' % instance
415 func_dict = dict([(f.name, f) for f in wglapi.functions])
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);
424 def handle_default():
425 print ' OS::DebugMessage("apitrace: unknown function \\"%s\\"\\n", lpszProc);'
427 string_switch('lpszProc', func_dict.keys(), handle_case, handle_default)
431 if __name__ == '__main__':
433 print '#define _GDI32_'
435 print '#include "glimports.hpp"'
437 print '#include "trace_write.hpp"'
438 print '#include "os.hpp"'
439 print '#include "glsize.hpp"'
443 static HINSTANCE g_hDll = NULL;
446 __GetProcAddress(LPCSTR lpProcName)
449 char szDll[MAX_PATH] = {0};
451 if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
455 strcat(szDll, "\\\\opengl32.dll");
457 g_hDll = LoadLibraryA(szDll);
463 return GetProcAddress(g_hDll, lpProcName);
468 tracer.trace_api(wglapi)
470 print '} /* extern "C" */'