1 ##########################################################################
3 # Copyright 2010 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 ##########################################################################/
28 from glapi import glapi
29 from glxapi import glxapi
30 from wglapi import wglapi
33 public_symbols = set([
36 "glAreTexturesResident",
89 "glCopyTexSubImage1D",
90 "glCopyTexSubImage2D",
99 "glDisableClientState",
108 "glEnableClientState",
151 "glGetPolygonStipple",
159 "glGetTexLevelParameterfv",
160 "glGetTexLevelParameteriv",
161 "glGetTexParameterfv",
162 "glGetTexParameteriv",
177 "glInterleavedArrays",
242 "glPrioritizeTextures",
244 "glPushClientAttrib",
371 "wglChoosePixelFormat",
374 "wglCreateLayerContext",
376 "wglDescribeLayerPlane",
377 "wglDescribePixelFormat",
378 "wglGetCurrentContext",
380 "wglGetDefaultProcAddress",
381 "wglGetLayerPaletteEntries",
385 "wglRealizeLayerPalette",
386 "wglSetLayerPaletteEntries",
390 "wglSwapLayerBuffers",
391 "wglSwapMultipleBuffers",
392 "wglUseFontBitmapsA",
393 "wglUseFontBitmapsW",
394 "wglUseFontOutlinesA",
395 "wglUseFontOutlinesW",
401 def function_pointer_type(self, function):
402 return '__PFN' + function.name.upper()
404 def function_pointer_value(self, function):
405 return '__' + function.name + '_ptr'
407 def dispatch_function(self, function):
408 if function.name in public_symbols:
411 ptype = self.function_pointer_type(function)
412 pvalue = self.function_pointer_value(function)
413 print 'typedef ' + function.prototype('* %s' % ptype) + ';'
414 print 'static %s %s = NULL;' % (ptype, pvalue)
416 print 'static inline ' + function.prototype('__' + function.name) + ' {'
417 if function.type is stdapi.Void:
421 self.get_true_pointer(function)
422 pvalue = self.function_pointer_value(function)
423 print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args]))
426 print '#define %s __%s' % (function.name, function.name)
428 def get_true_pointer(self, function):
429 ptype = self.function_pointer_type(function)
430 pvalue = self.function_pointer_value(function)
431 if function.name in public_symbols:
432 get_proc_address = '__getProcAddress'
434 get_proc_address = '__glGetProcAddress'
435 print ' if (!%s) {' % (pvalue,)
436 print ' %s = (%s)%s("%s");' % (pvalue, ptype, get_proc_address, function.name)
437 print ' if (!%s) {' % (pvalue,)
438 self.fail_function(function)
442 def fail_function(self, function):
443 print ' std::cerr << "error: unavailable function \\"%s\\"\\n";' % function.name
444 if function.fail is not None:
445 if function.type is stdapi.Void:
446 assert function.fail == ''
449 assert function.fail != ''
450 print ' return %s;' % function.fail
455 if __name__ == '__main__':
457 print '#include "glimports.hpp"'
458 print '#include "os.hpp"'
461 print 'typedef void (*__PROC)(void);'
463 print 'static __PROC __getProcAddress(const char *name);'
465 print 'static __PROC __glGetProcAddress(const char *name);'
468 print '#define __glGetProcAddress wglGetProcAddress'
470 print '#define __glGetProcAddress(name) glXGetProcAddress((const GLubyte *)(name))'
473 dispatcher = Dispatcher()
474 for function in glapi.functions:
475 dispatcher.dispatch_function(function)
482 static HINSTANCE g_hDll = NULL;
485 __getProcAddress(const char *name)
488 char szDll[MAX_PATH] = {0};
490 if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
494 strcat(szDll, "\\\\opengl32.dll");
496 g_hDll = LoadLibraryA(szDll);
502 return GetProcAddress(g_hDll, name);
506 __glGetProcAddress(const char *name) {
507 return __wglGetProcAddress(name);
512 static void g_module = NULL;
515 __getProcAddress(const char *name)
518 g_module = dlopen("libGL.so", RTLD_LAZY);
524 return (__PROC)dlsym(g_module, name);
528 __glGetProcAddress(const char *name) {
529 return __glXGetProcAddress(name);