class glXEnumFunction:
def __init__(self, name):
self.name = name
-
+ self.mode = 0
+ self.sig = None
+
# "enums" is a set of lists. The element in the set is the
# value of the enum. The list is the list of names for that
# value. For example, [0x8126] = {"POINT_SIZE_MIN",
def signature( self ):
- sig = ""
- for i in self.count:
- for e in self.count[i]:
- sig += "%04x,%u," % (e, i)
+ if self.sig == None:
+ self.sig = ""
+ for i in self.count:
+ for e in self.count[i]:
+ self.sig += "%04x,%u," % (e, i)
- return sig;
+ return self.sig
+
+
+ def set_mode( self, mode ):
+ """Mark an enum-function as a 'set' function."""
+
+ self.mode = mode
+
+
+ def is_set( self ):
+ return self.mode
def PrintUsingTable(self):
if not self.context.glx_enum_functions.has_key( n ):
f = glXEnumFunction( n )
+ f.set_mode( mode )
self.context.glx_enum_functions[ f.name ] = f
self.context.glx_enum_functions[ n ].append( c, self.value, self.name )
import sys, getopt, copy
-class PrintGlxSizeStubs_c(glX_XML.GlxProto):
- def __init__(self):
+class SizeStubFunctionIterator:
+ """Iterate over functions that need "size" information.
+
+ Iterate over the functions that have variable sized data. First the
+ "set"-type functions are iterated followed by the "get"-type
+ functions.
+ """
+
+ def __init__(self, context):
+ self.data = []
+ self.index = 0
+
+ set_functions = []
+ get_functions = []
+ extra_data = []
+
+ for f in gl_XML.glFunctionIterator(context):
+ if f.fn_offset < 0: break
+
+ if context.glx_enum_functions.has_key(f.name):
+ ef = context.glx_enum_functions[f.name]
+ if ef.is_set():
+ set_functions.append(f)
+ else:
+ get_functions.append(f)
+
+
+ if (context.which_functions & PrintGlxSizeStubs_c.do_set) != 0:
+ self.data += set_functions
+ elif context.get_alias_set:
+ extra_data = set_functions
+
+ if (context.which_functions & PrintGlxSizeStubs_c.do_get) != 0:
+ self.data += get_functions
+
+
+ for f in extra_data + self.data:
+ sig = context.glx_enum_functions[f.name].signature()
+
+ if not context.glx_enum_sigs.has_key(sig):
+ context.glx_enum_sigs[sig] = f.name;
+
+ return
+
+
+ def __iter__(self):
+ return self
+
+
+ def next(self):
+ if self.index == len(self.data):
+ raise StopIteration
+
+ f = self.data[ self.index ]
+ self.index += 1
+
+ return f
+
+
+class PrintGlxSizeStubs_common(glX_XML.GlxProto):
+ do_get = (1 << 0)
+ do_set = (1 << 1)
+ do_get_alias_set = (1 << 2)
+
+ def __init__(self, which_functions):
glX_XML.GlxProto.__init__(self)
self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM")
self.aliases = []
self.glx_enum_sigs = {}
self.name = "glX_proto_size.py (from Mesa)"
+ self.which_functions = which_functions
+
+ if (((which_functions & PrintGlxSizeStubs_common.do_set) != 0) and ((which_functions & PrintGlxSizeStubs_common.do_get) != 0)) or ((which_functions & PrintGlxSizeStubs_common.do_get_alias_set) != 0):
+ self.get_alias_set = 1
+ else:
+ self.get_alias_set = 0
+
+ def functionIterator(self):
+ return SizeStubFunctionIterator(self)
+
+
+class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common):
def printRealHeader(self):
print ''
print '#include <GL/gl.h>'
print ''
print ''
+
def printRealFooter(self):
for a in self.aliases:
print a
+
def printFunction(self, f):
- if self.glx_enum_functions.has_key(f.name):
- ef = self.glx_enum_functions[f.name]
+ ef = self.glx_enum_functions[f.name]
+ n = self.glx_enum_sigs[ ef.signature() ];
- sig = ef.signature();
- if self.glx_enum_sigs.has_key(sig):
- n = self.glx_enum_sigs[sig];
- a = 'ALIAS( %s, %s )' % (f.name, n)
- self.aliases.append(a)
- else:
- ef.Print( f.name )
- self.glx_enum_sigs[sig] = f.name;
+ if n != f.name:
+ a = 'ALIAS( %s, %s )' % (f.name, n)
+ self.aliases.append(a)
+ else:
+ ef.Print( f.name )
-class PrintGlxSizeStubs_h(glX_XML.GlxProto):
- def __init__(self):
- glX_XML.GlxProto.__init__(self)
- self.license = license.bsd_license_template % ( "(C) Copyright IBM Corporation 2004", "IBM")
- self.aliases = []
- self.glx_enum_sigs = {}
- self.name = "glX_proto_size.py (from Mesa)"
-
+class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common):
def printRealHeader(self):
print """
/**
def printFunction(self, f):
- if self.glx_enum_functions.has_key(f.name):
- ef = self.glx_enum_functions[f.name]
- print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (f.name)
+ ef = self.glx_enum_functions[f.name]
+ print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (f.name)
def show_usage():
- print "Usage: %s [-f input_file_name] [-m output_mode]" % sys.argv[0]
+ print "Usage: %s [-f input_file_name] -m output_mode [--only-get | --only-set] [--get-alias-set]" % sys.argv[0]
+ print " -m output_mode Output mode can be one of 'size_c' or 'size_h'."
+ print " --only-get Only emit 'get'-type functions."
+ print " --only-set Only emit 'set'-type functions."
+ print " --get-alias-set When only 'get'-type functions are emitted, allow them"
+ print " to be aliases to 'set'-type funcitons."
+ print ""
+ print "By default, both 'get' and 'set'-type functions are emitted."
sys.exit(1)
file_name = "gl_API.xml"
try:
- (args, trail) = getopt.getopt(sys.argv[1:], "f:m:")
+ (args, trail) = getopt.getopt(sys.argv[1:], "f:m:", ["only-get", "only-set", "get-alias-set"])
except Exception,e:
show_usage()
- mode = "proto"
+ mode = None
+ which_functions = PrintGlxSizeStubs_common.do_get | PrintGlxSizeStubs_common.do_set
+
for (arg,val) in args:
if arg == "-f":
file_name = val
elif arg == "-m":
mode = val
+ elif arg == "--only-get":
+ which_functions = PrintGlxSizeStubs_common.do_get
+ elif arg == "--only-set":
+ which_functions = PrintGlxSizeStubs_common.do_set
+ elif arg == "--get-alias-set":
+ which_functions |= PrintGlxSizeStubs_common.do_get_alias_set
if mode == "size_c":
- dh = PrintGlxSizeStubs_c()
+ dh = PrintGlxSizeStubs_c( which_functions )
elif mode == "size_h":
- dh = PrintGlxSizeStubs_h()
+ dh = PrintGlxSizeStubs_h( which_functions )
else:
show_usage()