3 # Copyright 2010 VMware, Inc.
4 # Copyright 2004, 2005 IBM Corporation
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the "Software"),
9 # to deal in the Software without restriction, including without limitation
10 # on the rights to use, copy, modify, merge, publish, distribute, sub
11 # license, and/or sell copies of the Software, and to permit persons to whom
12 # the Software is furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice (including the next
15 # paragraph) shall be included in all copies or substantial portions of the
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 # THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 # Jose Fonseca <jfonseca@vmware.com>
28 # Ian Romanick <idr@us.ibm.com>
33 glapi_path = os.path.join(os.environ['MESA'], 'src/mapi/glapi/gen')
34 sys.path.insert(0, glapi_path)
36 import gl_XML, glX_XML
38 import getopt, copy, string
41 class glx_enum_function:
42 def __init__(self, func_name, enum_dict):
47 # "enums" is a set of lists. The element in the set is the
48 # value of the enum. The list is the list of names for that
49 # value. For example, [0x8126] = {"POINT_SIZE_MIN",
50 # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT",
51 # "POINT_SIZE_MIN_SGIS"}.
55 # "count" is indexed by count values. Each element of count
56 # is a list of index to "enums" that have that number of
57 # associated data elements. For example, [4] =
58 # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
59 # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here,
60 # but the actual hexadecimal values would be in the array).
65 # Fill self.count and self.enums using the dictionary of enums
66 # that was passed in. The generic Get functions (e.g.,
67 # GetBooleanv and friends) are handled specially here. In
68 # the data the generic Get functions are refered to as "Get".
70 if func_name in ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev"]:
73 match_name = func_name
76 for enum_name in enum_dict:
77 e = enum_dict[ enum_name ]
79 if e.functions.has_key( match_name ):
80 [count, mode] = e.functions[ match_name ]
82 if mode_set and mode != self.mode:
83 raise RuntimeError("Not all enums for %s have the same mode." % (func_name))
87 if self.enums.has_key( e.value ):
88 if e.name not in self.enums[ e.value ]:
89 self.enums[ e.value ].append( e )
91 if not self.count.has_key( count ):
92 self.count[ count ] = []
94 self.enums[ e.value ] = [ e ]
95 self.count[ count ].append( e.value )
101 def signature( self ):
106 raise RuntimeError("i is None. WTF?")
109 for e in self.count[i]:
110 self.sig += "%04x,%d," % (e, i)
115 def PrintUsingSwitch(self, name):
116 """Emit the body of the __gl*_size function using a
119 print ' switch (pname) {'
122 for e in self.count[c]:
125 # There may be multiple enums with the same
126 # value. This happens has extensions are
127 # promoted from vendor-specific or EXT to
128 # ARB and to the core. Emit the first one as
129 # a case label, and emit the others as
130 # commented-out case labels.
133 for enum_obj in self.enums[e]:
134 list[ enum_obj.priority() ] = enum_obj.name
141 print ' case GL_%s:' % (j)
144 print '/* case GL_%s:*/' % (j)
147 print ' return __gl%s_variable_size(pname);' % (name)
149 print ' return %u;' % (c)
152 print ' OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\\n", __FUNCTION__, pname);'
157 def Print(self, name):
158 print 'static inline size_t'
159 print '__gl%s_size(GLenum pname)' % (name)
162 self.PrintUsingSwitch(name)
168 class glx_server_enum_function(glx_enum_function):
169 def __init__(self, func, enum_dict):
170 glx_enum_function.__init__(self, func.name, enum_dict)
176 def signature( self ):
178 sig = glx_enum_function.signature(self)
180 p = self.function.variable_length_parameter()
182 sig += "%u" % (p.size())
189 def Print(self, name, printer):
191 printer.common_func_print_just_header( f )
196 for param_name in f.count_parameter_list:
197 o = f.offset_of( param_name )
200 for param_name in f.counter_list:
201 o = f.offset_of( param_name )
207 p = f.parameters_by_name[ foo[o] ]
209 printer.common_emit_one_arg(p, "pc", 0)
210 fixup.append( p.name )
213 print ' GLsizei compsize;'
216 printer.common_emit_fixups(fixup)
219 print ' compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ","))
220 p = f.variable_length_parameter()
221 print ' return __GLX_PAD(%s);' % (p.size_string())
227 class PrintGlxSizeStubs_c(gl_XML.gl_print_base):
230 gl_XML.gl_print_base.__init__(self)
232 self.name = "glX_proto_size.py (from Mesa)"
233 self.license = license.bsd_license_template % ( "Copyright 2010 VMware, Inc.\nCopyright 2004 IBM Corporation", "AUTHORS")
235 def printRealHeader(self):
238 print '#include <cassert>'
240 print '#include "glimports.hpp"'
244 def printBody(self, api):
247 for func in api.functionIterateByOffset():
248 ef = glx_enum_function( func.name, api.enums_by_name )
249 if len(ef.enums) == 0:
254 if enum_sigs.has_key( sig ):
255 alias_name, real_name = func.name, enum_sigs[ sig ]
256 print '#define __gl%s_size __gl%s_size' % (alias_name, real_name)
259 enum_sigs[ sig ] = func.name
260 ef.Print( func.name )
264 print "Usage: %s [-f input_file_name] [--only-get | --only-set] [--get-alias-set]" % sys.argv[0]
268 if __name__ == '__main__':
269 file_name = os.path.join(glapi_path, "gl_API.xml")
272 (args, trail) = getopt.getopt(sys.argv[1:], "f:h:", ["header-tag"])
278 for (arg,val) in args:
281 elif (arg == '-h') or (arg == "--header-tag"):
284 printer = PrintGlxSizeStubs_c()
286 api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )