]> git.cworth.org Git - apitrace/commitdiff
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 621610af4451c0720c796ee0c366d8fe2b91deb3..14ff501f5681777a19a56b8321643d2e68239388 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 aab7f986c43a4390c2225b95a2bf7ff1bc526cbe..a709da3ba08ea84b97f6353be66c2509fee29a09 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 32f7f7ca50da65fda2a20fd5a5316b55bd1b41d7..1b578eed6c4d245f1c30e4e538cf215a08a55add 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 2200a88bfeaa972385d46482229327e6bffd58ea..71d7cd613e110e5ed224b4777901e1b9ede87beb 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 7119cc688738ea1902579691387e2c3579210095..d7353a01455aa56ba23d181ccd22bcadf95ba8af 100644 (file)
@@ -454,3 +454,5 @@ glxapi.addFunctions([
 ])
 
 
+# To prevent collision with stdapi.Bool
+del Bool