-#!/usr/bin/env python
# (C) Copyright IBM Corporation 2004, 2005
# All Rights Reserved.
# Authors:
# Ian Romanick <idr@us.ibm.com>
+from __future__ import print_function
+
+import argparse
+
import gl_XML, glX_XML
import license
-import sys, getopt
class PrintGlOffsets(gl_XML.gl_print_base):
def __init__(self, es=False):
silence = ''
space = ''
- for p in f.parameterIterator():
+ for p in f.parameterIterator(name):
if p.is_padding:
continue
if (cat.startswith("es") or cat.startswith("GL_OES")):
need_proto = True
if need_proto:
- print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name))
- print ''
+ print('%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name)))
+ print('')
- print '%s %s KEYWORD2 NAME(%s)(%s)' % (keyword, f.return_type, n, f.get_parameter_string(name))
- print '{'
+ print('%s %s KEYWORD2 NAME(%s)(%s)' % (keyword, f.return_type, n, f.get_parameter_string(name)))
+ print('{')
if silence:
- print ' %s' % (silence)
+ print(' %s' % (silence))
if p_string == "":
- print ' %s(%s, (), (F, "gl%s();\\n"));' \
- % (dispatch, f.name, name)
+ print(' %s(%s, (), (F, "gl%s();\\n"));' \
+ % (dispatch, f.name, name))
else:
- print ' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \
- % (dispatch, f.name, p_string, name, t_string, o_string)
- print '}'
- print ''
+ print(' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \
+ % (dispatch, f.name, p_string, name, t_string, o_string))
+ print('}')
+ print('')
return
def printRealHeader(self):
- print ''
+ print('')
self.printVisibility( "HIDDEN", "hidden" )
- print """
+ print("""
/*
* This file is a template which generates the OpenGL API entry point
* functions. It should be included by a .c file which first defines
* #define KEYWORD1
* #define KEYWORD2
* #define NAME(func) gl##func
- * #define DISPATCH(func, args, msg) \\
- * struct _glapi_table *dispatch = CurrentDispatch; \\
+ * #define DISPATCH(func, args, msg) \\
+ * struct _glapi_table *dispatch = CurrentClientDispatch; \\
* (*dispatch->func) args
- * #define RETURN DISPATCH(func, args, msg) \\
- * struct _glapi_table *dispatch = CurrentDispatch; \\
+ * #define RETURN DISPATCH(func, args, msg) \\
+ * struct _glapi_table *dispatch = CurrentClientDispatch; \\
* return (*dispatch->func) args
*
*/
#error RETURN_DISPATCH must be defined
#endif
-"""
+""")
return
def printInitDispatch(self, api):
- print """
+ print("""
#endif /* defined( NAME ) */
/*
#error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined
#endif
-_glapi_proc DISPATCH_TABLE_NAME[] = {"""
+_glapi_proc DISPATCH_TABLE_NAME[] = {""")
for f in api.functionIterateByOffset():
- print ' TABLE_ENTRY(%s),' % (f.dispatch_name())
+ print(' TABLE_ENTRY(%s),' % (f.dispatch_name()))
- print ' /* A whole bunch of no-op functions. These might be called'
- print ' * when someone tries to call a dynamically-registered'
- print ' * extension function without a current rendering context.'
- print ' */'
+ print(' /* A whole bunch of no-op functions. These might be called')
+ print(' * when someone tries to call a dynamically-registered')
+ print(' * extension function without a current rendering context.')
+ print(' */')
for i in range(1, 100):
- print ' TABLE_ENTRY(Unused),'
+ print(' TABLE_ENTRY(Unused),')
- print '};'
- print '#endif /* DISPATCH_TABLE_NAME */'
- print ''
+ print('};')
+ print('#endif /* DISPATCH_TABLE_NAME */')
+ print('')
return
def printAliasedTable(self, api):
- print """
+ print("""
/*
* This is just used to silence compiler warnings.
* We list the functions which are not otherwise used.
*/
#ifdef UNUSED_TABLE_NAME
-_glapi_proc UNUSED_TABLE_NAME[] = {"""
+_glapi_proc UNUSED_TABLE_NAME[] = {""")
normal_entries = []
proto_entries = []
normal_entries.extend(normal_ents)
proto_entries.extend(proto_ents)
- print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS'
+ print('#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS')
for ent in normal_entries:
- print ' TABLE_ENTRY(%s),' % (ent)
- print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */'
- print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS'
+ print(' TABLE_ENTRY(%s),' % (ent))
+ print('#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */')
+ print('#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS')
for ent in proto_entries:
- print ' TABLE_ENTRY(%s),' % (ent)
- print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */'
+ print(' TABLE_ENTRY(%s),' % (ent))
+ print('#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */')
- print '};'
- print '#endif /*UNUSED_TABLE_NAME*/'
- print ''
+ print('};')
+ print('#endif /*UNUSED_TABLE_NAME*/')
+ print('')
return
normal_entry_points.append((func, normal_ents))
proto_entry_points.append((func, proto_ents))
- print '#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS'
- print ''
+ print('#ifndef _GLAPI_SKIP_NORMAL_ENTRY_POINTS')
+ print('')
for func, ents in normal_entry_points:
for ent in ents:
self.printFunction(func, ent)
- print ''
- print '#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */'
- print ''
- print '/* these entry points might require different protocols */'
- print '#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS'
- print ''
+ print('')
+ print('#endif /* _GLAPI_SKIP_NORMAL_ENTRY_POINTS */')
+ print('')
+ print('/* these entry points might require different protocols */')
+ print('#ifndef _GLAPI_SKIP_PROTO_ENTRY_POINTS')
+ print('')
for func, ents in proto_entry_points:
for ent in ents:
self.printFunction(func, ent)
- print ''
- print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */'
- print ''
+ print('')
+ print('#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */')
+ print('')
self.printInitDispatch(api)
self.printAliasedTable(api)
return
-def show_usage():
- print "Usage: %s [-f input_file_name] [-c]" % sys.argv[0]
- print "-c Enable compatibility with OpenGL ES."
- sys.exit(1)
-
-if __name__ == '__main__':
- file_name = "gl_API.xml"
+def _parser():
+ """Parser arguments and return a namespace."""
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-f',
+ metavar='<input file name>',
+ dest='filename',
+ default="gl_API.xml",
+ help="An XML file describing the API.")
+ parser.add_argument('-c',
+ action='store_true',
+ dest='es',
+ help="Enable OpenGL ES compatibility")
+ return parser.parse_args()
- try:
- (args, trail) = getopt.getopt(sys.argv[1:], "f:c")
- except Exception,e:
- show_usage()
- es = False
- for (arg,val) in args:
- if arg == "-f":
- file_name = val
- elif arg == "-c":
- es = True
+def main():
+ """Main function."""
+ args = _parser()
- api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory())
+ api = gl_XML.parse_GL_API(args.filename, glX_XML.glx_item_factory())
- printer = PrintGlOffsets(es)
+ printer = PrintGlOffsets(args.es)
printer.Print(api)
+
+
+if __name__ == '__main__':
+ main()