R1/2/3/4/5xx: fixed calculation of cliprects in CopyBuffer.
[mesa.git] / src / mesa / glapi / gl_XML.py
index eef29072572102579ee6865900ca0634861950f7..b7a7388400dd261b303d3239998362ecdf134558 100644 (file)
@@ -44,58 +44,11 @@ def parse_GL_API( file_name, factory = None ):
        # dispatch offsets to the functions that request that their offsets
        # be assigned by the scripts.  Typically this means all functions
        # that are not part of the ABI.
-       #
-       # To bring some sanity to the generated offsets, we group all
-       # functions into four groups.  The groups have offsets assigned to
-       # their functions in order.  The groups are:
-       #
-       # 1. Core GL versions, sorted by version number.
-       # 2. ARB extensions, sorted by extension number.
-       # 3. Non-ARB extensions, sorted by extension number.
-       # 4. Un-numbered, non-ARB extensions, sorted by extension name.
-
-       lists = [{}, {}, {}, {}]
-
-       for func in api.functionIterateAll():
-               if func.assign_offset:
-                       [cat_name, cat_number] = api.category_dict[func.name]
-
-                       try:
-                               core_version = float(cat_name)
-                       except Exception,e:
-                               core_version = 0.0
-
-                       if core_version > 0.0:
-                               func_cat_type = 0
-                               key = cat_name
-                       elif cat_name.startswith( "GL_ARB_" ):
-                               func_cat_type = 1
-                               key = int(cat_number)
-                       else:
-                               if cat_number != None:
-                                       func_cat_type = 2
-                                       key = int(cat_number)
-                               else:
-                                       func_cat_type = 3
-                                       key = cat_name
-
-                       if not lists[func_cat_type].has_key(key):
-                               lists[func_cat_type][key] = {}
-
-                       lists[func_cat_type][key][func.name] = func
 
-       for func_cat_type in range(0,4):
-               keys = lists[func_cat_type].keys()
-               keys.sort()
-
-               for key in keys:
-                       names = lists[func_cat_type][key].keys()
-                       names.sort()
-
-                       for name in names:
-                               func = lists[func_cat_type][key][name]
-                               func.offset = api.next_offset;
-                               api.next_offset += 1
+       for func in api.functionIterateByCategory():
+               if func.assign_offset:
+                       func.offset = api.next_offset;
+                       api.next_offset += 1
 
        doc.freeDoc()
 
@@ -316,6 +269,41 @@ def real_category_name(c):
                return c
 
 
+def classify_category(name, number):
+       """Based on the category name and number, select a numerical class for it.
+       
+       Categories are divided into four classes numbered 0 through 3.  The
+       classes are:
+
+               0. Core GL versions, sorted by version number.
+               1. ARB extensions, sorted by extension number.
+               2. Non-ARB extensions, sorted by extension number.
+               3. Un-numbered extensions, sorted by extension name.
+       """
+
+       try:
+               core_version = float(name)
+       except Exception,e:
+               core_version = 0.0
+
+       if core_version > 0.0:
+               cat_type = 0
+               key = name
+       elif name.startswith("GL_ARB_") or name.startswith("GLX_ARB_") or name.startswith("WGL_ARB_"):
+               cat_type = 1
+               key = int(number)
+       else:
+               if number != None:
+                       cat_type = 2
+                       key = int(number)
+               else:
+                       cat_type = 3
+                       key = name
+
+
+       return [cat_type, key]
+
+
 def create_parameter_string(parameters, include_names):
        """Create a parameter string from a list of gl_parameters."""
 
@@ -450,8 +438,9 @@ class gl_parameter:
                #if ts == "GLdouble":
                #       print '/* stack size -> %s = %u (after) */' % (self.name, self.type_expr.get_stack_size())
 
-               self.is_counter = is_attr_true( element, 'counter' )
-               self.is_output  = is_attr_true( element, 'output' )
+               self.is_client_only = is_attr_true( element, 'client_only' )
+               self.is_counter     = is_attr_true( element, 'counter' )
+               self.is_output      = is_attr_true( element, 'output' )
 
 
                # Pixel data has special parameters.
