3 # (C) Copyright IBM Corporation 2004, 2005
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 # Ian Romanick <idr@us.ibm.com>
29 import gl_XML
, glX_XML
32 class PrintGlProcs(gl_XML
.gl_print_base
):
33 def __init__(self
, long_strings
):
34 gl_XML
.gl_print_base
.__init
__(self
)
36 self
.long_strings
= long_strings
37 self
.name
= "gl_procs.py (from Mesa)"
38 self
.license
= license
.bsd_license_template
% ( \
39 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
40 (C) Copyright IBM Corporation 2004, 2006""", "BRIAN PAUL, IBM")
43 def printRealHeader(self
):
45 /* This file is only included by glapi.c and is used for
46 * the GetProcAddress() function
51 #if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)
57 #if !defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING)
58 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , o }
59 #elif defined(NEED_FUNCTION_POINTER) && !defined(GLX_INDIRECT_RENDERING)
60 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f1 , o }
61 #elif defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING)
62 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f2 , o }
63 #elif !defined(NEED_FUNCTION_POINTER) && defined(GLX_INDIRECT_RENDERING)
64 # define NAME_FUNC_OFFSET(n,f1,f2,f3,o) { n , (_glapi_proc) f3 , o }
70 def printRealFooter(self
):
72 print '#undef NAME_FUNC_OFFSET'
75 def printFunctionString(self
, name
):
77 print ' "gl%s\\0"' % (name
)
86 def printBody(self
, api
):
89 print 'static const char gl_string_table[] ='
91 print 'static const char gl_string_table[] = {'
95 for func
in api
.functionIterateByOffset():
96 name
= func
.dispatch_name()
97 self
.printFunctionString(func
.name
)
98 table
.append((base_offset
, "gl" + name
, "gl" + name
, "NULL", func
.name
))
100 # The length of the function's name, plus 2 for "gl",
101 # plus 1 for the NUL.
103 base_offset
+= len(func
.name
) + 3
106 for func
in api
.functionIterateByOffset():
107 for n
in func
.entry_points
:
109 name
= func
.dispatch_name()
110 self
.printFunctionString( n
)
112 if func
.has_different_protocol(n
):
113 alt_name
= "gl" + func
.static_glx_name(n
)
114 table
.append((base_offset
, "gl" + name
, alt_name
, alt_name
, func
.name
))
116 table
.append((base_offset
, "gl" + name
, "gl" + name
, "NULL", func
.name
))
118 base_offset
+= len(n
) + 3
121 if self
.long_strings
:
128 print "#ifdef USE_MGL_NAMESPACE"
129 for func
in api
.functionIterateByOffset():
130 for n
in func
.entry_points
:
131 if (not func
.is_static_entry_point(func
.name
)) or (func
.has_different_protocol(n
) and not func
.is_static_entry_point(n
)):
132 print '#define gl_dispatch_stub_%u mgl_dispatch_stub_%u' % (func
.offset
, func
.offset
)
134 print "#endif /* USE_MGL_NAMESPACE */"
137 print '#if defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING)'
138 for func
in api
.functionIterateByOffset():
139 for n
in func
.entry_points
:
140 if (not func
.is_static_entry_point(func
.name
)) or (func
.has_different_protocol(n
) and not func
.is_static_entry_point(n
)):
141 print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func
.return_type
, func
.offset
, func
.get_parameter_string())
144 print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */'
147 print 'static const glprocs_table_t static_functions[] = {'
150 print ' NAME_FUNC_OFFSET(%5u, %s, %s, %s, _gloffset_%s),' % info
152 print ' NAME_FUNC_OFFSET(-1, NULL, NULL, NULL, 0)'
158 print "Usage: %s [-f input_file_name] [-m mode]" % sys
.argv
[0]
159 print "mode can be one of:"
160 print " long - Create code for compilers that can handle very"
161 print " long string constants. (default)"
162 print " short - Create code for compilers that can only handle"
163 print " ANSI C89 string constants."
166 if __name__
== '__main__':
167 file_name
= "gl_API.xml"
170 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:m:")
175 for (arg
,val
) in args
:
186 api
= gl_XML
.parse_GL_API(file_name
, glX_XML
.glx_item_factory())
187 printer
= PrintGlProcs(long_string
)