]> git.cworth.org Git - apitrace/commitdiff
retrace: Use different methods for writing int/floats.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 15 Nov 2012 13:36:09 +0000 (13:36 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 15 Nov 2012 13:36:09 +0000 (13:36 +0000)
More efficient code, less compiler warnings.

retrace/glstate_images.cpp
retrace/glstate_params.py
retrace/glstate_shaders.cpp
retrace/json.hpp

index e534a654320ef55bafbe1adda4d847df0af3e6da..e5e14517dc299e78d65fe69e98899961bc18cec2 100644 (file)
@@ -409,9 +409,9 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
     // Tell the GUI this is no ordinary object, but an image
     json.writeStringMember("__class__", "image");
 
-    json.writeNumberMember("__width__", desc.width);
-    json.writeNumberMember("__height__", desc.height);
-    json.writeNumberMember("__depth__", desc.depth);
+    json.writeIntMember("__width__", desc.width);
+    json.writeIntMember("__height__", desc.height);
+    json.writeIntMember("__depth__", desc.depth);
 
     json.writeStringMember("__format__", formatToString(desc.internalFormat));
 
@@ -419,7 +419,7 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
     // texture internal format
     json.writeStringMember("__type__", "uint8");
     json.writeBoolMember("__normalized__", true);
-    json.writeNumberMember("__channels__", channels);
+    json.writeIntMember("__channels__", channels);
 
     GLubyte *pixels = new GLubyte[desc.depth*desc.width*desc.height*channels];
 
@@ -859,9 +859,9 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format,
     // Tell the GUI this is no ordinary object, but an image
     json.writeStringMember("__class__", "image");
 
-    json.writeNumberMember("__width__", width);
-    json.writeNumberMember("__height__", height);
-    json.writeNumberMember("__depth__", 1);
+    json.writeIntMember("__width__", width);
+    json.writeIntMember("__height__", height);
+    json.writeIntMember("__depth__", 1);
 
     json.writeStringMember("__format__", formatToString(internalFormat));
 
@@ -869,7 +869,7 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format,
     // texture internal format
     json.writeStringMember("__type__", "uint8");
     json.writeBoolMember("__normalized__", true);
-    json.writeNumberMember("__channels__", channels);
+    json.writeIntMember("__channels__", channels);
 
     GLenum type = GL_UNSIGNED_BYTE;
 
index a87457ff532cbea9b6f68d0f8fe43e4d91ce4cbd..c88b6f043475fefe98ad8ea8b9cd12d59811cfd5 100644 (file)
@@ -203,8 +203,10 @@ class JsonWriter(Visitor):
     def visitLiteral(self, literal, instance):
         if literal.kind == 'Bool':
             print '    json.writeBool(%s);' % instance
-        elif literal.kind in ('SInt', 'Uint', 'Float', 'Double'):
-            print '    json.writeNumber(%s);' % instance
+        elif literal.kind in ('SInt', 'Uint'):
+            print '    json.writeInt(%s);' % instance
+        elif literal.kind in ('Float', 'Double'):
+            print '    json.writeFloat(%s);' % instance
         else:
             raise NotImplementedError
 
@@ -219,7 +221,7 @@ class JsonWriter(Visitor):
             print '    dumpEnum(json, %s);' % instance
         else:
             assert False
-            print '    json.writeNumber(%s);' % instance
+            print '    json.writeInt(%s);' % instance
 
     def visitBitmask(self, bitmask, instance):
         raise NotImplementedError
@@ -228,7 +230,7 @@ class JsonWriter(Visitor):
         self.visit(alias.type, instance)
 
     def visitOpaque(self, opaque, instance):
-        print '    json.writeNumber((size_t)%s);' % instance
+        print '    json.writeInt((size_t)%s);' % instance
 
     __index = 0
 
@@ -273,7 +275,7 @@ class StateDumper:
         print '        json.writeString("GL_TRUE");'
         print '        break;'
         print '    default:'
-        print '        json.writeNumber(static_cast<GLint>(value));'
+        print '        json.writeInt(static_cast<GLint>(value));'
         print '        break;'
         print '    }'
         print '}'
@@ -299,7 +301,7 @@ class StateDumper:
         print '    if (s) {'
         print '        json.writeString(s);'
         print '    } else {'
-        print '        json.writeNumber(pname);'
+        print '        json.writeInt(pname);'
         print '    }'
         print '}'
         print
@@ -433,7 +435,7 @@ class StateDumper:
             print '            json.endMember();'
             print '            binding = 0;'
             print '            glGetIntegerv(%s, &binding);' % binding
-            print '            json.writeNumberMember("%s", binding);' % binding
+            print '            json.writeIntMember("%s", binding);' % binding
             print '            if (enabled || binding) {'
             print '                json.beginMember("%s");' % target
             print '                json.beginObject();'
index a651d994736780f1d331d29c4af03d1db28936c2..d32a7b42746821d8d19f40e425eb5fdf80f36c6a 100644 (file)
@@ -245,16 +245,16 @@ dumpUniformValues(JSONWriter &json, GLenum type, const void *values, GLint matri
 
             switch (elemType) {
             case GL_FLOAT:
-                json.writeNumber(*u.fvalue);
+                json.writeFloat(*u.fvalue);
                 break;
             case GL_DOUBLE:
-                json.writeNumber(*u.dvalue);
+                json.writeFloat(*u.dvalue);
                 break;
             case GL_INT:
-                json.writeNumber(*u.ivalue);
+                json.writeInt(*u.ivalue);
                 break;
             case GL_UNSIGNED_INT:
-                json.writeNumber(*u.uivalue);
+                json.writeInt(*u.uivalue);
                 break;
             case GL_BOOL:
                 json.writeBool(*u.uivalue);
@@ -625,10 +625,10 @@ dumpArbProgramUniforms(JSONWriter &json, GLenum target, const char *prefix)
 
         json.beginMember(name);
         json.beginArray();
-        json.writeNumber(params[0]);
-        json.writeNumber(params[1]);
-        json.writeNumber(params[2]);
-        json.writeNumber(params[3]);
+        json.writeFloat(params[0]);
+        json.writeFloat(params[1]);
+        json.writeFloat(params[2]);
+        json.writeFloat(params[3]);
         json.endArray();
         json.endMember();
     }
@@ -648,10 +648,10 @@ dumpArbProgramUniforms(JSONWriter &json, GLenum target, const char *prefix)
 
         json.beginMember(name);
         json.beginArray();
-        json.writeNumber(params[0]);
-        json.writeNumber(params[1]);
-        json.writeNumber(params[2]);
-        json.writeNumber(params[3]);
+        json.writeFloat(params[0]);
+        json.writeFloat(params[1]);
+        json.writeFloat(params[2]);
+        json.writeFloat(params[3]);
         json.endArray();
         json.endMember();
     }
index 4ad2ab35d2fd9f270fd4c53845b4ef0293b0b422..0431cf775189d4a6a85fc68d8373a431cd88ac4c 100644 (file)
@@ -320,14 +320,14 @@ public:
      * Special case for char to prevent it to be written as a literal
      * character.
      */
-    inline void writeNumber(char n) {
+    inline void writeInt(signed char n) {
         separator();
         os << std::dec << static_cast<int>(n);
         value = true;
         space = ' ';
     }
 
-    inline void writeNumber(unsigned char n) {
+    inline void writeInt(unsigned char n) {
         separator();
         os << std::dec << static_cast<unsigned>(n);
         value = true;
@@ -335,7 +335,14 @@ public:
     }
 
     template<class T>
-    inline void writeNumber(T n) {
+    inline void writeInt(T n) {
+        separator();
+        os << std::dec << n;
+        value = true;
+        space = ' ';
+    }
+    template<class T>
+    inline void writeFloat(T n) {
         separator();
         if (isnan(n)) {
             // NaN is non-standard but widely supported
@@ -366,9 +373,9 @@ public:
     }
 
     template<class T>
-    inline void writeNumberMember(const char *name, T n) {
+    inline void writeIntMember(const char *name, T n) {
         beginMember(name);
-        writeNumber(n);
+        writeInt(n);
         endMember();
     }
 };