From 7870298086cfdde020437e23ba86abb61741129e Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sun, 25 Oct 2009 23:24:18 +0800 Subject: glapi: Allow normal entry points to be skipped. Reorganize glapitemp.h such that it is possible to skip normal entry points or protocol entry points by defining _GLAPI_SKIP_NORMAL_ENTRY_POINTS or _GLAPI_SKIP_PROTO_ENTRY_POINTS. Protocol entry points are those with different GLX protocols. They are skipped in libglapi.a when GLX_INDIRECT_RENDERING is defined. Signed-off-by: Chia-I Wu --- src/mesa/glapi/gl_apitemp.py | 100 +++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 23 deletions(-) (limited to 'src/mesa/glapi/gl_apitemp.py') diff --git a/src/mesa/glapi/gl_apitemp.py b/src/mesa/glapi/gl_apitemp.py index a37c08d6ce..d4f8b1d8f8 100644 --- a/src/mesa/glapi/gl_apitemp.py +++ b/src/mesa/glapi/gl_apitemp.py @@ -82,9 +82,6 @@ class PrintGlOffsets(gl_XML.gl_print_base): else: dispatch = "DISPATCH" - if f.has_different_protocol(name): - print '#ifndef GLX_INDIRECT_RENDERING' - if not f.is_static_entry_point(name): print '%s %s KEYWORD2 NAME(%s)(%s);' % (keyword, f.return_type, n, f.get_parameter_string(name)) print '' @@ -98,8 +95,6 @@ class PrintGlOffsets(gl_XML.gl_print_base): print ' %s(%s, (%s), (F, "gl%s(%s);\\n", %s));' \ % (dispatch, f.name, p_string, name, t_string, o_string) print '}' - if f.has_different_protocol(name): - print '#endif /* GLX_INDIRECT_RENDERING */' print '' return @@ -172,6 +167,10 @@ class PrintGlOffsets(gl_XML.gl_print_base): #error TABLE_ENTRY must be defined #endif +#ifdef _GLAPI_SKIP_NORMAL_ENTRY_POINTS +#error _GLAPI_SKIP_NORMAL_ENTRY_POINTS must not be defined +#endif + static _glapi_proc DISPATCH_TABLE_NAME[] = {""" for f in api.functionIterateByOffset(): print ' TABLE_ENTRY(%s),' % (f.dispatch_name()) @@ -198,33 +197,88 @@ static _glapi_proc DISPATCH_TABLE_NAME[] = {""" #ifdef UNUSED_TABLE_NAME static _glapi_proc UNUSED_TABLE_NAME[] = {""" + normal_entries = [] + proto_entries = [] for f in api.functionIterateByOffset(): - for n in f.entry_points: - if n != f.name: - if f.is_static_entry_point(n): - text = ' TABLE_ENTRY(%s),' % (n) - - if f.has_different_protocol(n): - print '#ifndef GLX_INDIRECT_RENDERING' - print text - print '#endif' - else: - print text + normal_ents, proto_ents = self.classifyEntryPoints(f) + + # exclude f.name + if f.name in normal_ents: + normal_ents.remove(f.name) + elif f.name in proto_ents: + proto_ents.remove(f.name) + + normal_ents = [f.static_name(ent) for ent in normal_ents] + proto_ents = [f.static_name(ent) for ent in proto_ents] + + normal_entries.extend(normal_ents) + proto_entries.extend(proto_ents) + + 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' + for ent in proto_entries: + print ' TABLE_ENTRY(%s),' % (ent) + print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' + print '};' print '#endif /*UNUSED_TABLE_NAME*/' print '' return + def classifyEntryPoints(self, func): + normal_names = [] + normal_stubs = [] + proto_names = [] + proto_stubs = [] + # classify the entry points + for name in func.entry_points: + if func.has_different_protocol(name): + if func.is_static_entry_point(name): + proto_names.append(name) + else: + proto_stubs.append(name) + else: + if func.is_static_entry_point(name): + normal_names.append(name) + else: + normal_stubs.append(name) + # there can be at most one stub for a function + if normal_stubs: + normal_names.append(normal_stubs[0]) + elif proto_stubs: + proto_names.append(proto_stubs[0]) + + return (normal_names, proto_names) + def printBody(self, api): + normal_entry_points = [] + proto_entry_points = [] for func in api.functionIterateByOffset(): - got_stub = 0 - for n in func.entry_points: - if func.is_static_entry_point(n): - self.printFunction(func, n) - elif not got_stub: - self.printFunction(func, n) - got_stub = 1 + normal_ents, proto_ents = self.classifyEntryPoints(func) + normal_entry_points.append((func, normal_ents)) + proto_entry_points.append((func, proto_ents)) + + 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 '' + for func, ents in proto_entry_points: + for ent in ents: + self.printFunction(func, ent) + print '' + print '#endif /* _GLAPI_SKIP_PROTO_ENTRY_POINTS */' + print '' self.printInitDispatch(api) self.printAliasedTable(api) -- cgit v1.2.3 From 1af44e9e5a3b522dd083f7e1486146376b01fdff Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 3 Sep 2009 11:05:06 +0800 Subject: glapi: Add OpenGL ES compatibility mode to scripts. When the mode is on, the scripts would generate headers that are suitable for OpenGL ES. There are two differences. One is that they will generate function prototypes for OpenGL ES specific functions. The other is that, when a function has multiple names, SET/GET/CALL macros would be generated for each of names. Signed-off-by: Chia-I Wu --- src/mesa/glapi/gl_apitemp.py | 21 +++++++++++++++++---- src/mesa/glapi/gl_offsets.py | 25 +++++++++++++++++++++---- src/mesa/glapi/gl_procs.py | 37 ++++++++++++++++++++++++++++++++----- src/mesa/glapi/gl_table.py | 44 ++++++++++++++++++++++++++++++++++++++------ 4 files changed, 108 insertions(+), 19 deletions(-) (limited to 'src/mesa/glapi/gl_apitemp.py') diff --git a/src/mesa/glapi/gl_apitemp.py b/src/mesa/glapi/gl_apitemp.py index d4f8b1d8f8..09b0d364ce 100644 --- a/src/mesa/glapi/gl_apitemp.py +++ b/src/mesa/glapi/gl_apitemp.py @@ -30,7 +30,7 @@ import license import sys, getopt class PrintGlOffsets(gl_XML.gl_print_base): - def __init__(self): + def __init__(self, es=False): gl_XML.gl_print_base.__init__(self) self.name = "gl_apitemp.py (from Mesa)" @@ -38,6 +38,8 @@ class PrintGlOffsets(gl_XML.gl_print_base): """Copyright (C) 1999-2001 Brian Paul All Rights Reserved. (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") + self.es = es + self.undef_list.append( "KEYWORD1" ) self.undef_list.append( "KEYWORD1_ALT" ) self.undef_list.append( "KEYWORD2" ) @@ -82,7 +84,14 @@ class PrintGlOffsets(gl_XML.gl_print_base): else: dispatch = "DISPATCH" + need_proto = False if not f.is_static_entry_point(name): + need_proto = True + elif self.es: + cat, num = api.get_category_for_name(name) + 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 '' @@ -286,22 +295,26 @@ static _glapi_proc UNUSED_TABLE_NAME[] = {""" def show_usage(): - print "Usage: %s [-f input_file_name]" % sys.argv[0] + 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" try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:") + (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 api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - printer = PrintGlOffsets() + printer = PrintGlOffsets(es) printer.Print(api) diff --git a/src/mesa/glapi/gl_offsets.py b/src/mesa/glapi/gl_offsets.py index b8b509d09f..54867b3463 100644 --- a/src/mesa/glapi/gl_offsets.py +++ b/src/mesa/glapi/gl_offsets.py @@ -30,9 +30,10 @@ import license import sys, getopt class PrintGlOffsets(gl_XML.gl_print_base): - def __init__(self): + def __init__(self, es=False): gl_XML.gl_print_base.__init__(self) + self.es = es self.name = "gl_offsets.py (from Mesa)" self.header_tag = '_GLAPI_OFFSETS_H_' self.license = license.bsd_license_template % ( \ @@ -46,6 +47,7 @@ class PrintGlOffsets(gl_XML.gl_print_base): functions = [] abi_functions = [] + alias_functions = [] count = 0 for f in api.functionIterateByOffset(): if not f.is_abi(): @@ -54,6 +56,10 @@ class PrintGlOffsets(gl_XML.gl_print_base): else: abi_functions.append( f ) + if self.es: + # remember functions with aliases + if len(f.entry_points) > 1: + alias_functions.append(f) for f in abi_functions: print '#define _gloffset_%s %d' % (f.name, f.offset) @@ -78,26 +84,37 @@ class PrintGlOffsets(gl_XML.gl_print_base): print '' print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */' + if alias_functions: + print '' + print '/* define aliases for compatibility */' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define _gloffset_%s _gloffset_%s' % (name, f.name) return def show_usage(): - print "Usage: %s [-f input_file_name]" % sys.argv[0] + 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" try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:") + (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 api = gl_XML.parse_GL_API( file_name ) - printer = PrintGlOffsets() + printer = PrintGlOffsets(es) printer.Print( api ) diff --git a/src/mesa/glapi/gl_procs.py b/src/mesa/glapi/gl_procs.py index cd1a68cee1..5de61fbdfe 100644 --- a/src/mesa/glapi/gl_procs.py +++ b/src/mesa/glapi/gl_procs.py @@ -30,9 +30,10 @@ import gl_XML, glX_XML import sys, getopt class PrintGlProcs(gl_XML.gl_print_base): - def __init__(self, long_strings): + def __init__(self, long_strings, es=False): gl_XML.gl_print_base.__init__(self) + self.es = es self.long_strings = long_strings self.name = "gl_procs.py (from Mesa)" self.license = license.bsd_license_template % ( \ @@ -141,6 +142,28 @@ typedef struct { print '%s GLAPIENTRY gl_dispatch_stub_%u(%s);' % (func.return_type, func.offset, func.get_parameter_string()) break + if self.es: + categories = {} + for func in api.functionIterateByOffset(): + for n in func.entry_points: + cat, num = api.get_category_for_name(n) + if (cat.startswith("es") or cat.startswith("GL_OES")): + if not categories.has_key(cat): + categories[cat] = [] + proto = 'GLAPI %s GLAPIENTRY %s(%s);' \ + % (func.return_type, "gl" + n, func.get_parameter_string(n)) + categories[cat].append(proto) + if categories: + print '' + print '/* OpenGL ES specific prototypes */' + print '' + keys = categories.keys() + keys.sort() + for key in keys: + print '/* category %s */' % key + print "\n".join(categories[key]) + print '' + print '#endif /* defined(NEED_FUNCTION_POINTER) || defined(GLX_INDIRECT_RENDERING) */' print '' @@ -155,8 +178,9 @@ typedef struct { def show_usage(): - print "Usage: %s [-f input_file_name] [-m mode]" % sys.argv[0] - print "mode can be one of:" + print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] + print "-c Enable compatibility with OpenGL ES." + print "-m mode mode can be one of:" print " long - Create code for compilers that can handle very" print " long string constants. (default)" print " short - Create code for compilers that can only handle" @@ -167,11 +191,12 @@ if __name__ == '__main__': file_name = "gl_API.xml" try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:") + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") except Exception,e: show_usage() long_string = 1 + es = False for (arg,val) in args: if arg == "-f": file_name = val @@ -182,7 +207,9 @@ if __name__ == '__main__': long_string = 1 else: show_usage() + elif arg == "-c": + es = True api = gl_XML.parse_GL_API(file_name, glX_XML.glx_item_factory()) - printer = PrintGlProcs(long_string) + printer = PrintGlProcs(long_string, es) printer.Print(api) diff --git a/src/mesa/glapi/gl_table.py b/src/mesa/glapi/gl_table.py index 698795fb0a..3bd7569e92 100644 --- a/src/mesa/glapi/gl_table.py +++ b/src/mesa/glapi/gl_table.py @@ -30,9 +30,10 @@ import license import sys, getopt class PrintGlTable(gl_XML.gl_print_base): - def __init__(self): + def __init__(self, es=False): gl_XML.gl_print_base.__init__(self) + self.es = es self.header_tag = '_GLAPI_TABLE_H_' self.name = "gl_table.py (from Mesa)" self.license = license.bsd_license_template % ( \ @@ -68,9 +69,10 @@ class PrintGlTable(gl_XML.gl_print_base): class PrintRemapTable(gl_XML.gl_print_base): - def __init__(self): + def __init__(self, es=False): gl_XML.gl_print_base.__init__(self) + self.es = es self.header_tag = '_GLAPI_DISPATCH_H_' self.name = "gl_table.py (from Mesa)" self.license = license.bsd_license_template % ("(C) Copyright IBM Corporation 2005", "IBM") @@ -115,6 +117,7 @@ class PrintRemapTable(gl_XML.gl_print_base): functions = [] abi_functions = [] + alias_functions = [] count = 0 for f in api.functionIterateByOffset(): if not f.is_abi(): @@ -123,6 +126,11 @@ class PrintRemapTable(gl_XML.gl_print_base): else: abi_functions.append( f ) + if self.es: + # remember functions with aliases + if len(f.entry_points) > 1: + alias_functions.append(f) + for f in abi_functions: print '#define CALL_%s(disp, parameters) (*((disp)->%s)) parameters' % (f.name, f.name) @@ -162,33 +170,57 @@ class PrintRemapTable(gl_XML.gl_print_base): print '' print '#endif /* !defined(_GLAPI_USE_REMAP_TABLE) */' + + if alias_functions: + print '' + print '/* define aliases for compatibility */' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define CALL_%s(disp, parameters) CALL_%s(disp, parameters)' % (name, f.name) + print '#define GET_%s(disp) GET_%s(disp)' % (name, f.name) + print '#define SET_%s(disp, fn) SET_%s(disp, fn)' % (name, f.name) + print '' + + print '#if defined(_GLAPI_USE_REMAP_TABLE)' + for f in alias_functions: + for name in f.entry_points: + if name != f.name: + print '#define %s_remap_index %s_remap_index' % (name, f.name) + print '#endif /* defined(_GLAPI_USE_REMAP_TABLE) */' + print '' + return def show_usage(): - print "Usage: %s [-f input_file_name] [-m mode]" % sys.argv[0] + print "Usage: %s [-f input_file_name] [-m mode] [-c]" % sys.argv[0] print " -m mode Mode can be 'table' or 'remap_table'." + print " -c Enable compatibility with OpenGL ES." sys.exit(1) if __name__ == '__main__': file_name = "gl_API.xml" try: - (args, trail) = getopt.getopt(sys.argv[1:], "f:m:") + (args, trail) = getopt.getopt(sys.argv[1:], "f:m:c") except Exception,e: show_usage() mode = "table" + es = False for (arg,val) in args: if arg == "-f": file_name = val elif arg == "-m": mode = val + elif arg == "-c": + es = True if mode == "table": - printer = PrintGlTable() + printer = PrintGlTable(es) elif mode == "remap_table": - printer = PrintRemapTable() + printer = PrintRemapTable(es) else: show_usage() -- cgit v1.2.3