[Mesa-dev] [RFC 10/13] wip

Dylan Baker dylan at pnwbakers.com
Fri Nov 23 22:27:59 UTC 2018


---
 src/mapi/glapi/gen/khr_xml.py | 81 +++++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 3 deletions(-)

diff --git a/src/mapi/glapi/gen/khr_xml.py b/src/mapi/glapi/gen/khr_xml.py
index 784931b5059..7909afb922d 100644
--- a/src/mapi/glapi/gen/khr_xml.py
+++ b/src/mapi/glapi/gen/khr_xml.py
@@ -33,6 +33,80 @@ import six
 import mesa_data
 
 
+ at attr.s
+class CType(object):
+
+    """Represents a C Type."""
+
+    name = attr.ib(type=six.text_type)
+    size = attr.ib(type=int)
+
+
+C_TYPES = {
+    c.name: c for c in [
+        CType('void', 1),
+        CType('char', 1),
+        CType('short', 2),
+        CType('int', 4),
+        CType('long', 4),
+        CType('float', 4),
+        CType('double', 8),
+        CType('enum', 4),
+    ]
+}
+
+
+ at six.python_2_unicode_compatible
+ at attr.s(str=False)
+class GLType(object):
+
+    """Represents a GLType."""
+
+    name = attr.ib(type=six.text_type)
+    ctype = attr.ib(type=CType)
+
+    @property
+    def size(self):
+        return self.ctype.size
+
+    def __str__(self):
+        return self.name
+
+
+GL_TYPES = {
+    g.name: g for g in [
+        # For the purposes of this list an unsigned and a signed are equivalent
+        GLType('GLenum', C_TYPES['int']),
+        GLType('GLboolean', C_TYPES['char']),
+        GLType('GLbitfield', C_TYPES['int']),
+        GLType('GLbyte', C_TYPES['char']),
+        GLType('GLshort', C_TYPES['short']),
+        GLType('GLint', C_TYPES['int']),
+        GLType('GLclampx', C_TYPES['int']),
+        GLType('GLubyte', C_TYPES['char']),
+        GLType('GLushort', C_TYPES['short']),
+        GLType('GLhalfNV', C_TYPES['short']),
+        GLType('GLuint', C_TYPES['int']),
+        GLType('GLsizei', C_TYPES['int']),
+        GLType('GLfloat', C_TYPES['float']),
+        GLType('GLclampf', C_TYPES['float']),
+        GLType('GLdouble', C_TYPES['double']),
+        GLType('GLclampd', C_TYPES['double']),
+        GLType('GLchar', C_TYPES['char']),
+        GLType('GLcharARB', C_TYPES['char']),
+        GLType('GLfixed', C_TYPES['int']),
+
+        # XXX: everything after this are pretty sketchy
+        GLType('GLuint64', C_TYPES['int']),
+        GLType('GLuint64EXT', C_TYPES['int']),
+        GLType('GLhandleARB', C_TYPES['int']),
+        GLType('void', C_TYPES['void']),
+        GLType('GLeglClientBufferEXT', C_TYPES['void']),
+        GLType('GLeglImageOES', C_TYPES['void']),
+    ]
+}
+
+
 @attr.s
 class Length(object):
 
@@ -93,7 +167,7 @@ class Param(object):
     type = attr.ib(type=six.text_type)
     prefix = attr.ib()  # type: Optional[six.text_type]
     suffix = attr.ib()  # type: Optional[six.text_type]
-    len = attr.ib()     # type: Optional[six.text_type]
+    len = attr.ib()     # type: Optional[Length]
 
     def is_pointer(self):
         if self.suffix is not None:
@@ -108,7 +182,7 @@ class Param(object):
         if self.suffix:
             vals.append(self.suffix)
         vals.append(self.name)
-        return ' '.join(vals)
+        return ' '.join(str(v) for v in vals)
 
 
 @attr.s
@@ -164,7 +238,6 @@ def make_functions(xml):
             len_ = Length.from_xml(param.attrib.get('len'))
 
             if not type_:
-
                 split = prefix.split(' ')
                 assert 1 < len(split) <= 3
                 if len(split) == 3:
@@ -175,6 +248,8 @@ def make_functions(xml):
                     else:
                         prefix, type_ = split
 
+            type_ = GL_TYPES.get(type_, type_)
+
             params.append(Param(name, type_, prefix, suffix, len_))
 
         yield Function(proto, params, mesa_data.FUNCTIONS.get(proto.name))
-- 
2.19.2



More information about the mesa-dev mailing list