Dump GLboolean as enum.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 16 Apr 2012 19:09:42 +0000 (20:09 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 16 Apr 2012 19:09:42 +0000 (20:09 +0100)
More readable.

common/json.hpp
retrace/glstate_internal.hpp
retrace/glstate_params.py
specs/__init__.py [deleted file]
specs/gltypes.py
specs/glxapi.py

index 621610a..14ff501 100644 (file)
@@ -306,6 +306,25 @@ public:
         space = ' ';
     }
 
+
+    /**
+     * Special case for char to prevent it to be written as a literal
+     * character.
+     */
+    inline void writeNumber(char n) {
+        separator();
+        os << std::dec << static_cast<int>(n);
+        value = true;
+        space = ' ';
+    }
+
+    inline void writeNumber(unsigned char n) {
+        separator();
+        os << std::dec << static_cast<unsigned>(n);
+        value = true;
+        space = ' ';
+    }
+
     template<class T>
     inline void writeNumber(T n) {
         if (n != n) {
index aab7f98..a709da3 100644 (file)
@@ -54,6 +54,8 @@ struct Context
 };
 
 
+void dumpBoolean(JSONWriter &json, GLboolean value);
+
 void dumpEnum(JSONWriter &json, GLenum pname);
 
 void dumpParameters(JSONWriter &json, Context &context);
index 32f7f7c..1b578ee 100644 (file)
@@ -144,7 +144,7 @@ class StateGetter(Visitor):
         return self.visitScalar(alias, args)
 
     def visitEnum(self, enum, args):
-        return self.visit(GLint, args)
+        return self.visitScalar(enum, args)
 
     def visitBitmask(self, bitmask, args):
         return self.visit(GLint, args)
@@ -213,9 +213,12 @@ class JsonWriter(Visitor):
         print '    json.writeString((const char *)%s);' % instance
 
     def visitEnum(self, enum, instance):
-        if enum.expr == 'GLenum':
+        if enum is GLboolean:
+            print '    dumpBoolean(json, %s);' % instance
+        elif enum is GLenum:
             print '    dumpEnum(json, %s);' % instance
         else:
+            assert False
             print '    json.writeNumber(%s);' % instance
 
     def visitBitmask(self, bitmask, instance):
@@ -259,6 +262,23 @@ class StateDumper:
         print 'namespace glstate {'
         print
 
+        print 'void'
+        print 'dumpBoolean(JSONWriter &json, GLboolean value)'
+        print '{'
+        print '    switch (value) {'
+        print '    case GL_FALSE:'
+        print '        json.writeString("GL_FALSE");'
+        print '        break;'
+        print '    case GL_TRUE:'
+        print '        json.writeString("GL_TRUE");'
+        print '        break;'
+        print '    default:'
+        print '        json.writeNumber(static_cast<GLint>(value));'
+        print '        break;'
+        print '    }'
+        print '}'
+        print
+
         print 'const char *'
         print 'enumToString(GLenum pname)'
         print '{'
@@ -272,13 +292,6 @@ class StateDumper:
         print '}'
         print
 
-        print 'static void'
-        print 'dumpFramebufferAttachementParameters(JSONWriter &json, GLenum target, GLenum attachment)'
-        print '{'
-        self.dump_attachment_parameters('target', 'attachment')
-        print '}'
-        print
-
         print 'void'
         print 'dumpEnum(JSONWriter &json, GLenum pname)'
         print '{'
@@ -291,6 +304,13 @@ class StateDumper:
         print '}'
         print
 
+        print 'static void'
+        print 'dumpFramebufferAttachementParameters(JSONWriter &json, GLenum target, GLenum attachment)'
+        print '{'
+        self.dump_attachment_parameters('target', 'attachment')
+        print '}'
+        print
+
         print 'void dumpParameters(JSONWriter &json, Context &context)'
         print '{'
         print '    json.beginMember("parameters");'
@@ -408,7 +428,9 @@ class StateDumper:
             print '            // %s' % target
             print '            enabled = GL_FALSE;'
             print '            glGetBooleanv(%s, &enabled);' % target
-            print '            json.writeBoolMember("%s", enabled);' % target
+            print '            json.beginMember("%s");' % target
+            print '            dumpBoolean(json, enabled);'
+            print '            json.endMember();'
             print '            binding = 0;'
             print '            glGetIntegerv(%s, &binding);' % binding
             print '            json.writeNumberMember("%s", binding);' % binding
diff --git a/specs/__init__.py b/specs/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
index 2200a88..71d7cd6 100644 (file)
@@ -32,7 +32,11 @@ import platform
 from stdapi import *
 
 
-GLboolean = Alias("GLboolean", Bool)
+GLboolean = Enum("GLboolean", [
+    "GL_TRUE",
+    "GL_FALSE",
+])
+
 GLvoid = Alias("GLvoid", Void)
 GLbyte = Alias("GLbyte", SChar)
 GLshort = Alias("GLshort", Short)
index 7119cc6..d7353a0 100644 (file)
@@ -454,3 +454,5 @@ glxapi.addFunctions([
 ])
 
 
+# To prevent collision with stdapi.Bool
+del Bool