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
31 public_symbols = set([
34 "glAreTexturesResident",
87 "glCopyTexSubImage1D",
88 "glCopyTexSubImage2D",
97 "glDisableClientState",
106 "glEnableClientState",
149 "glGetPolygonStipple",
157 "glGetTexLevelParameterfv",
158 "glGetTexLevelParameteriv",
159 "glGetTexParameterfv",
160 "glGetTexParameteriv",
175 "glInterleavedArrays",
240 "glPrioritizeTextures",
242 "glPushClientAttrib",
369 "wglChoosePixelFormat",
372 "wglCreateLayerContext",
374 "wglDescribeLayerPlane",
375 "wglDescribePixelFormat",
376 "wglGetCurrentContext",
378 "wglGetDefaultProcAddress",
379 "wglGetLayerPaletteEntries",
383 "wglRealizeLayerPalette",
384 "wglSetLayerPaletteEntries",
388 "wglSwapLayerBuffers",
389 "wglSwapMultipleBuffers",
390 "wglUseFontBitmapsA",
391 "wglUseFontBitmapsW",
392 "wglUseFontOutlinesA",
393 "wglUseFontOutlinesW",
396 class WglTracer(Tracer):
398 def get_function_address(self, function):
399 #print 'DebugBreak();'
400 if function.name in public_symbols:
401 return '__GetProcAddress("%s")' % (function.name,)
403 print ' if (!pwglGetProcAddress) {'
404 print ' pwglGetProcAddress = (PwglGetProcAddress)__GetProcAddress("wglGetProcAddress");'
405 print ' if (!pwglGetProcAddress)'
406 print ' Log::Abort();'
408 return 'pwglGetProcAddress("%s")' % (function.name,)
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);
423 if __name__ == '__main__':
425 print '#define _GDI32_'
427 print '#include "glimports.hpp"'
429 print '#include "log.hpp"'
430 print '#include "glsize.hpp"'
432 print '#ifndef PFD_SUPPORT_DIRECTDRAW'
433 print '#define PFD_SUPPORT_DIRECTDRAW 0x00002000'
435 print '#ifndef PFD_SUPPORT_COMPOSITION'
436 print '#define PFD_SUPPORT_COMPOSITION 0x00008000'
439 print '#define GLAPIENTRY __stdcall'
441 print '#ifdef __MINGW32__'
443 print 'typedef struct _WGLSWAP'
446 print ' UINT uiFlags;'
447 print '} WGLSWAP, *PWGLSWAP, FAR *LPWGLSWAP;'
449 print '#define WGL_SWAPMULTIPLE_MAX 16'
455 static HINSTANCE g_hDll = NULL;
458 __GetProcAddress(LPCSTR lpProcName)
461 char szDll[MAX_PATH] = {0};
463 if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
467 strcat(szDll, "\\\\opengl32.dll");
469 g_hDll = LoadLibraryA(szDll);
475 return GetProcAddress(g_hDll, lpProcName);
480 tracer.trace_api(wglapi)
482 print '} /* extern "C" */'