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 ##########################################################################/
27 """Generated an header, glproc.hpp, which does pretty much what GLEW does, but
28 covers all the functions we support.
33 from glapi import glapi
34 from glxapi import glxapi
35 from wglapi import wglapi
38 public_symbols = set([
41 "glAreTexturesResident",
94 "glCopyTexSubImage1D",
95 "glCopyTexSubImage2D",
104 "glDisableClientState",
113 "glEnableClientState",
156 "glGetPolygonStipple",
164 "glGetTexLevelParameterfv",
165 "glGetTexLevelParameteriv",
166 "glGetTexParameterfv",
167 "glGetTexParameteriv",
182 "glInterleavedArrays",
247 "glPrioritizeTextures",
249 "glPushClientAttrib",
376 "wglChoosePixelFormat",
379 "wglCreateLayerContext",
381 "wglDescribeLayerPlane",
382 "wglDescribePixelFormat",
383 "wglGetCurrentContext",
385 "wglGetDefaultProcAddress",
386 "wglGetLayerPaletteEntries",
390 "wglRealizeLayerPalette",
391 "wglSetLayerPaletteEntries",
395 "wglSwapLayerBuffers",
396 "wglSwapMultipleBuffers",
397 "wglUseFontBitmapsA",
398 "wglUseFontBitmapsW",
399 "wglUseFontOutlinesA",
400 "wglUseFontOutlinesW",
406 def function_pointer_type(self, function):
407 return '__PFN' + function.name.upper()
409 def function_pointer_value(self, function):
410 return '__' + function.name + '_ptr'
412 def dispatch_function(self, function):
413 if function.name in public_symbols:
416 ptype = self.function_pointer_type(function)
417 pvalue = self.function_pointer_value(function)
418 print 'typedef ' + function.prototype('* %s' % ptype) + ';'
419 print 'static %s %s = NULL;' % (ptype, pvalue)
421 print 'static inline ' + function.prototype('__' + function.name) + ' {'
422 if function.type is stdapi.Void:
426 self.get_true_pointer(function)
427 pvalue = self.function_pointer_value(function)
428 print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args]))
431 print '#define %s __%s' % (function.name, function.name)
433 def get_true_pointer(self, function):
434 ptype = self.function_pointer_type(function)
435 pvalue = self.function_pointer_value(function)
436 if function.name in public_symbols:
437 get_proc_address = '__getProcAddress'
439 get_proc_address = '__glGetProcAddress'
440 print ' if (!%s) {' % (pvalue,)
441 print ' %s = (%s)%s("%s");' % (pvalue, ptype, get_proc_address, function.name)
442 print ' if (!%s) {' % (pvalue,)
443 self.fail_function(function)
447 def fail_function(self, function):
448 print ' std::cerr << "error: unavailable function \\"%s\\"\\n";' % function.name
449 if function.fail is not None:
450 if function.type is stdapi.Void:
451 assert function.fail == ''
454 assert function.fail != ''
455 print ' return %s;' % function.fail
460 if __name__ == '__main__':
462 print '#include "glimports.hpp"'
463 print '#include "os.hpp"'
466 print 'typedef void (*__PROC)(void);'
468 print 'static __PROC __getProcAddress(const char *name);'
470 print 'static __PROC __glGetProcAddress(const char *name);'
473 print '#define __glGetProcAddress wglGetProcAddress'
475 print '#define __glGetProcAddress(name) glXGetProcAddress((const GLubyte *)(name))'
478 dispatcher = Dispatcher()
479 for function in glapi.functions:
480 dispatcher.dispatch_function(function)
487 static HINSTANCE g_hDll = NULL;
490 __getProcAddress(const char *name)
493 char szDll[MAX_PATH] = {0};
495 if (!GetSystemDirectoryA(szDll, MAX_PATH)) {
499 strcat(szDll, "\\\\opengl32.dll");
501 g_hDll = LoadLibraryA(szDll);
507 return GetProcAddress(g_hDll, name);
511 __glGetProcAddress(const char *name) {
512 return __wglGetProcAddress(name);
517 static void g_module = NULL;
520 __getProcAddress(const char *name)
523 g_module = dlopen("libGL.so", RTLD_LAZY);
529 return (__PROC)dlsym(g_module, name);
533 __glGetProcAddress(const char *name) {
534 return __glXGetProcAddress(name);