]> git.cworth.org Git - apitrace/blob - glx.py
Cleanup generated log code.
[apitrace] / glx.py
1 ##########################################################################
2 #
3 # Copyright 2008-2009 VMware, Inc.
4 # All Rights Reserved.
5 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
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
22 # THE SOFTWARE.
23 #
24 ##########################################################################/
25
26 from gl import *
27 from dl import *
28
29 libgl = Dll("GL")
30 libgl.functions = basic_functions(DllFunction)
31
32
33 class GlxGetProcAddressFunction(DllFunction):
34
35     def __init__(self, type, name, args):
36         DllFunction.__init__(self, type, name, args)
37         self.functions = []
38
39     def wrap_decl(self):
40         for function in self.functions:
41             function.wrap_decl()
42         DllFunction.wrap_decl(self)
43
44     def wrap_impl(self):
45         for function in self.functions:
46             function.wrap_impl()
47         DllFunction.wrap_impl(self)
48
49     def post_call_impl(self):
50         print '    if(result) {'
51         for function in self.functions:
52             ptype = function.pointer_type()
53             pvalue = function.pointer_value()
54             print '        if(!strcmp("%s", (const char *)procName)) {' % function.name
55             print '            %s = (%s)result;' % (pvalue, ptype)
56             print '            result = (void(*)())&%s;' % function.name;
57             print '        }'
58         print '    }'
59
60
61 PROC = Opaque("__GLXextFuncPtr")
62
63 glXgetprocaddress = GlxGetProcAddressFunction(PROC, "glXGetProcAddress", [(Alias("const GLubyte *", String), "procName")])
64 libgl.functions.append(glXgetprocaddress)
65
66 class GlxFunction(Function):
67
68     def __init__(self, type, name, args, call = '', **kwargs):
69         Function.__init__(self, type, name, args, call=call, **kwargs)
70         
71     def get_true_pointer(self):
72         ptype = self.pointer_type()
73         pvalue = self.pointer_value()
74         print '    if(!%s)' % (pvalue,)
75         self.fail_impl()
76
77 glXgetprocaddress.functions += extended_functions(GlxFunction)
78
79
80 if __name__ == '__main__':
81     print
82     print '#include <stdlib.h>'
83     print '#include <string.h>'
84     print '#include <dlfcn.h>'
85     print '#include <X11/Xlib.h>'
86     print '#include <GL/gl.h>'
87     print '#include <GL/glext.h>'
88     print '#include <GL/glx.h>'
89     print '#include <GL/glxext.h>'
90     print
91     print '#include "log.hpp"'
92     print '#include "glhelpers.hpp"'
93     print
94     print 'extern "C" {'
95     print
96     wrap()
97     print
98     print '}'