X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=inline;f=glproc.py;h=7c7beb90e072fba7cfc845cd8237139819d442ef;hb=1a9f7af32205d900c88fef0b544546eb0d7c84ee;hp=f3dc3d2e95a64bce65b8b704457e1a83aa21365c;hpb=68ec4122ceae159709f74ace0eb862595ed68d8a;p=apitrace diff --git a/glproc.py b/glproc.py index f3dc3d2..7c7beb9 100644 --- a/glproc.py +++ b/glproc.py @@ -30,9 +30,11 @@ covers all the functions we support. import stdapi +from dispatch import Dispatcher from glapi import glapi from glxapi import glxapi from wglapi import wglapi +from cglapi import cglapi # See http://www.opengl.org/registry/ABI/ @@ -405,182 +407,62 @@ public_symbols = set([ ]) -class Dispatcher: - - def header(self): - pass - #print 'typedef void (*__PROC)(void);' - #print - #print 'static __PROC __getPublicProcAddress(const char *name);' - #print 'static __PROC __getPrivateProcAddress(const char *name);' - #print - - def dispatch_api(self, api): - for function in api.functions: - dispatcher.dispatch_function(function) - - print '#ifdef RETRACE' - for function in api.functions: - if not self.is_public_function(function): - print '#define %s __%s' % (function.name, function.name) - print '#endif /* RETRACE */' - print - - def function_pointer_type(self, function): - return '__PFN' + function.name.upper() - - def function_pointer_value(self, function): - return '__' + function.name + '_ptr' - - def dispatch_function(self, function): - if self.is_public_function(function): - print '#ifndef RETRACE' - print - ptype = self.function_pointer_type(function) - pvalue = self.function_pointer_value(function) - print 'typedef ' + function.prototype('* %s' % ptype) + ';' - print 'static %s %s = NULL;' % (ptype, pvalue) - print - print 'static inline ' + function.prototype('__' + function.name) + ' {' - if function.type is stdapi.Void: - ret = '' - else: - ret = 'return ' - self.get_true_pointer(function) - pvalue = self.function_pointer_value(function) - print ' %s%s(%s);' % (ret, pvalue, ', '.join([str(arg.name) for arg in function.args])) - print '}' - print - if self.is_public_function(function): - print '#endif /* !RETRACE */' - print - - def is_public_function(self, function): - return True - - def get_true_pointer(self, function): - ptype = self.function_pointer_type(function) - pvalue = self.function_pointer_value(function) - if self.is_public_function(function): - get_proc_address = '__getPublicProcAddress' - else: - get_proc_address = '__getPrivateProcAddress' - print ' if (!%s) {' % (pvalue,) - print ' %s = (%s)%s("%s");' % (pvalue, ptype, get_proc_address, function.name) - print ' if (!%s) {' % (pvalue,) - self.fail_function(function) - print ' }' - print ' }' - - def fail_function(self, function): - print ' OS::DebugMessage("error: unavailable function \\"%s\\"\\n");' % function.name - if function.fail is not None: - if function.type is stdapi.Void: - assert function.fail == '' - print ' return;' - else: - assert function.fail != '' - print ' return %s;' % function.fail - else: - print ' __abort();' - - class GlDispatcher(Dispatcher): def header(self): - Dispatcher.header(self) print '#ifdef RETRACE' - print '# ifdef WIN32' + print '# if defined(_WIN32)' print '# define __getPrivateProcAddress(name) wglGetProcAddress(name)' + print '# elif defined(__APPLE__)' + print '# include ' + print '# define __getPrivateProcAddress(name) dlsym(RTLD_DEFAULT, name)' print '# else' print '# define __getPrivateProcAddress(name) glXGetProcAddressARB((const GLubyte *)(name))' print '# endif' - print '# define __abort() OS::Abort()' print '#else /* !RETRACE */' - print '# ifdef WIN32' + print '# ifdef _WIN32' + print ' PROC __getPublicProcAddress(LPCSTR lpProcName);' print '# define __getPrivateProcAddress(name) __wglGetProcAddress(name)' print ' static inline PROC __stdcall __wglGetProcAddress(const char * lpszProc);' print '# else' - print '# define __getPublicProcAddress(name) dlsym(RTLD_NEXT, name)' - print '# define __getPrivateProcAddress(name) __glXGetProcAddressARB((const GLubyte *)(name))' - print ' static inline __GLXextFuncPtr __glXGetProcAddressARB(const GLubyte * procName);' + print '# define __getPublicProcAddress(name) __libgl_sym(name)' + print ' void * __libgl_sym(const char *symbol);' + print '# ifdef __APPLE__' + print '# define __getPrivateProcAddress(name) __getPublicProcAddress(name)' + print '# else' + print '# define __getPrivateProcAddress(name) __glXGetProcAddressARB((const GLubyte *)(name))' + print ' static inline __GLXextFuncPtr __glXGetProcAddressARB(const GLubyte * procName);' + print '# endif' print '# endif' - print '# define __abort() Trace::Abort()' print '#endif /* !RETRACE */' print def is_public_function(self, function): - return function.name in public_symbols + return function.name in public_symbols or function.name.startswith('CGL') if __name__ == '__main__': print + print '#ifndef _GLPROC_HPP_' + print '#define _GLPROC_HPP_' + print print '#include "glimports.hpp"' print '#include "os.hpp"' print print dispatcher = GlDispatcher() dispatcher.header() - print '#ifdef WIN32' + print '#if defined(_WIN32)' print dispatcher.dispatch_api(wglapi) - print '#else /* !WIN32 */' + print '#elif defined(__APPLE__)' + dispatcher.dispatch_api(cglapi) + print '#else' print dispatcher.dispatch_api(glxapi) - print '#endif /* !WIN32 */' + print '#endif' print dispatcher.dispatch_api(glapi) print - if 0: - print ''' - -#ifdef WIN32 - -static HINSTANCE g_hDll = NULL; - -static __PROC -__getProcAddress(const char *name) -{ - if (!g_hDll) { - char szDll[MAX_PATH] = {0}; - - if (!GetSystemDirectoryA(szDll, MAX_PATH)) { - return NULL; - } - - strcat(szDll, "\\\\opengl32.dll"); - - g_hDll = LoadLibraryA(szDll); - if (!g_hDll) { - return NULL; - } - } - - return GetProcAddress(g_hDll, name); -} - -#else - -static void g_module = NULL; - -static __PROC -__getProcAddress(const char *name) -{ - if (!g_module) { - g_module = dlopen("libGL.so", RTLD_LAZY); - if (!g_module) { - return NULL; - } - } - - return (__PROC)dlsym(g_module, name); -} - -static inline __PROC -__glGetProcAddress(const char *name) { - return __glXGetProcAddressARB(name); -} - -#endif - - ''' + print '#endif /* !_GLPROC_HPP_ */' + print