Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[mesa.git] / src / mesa / glapi / gl_enums.py
index 0e3c57042a65d2caa3052bab9a52eb18ec3d11ac..27ab119537ec3dc9a8f81ab5a69de6614d388caf 100644 (file)
@@ -43,6 +43,7 @@ class PrintGlEnums(gl_XML.gl_print_base):
 
        def printRealHeader(self):
                print '#include "glheader.h"'
+               print '#include "mfeatures.h"'
                print '#include "enums.h"'
                print '#include "imports.h"'
                print ''
@@ -55,8 +56,6 @@ class PrintGlEnums(gl_XML.gl_print_base):
 
        def print_code(self):
                print """
-#define Elements(x) sizeof(x)/sizeof(*x)
-
 typedef int (*cfunc)(const void *, const void *);
 
 /**
@@ -96,8 +95,10 @@ const char *_mesa_lookup_enum_by_nr( int nr )
 {
    unsigned * i;
 
-   i = (unsigned *)bsearch( & nr, reduced_enums, Elements(reduced_enums),
-                            sizeof(reduced_enums[0]), (cfunc) compar_nr );
+   i = (unsigned *) _mesa_bsearch(& nr, reduced_enums,
+                                  Elements(reduced_enums),
+                                  sizeof(reduced_enums[0]),
+                                  (cfunc) compar_nr);
 
    if ( i != NULL ) {
       return & enum_string_table[ all_enums[ *i ].offset ];
@@ -109,13 +110,38 @@ const char *_mesa_lookup_enum_by_nr( int nr )
    }
 }
 
+/* Get the name of an enum given that it is a primitive type.  Avoids
+ * GL_FALSE/GL_POINTS ambiguity and others.
+ */
+const char *_mesa_lookup_prim_by_nr( int nr )
+{
+   switch (nr) {
+   case GL_POINTS: return "GL_POINTS";
+   case GL_LINES: return "GL_LINES";
+   case GL_LINE_STRIP: return "GL_LINE_STRIP";
+   case GL_LINE_LOOP: return "GL_LINE_LOOP";
+   case GL_TRIANGLES: return "GL_TRIANGLES";
+   case GL_TRIANGLE_STRIP: return "GL_TRIANGLE_STRIP";
+   case GL_TRIANGLE_FAN: return "GL_TRIANGLE_FAN";
+   case GL_QUADS: return "GL_QUADS";
+   case GL_QUAD_STRIP: return "GL_QUAD_STRIP";
+   case GL_POLYGON: return "GL_POLYGON";
+   case GL_POLYGON+1: return "OUTSIDE_BEGIN_END";
+   default: return "<invalid>";
+   }
+}
+
+
+
 int _mesa_lookup_enum_by_name( const char *symbol )
 {
    enum_elt * f = NULL;
 
    if ( symbol != NULL ) {
-      f = (enum_elt *)bsearch( symbol, all_enums, Elements(all_enums),
-                              sizeof( enum_elt ), (cfunc) compar_name );
+      f = (enum_elt *) _mesa_bsearch(symbol, all_enums,
+                                     Elements(all_enums),
+                                     sizeof( enum_elt ),
+                                     (cfunc) compar_name);
    }
 
    return (f != NULL) ? f->n : -1;