@@ -614,6 +603,8 @@ class gl_function( gl_item ):
 
                self.assign_offset = 0
 
+               self.static_entry_points = []
+
                # Track the parameter string (for the function prototype)
                # for each entry-point.  This is done because some functions
                # change their prototype slightly when promoted from extension
@@ -634,7 +625,8 @@ class gl_function( gl_item ):
                name = element.nsProp( "name", None )
                alias = element.nsProp( "alias", None )
 
-               self.static_dispatch = is_attr_true(element, "static_dispatch")
+               if is_attr_true(element, "static_dispatch"):
+                       self.static_entry_points.append(name)
 
                self.entry_points.append( name )
                if alias:
@@ -731,6 +723,32 @@ class gl_function( gl_item ):
                
                return create_parameter_string( self.parameters, 1 )
 
+       def get_called_parameter_string(self):
+               p_string = ""
+               comma = ""
+
+               for p in self.parameterIterator():
+                       p_string = p_string + comma + p.name
+                       comma = ", "
+
+               return p_string
+
+
+       def is_static_entry_point(self, name):
+               return name in self.static_entry_points
+
+       def dispatch_name(self):
+               if self.name in self.static_entry_points:
+                       return self.name
+               else:
+                       return "_dispatch_stub_%u" % (self.offset)
+
+       def static_name(self, name):
+               if name in self.static_entry_points:
+                       return name
+               else:
+                       return "_dispatch_stub_%u" % (self.offset)
+
 
 class gl_item_factory:
        """Factory to create objects derived from gl_item."""
@@ -755,7 +773,9 @@ class gl_api:
                self.functions_by_name = {}
                self.enums_by_name = {}
                self.types_by_name = {}
+
                self.category_dict = {}
+               self.categories = [{}, {}, {}, {}]
 
                self.factory = factory
 
@@ -793,6 +813,9 @@ class gl_api:
                cat_name = cat.nsProp( "name", None )
                cat_number = cat.nsProp( "number", None )
 
+               [cat_type, key] = classify_category(cat_name, cat_number)
+               self.categories[cat_type][key] = [cat_name, cat_number]
+
                child = cat.children
                while child:
                        if child.type == "element":
@@ -826,6 +849,43 @@ class gl_api:
                return
 
 
+       def functionIterateByCategory(self, cat = None):
+               """Iterate over functions by category.
+               
+               If cat is None, all known functions are iterated in category
+               order.  See classify_category for details of the ordering.
+               Within a category, functions are sorted by name.  If cat is
+               not None, then only functions in that category are iterated.
+               """
+               lists = [{}, {}, {}, {}]
+
+               for func in self.functionIterateAll():
+                       [cat_name, cat_number] = self.category_dict[func.name]
+
+                       if (cat == None) or (cat == cat_name):
+                               [func_cat_type, key] = classify_category(cat_name, cat_number)
+
+                               if not lists[func_cat_type].has_key(key):
+                                       lists[func_cat_type][key] = {}
+
+                               lists[func_cat_type][key][func.name] = func
+
+
+               functions = []
+               for func_cat_type in range(0,4):
+                       keys = lists[func_cat_type].keys()
+                       keys.sort()
+
+                       for key in keys:
+                               names = lists[func_cat_type][key].keys()
+                               names.sort()
+
+                               for name in names:
+                                       functions.append(lists[func_cat_type][key][name])
+
+               return functions.__iter__()
+
+
        def functionIterateByOffset(self):
                max_offset = -1
                for func in self.functions_by_name.itervalues():
@@ -862,6 +922,25 @@ class gl_api:
                return list.__iter__()
 
 
+       def categoryIterate(self):
+               """Iterate over categories.
+               
+               Iterate over all known categories in the order specified by
+               classify_category.  Each iterated value is a tuple of the
+               name and number (which may be None) of the category.
+               """
+
+               list = []
+               for cat_type in range(0,4):
+                       keys = self.categories[cat_type].keys()
+                       keys.sort()
+                       
+                       for key in keys:
+                               list.append(self.categories[cat_type][key])
+                               
+               return list.__iter__()
+
+
        def get_category_for_name( self, name ):
                if self.category_dict.has_key(name):
                        return self.category_dict[name]