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;' % (instance, function.type, f.name);
422 if __name__ == '__main__':
424 print '#define _GDI32_'
426 print '#include <windows.h>'
427 print '#include <tchar.h>'
428 print '#include <GL/gl.h>'
429 print '#include "glext.h"'
430 print '#include "wglext.h"'
432 print '#include "log.hpp"'
433 print '#include "glhelpers.hpp"'
435 print '#ifndef PFD_SUPPORT_DIRECTDRAW'
436 print '#define PFD_SUPPORT_DIRECTDRAW 0x00002000'
438 print '#ifndef PFD_SUPPORT_COMPOSITION'
439 print '#define PFD_SUPPORT_COMPOSITION 0x00008000'
442 print '#define GLAPIENTRY __stdcall'
444 print '#ifdef __MINGW32__'
446 print 'typedef struct _WGLSWAP'
449 print ' UINT uiFlags;'
450 print '} WGLSWAP, *PWGLSWAP, FAR *LPWGLSWAP;'
452 print '#define WGL_SWAPMULTIPLE_MAX 16'
458 static HINSTANCE g_hDll = NULL;
461 __GetProcAddress(LPCSTR lpProcName)
464 char szDll[MAX_PATH] = {0};
466 if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
470 strcat(szDll, "\\\\opengl32.dll");
472 g_hDll = LoadLibraryA(szDll);
478 return GetProcAddress(g_hDll, lpProcName);
483 tracer.trace_api(wglapi)
485 print '} /* extern "C" */'