3 # (C) Copyright IBM Corporation 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>
30 import sys, getopt, string
51 "MultiTexCoord1fARB", \
52 "MultiTexCoord1fvARB", \
53 "MultiTexCoord2fARB", \
54 "MultiTexCoord2fvARB", \
55 "MultiTexCoord3fARB", \
56 "MultiTexCoord3fvARB", \
57 "MultiTexCoord4fARB", \
58 "MultiTexCoord4fvARB", \
61 "SecondaryColor3fEXT", \
62 "SecondaryColor3fvEXT", \
82 "VertexAttrib1fvNV", \
84 "VertexAttrib2fvNV", \
86 "VertexAttrib3fvNV", \
88 "VertexAttrib4fvNV", \
89 "VertexAttrib1fARB", \
90 "VertexAttrib1fvARB", \
91 "VertexAttrib2fARB", \
92 "VertexAttrib2fvARB", \
93 "VertexAttrib3fARB", \
94 "VertexAttrib3fvARB", \
95 "VertexAttrib4fARB", \
96 "VertexAttrib4fvARB", \
100 "DrawRangeElements", \
105 def all_entrypoints_in_abi(f, abi, api):
106 for n in f.entry_points:
107 [category, num] = api.get_category_for_name( n )
108 if category not in abi:
114 def any_entrypoints_in_abi(f, abi, api):
115 for n in f.entry_points:
116 [category, num] = api.get_category_for_name( n )
123 def condition_for_function(f, abi, all_not_in_ABI):
124 """Create a C-preprocessor condition for the function.
126 There are two modes of operation. If all_not_in_ABI is set, a
127 condition is only created is all of the entry-point names for f are
128 not in the selected ABI. If all_not_in_ABI is not set, a condition
129 is created if any entryp-point name is not in the selected ABI.
133 for n in f.entry_points:
134 [category, num] = api.get_category_for_name( n )
135 if category not in abi:
136 condition.append( 'defined(need_%s)' % (gl_XML.real_category_name( category )) )
143 class PrintGlExtensionGlue(gl_XML.gl_print_base):
145 gl_XML.gl_print_base.__init__(self)
147 self.name = "extension_helper.py (from Mesa)"
148 self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
152 def printRealHeader(self):
153 print '#include "utils.h"'
154 print '#include "main/dispatch.h"'
159 def printBody(self, api):
160 abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
165 print '# define NULL 0'
169 for f in api.functionIterateAll():
170 condition = condition_for_function(f, abi, 0)
172 print '#if %s' % (string.join(condition, " || "))
173 print 'static const char %s_names[] =' % (f.name)
175 parameter_signature = ''
176 for p in f.parameterIterator():
180 # FIXME: This is a *really* ugly hack. :(
182 tn = p.type_expr.get_base_type_node()
184 parameter_signature += 'p'
186 parameter_signature += 'i'
188 parameter_signature += 'f'
190 parameter_signature += 'd'
192 print ' "%s\\0" /* Parameter signature */' % (parameter_signature)
194 for n in f.entry_points:
195 print ' "gl%s\\0"' % (n)
197 [category, num] = api.get_category_for_name( n )
198 if category not in abi:
199 c = gl_XML.real_category_name(category)
200 if not category_list.has_key(c):
201 category_list[ c ] = []
203 category_list[ c ].append( f )
209 keys = category_list.keys()
212 for category in keys:
213 print '#if defined(need_%s)' % (category)
214 print 'static const struct dri_extension_function %s_functions[] = {' % (category)
216 for f in category_list[ category ]:
217 # A function either has an offset that is
218 # assigned by the ABI, or it has a remap
220 if any_entrypoints_in_abi(f, abi, api):
224 index_name = "%s_remap_index" % (f.name)
227 print ' { %s_names, %s, %d },' % (f.name, index_name, offset)
230 print ' { NULL, 0, 0 }'
238 class PrintInitDispatch(gl_XML.gl_print_base):
240 gl_XML.gl_print_base.__init__(self)
242 self.name = "extension_helper.py (from Mesa)"
243 self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM")
247 def do_function_body(self, api, abi, vtxfmt_only):
248 last_condition_string = None
249 for f in api.functionIterateByOffset():
250 if (f.name in vtxfmt) and not vtxfmt_only:
253 if (f.name not in vtxfmt) and vtxfmt_only:
256 condition = condition_for_function(f, abi, 1)
257 condition_string = string.join(condition, " || ")
259 if condition_string != last_condition_string:
260 if last_condition_string:
261 print '#endif /* %s */' % (last_condition_string)
264 print '#if %s' % (condition_string)
267 print ' disp->%s = vfmt->%s;' % (f.name, f.name)
269 print ' disp->%s = _mesa_%s;' % (f.name, f.name)
271 last_condition_string = condition_string
273 if last_condition_string:
274 print '#endif /* %s */' % (last_condition_string)
278 def printBody(self, api):
279 abi = [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
281 print 'void driver_init_exec_table(struct _glapi_table *disp)'
283 self.do_function_body(api, abi, 0)
286 print 'void driver_install_vtxfmt(struct _glapi_table *disp, const GLvertexformat *vfmt)'
288 self.do_function_body(api, abi, 1)
295 print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
296 print " -m output_mode Output mode can be one of 'extensions' or 'exec_init'."
299 if __name__ == '__main__':
300 file_name = "gl_API.xml"
303 (args, trail) = getopt.getopt(sys.argv[1:], "f:m:")
308 for (arg,val) in args:
315 api = gl_XML.parse_GL_API( file_name )
317 if mode == "extensions":
318 printer = PrintGlExtensionGlue()
319 elif mode == "exec_init":
320 printer = PrintInitDispatch()