]> git.cworth.org Git - apitrace/commitdiff
Linearize texture data in JSON.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 6 May 2011 23:10:25 +0000 (00:10 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 6 May 2011 23:10:25 +0000 (00:10 +0100)
glstate.py
gui/apisurface.cpp
gui/apisurface.h
gui/apitracecall.cpp
gui/mainwindow.cpp

index 5f7416bc42021249b355f4ed9b3d6f28870c130c..2ab7f288c863e2be61fc3ff0dda052602ffb7f01 100644 (file)
@@ -383,8 +383,16 @@ writeTextureImage(JSONWriter &json, GLenum target, GLint level)
     }
 
     if (width <= 0 || height <= 0 || depth <= 0) {
-        json.writeNull();
+        return;
     } else {
+        char label[512];
+
+        GLint active_texture = GL_TEXTURE0;
+        glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
+        snprintf(label, sizeof label, "%s, %s, level = %i", _enum_string(active_texture), _enum_string(target), level);
+
+        json.beginMember(label);
+
         json.beginObject();
 
         // Tell the GUI this is no ordinary object, but an image
@@ -615,16 +623,12 @@ writeDrawBuffers(JSONWriter &json, GLboolean writeDepth, GLboolean writeStencil)
         print 'static inline void'
         print 'writeTexture(JSONWriter &json, GLenum target, GLenum binding)'
         print '{'
-        print '    GLint texture = 0;'
-        print '    glGetIntegerv(binding, &texture);'
-        print '    if (!glIsEnabled(target) && !texture) {'
-        print '        json.writeNull();'
+        print '    GLint texture_binding = 0;'
+        print '    glGetIntegerv(binding, &texture_binding);'
+        print '    if (!glIsEnabled(target) && !texture_binding) {'
         print '        return;'
         print '    }'
         print
-        print '    json.beginObject();'
-        print '    json.beginMember("levels");'
-        print '    json.beginArray();'
         print '    GLint level = 0;'
         print '    do {'
         print '        GLint width = 0, height = 0;'
@@ -633,25 +637,11 @@ writeDrawBuffers(JSONWriter &json, GLboolean writeDepth, GLboolean writeStencil)
         print '        if (!width || !height) {'
         print '            break;'
         print '        }'
-        print '        json.beginObject();'
-        print
-        # FIXME: This is not the original texture name in the trace -- we need
-        # to do a reverse lookup of the texture mappings to find the original one
-        print '        json.beginMember("binding");'
-        print '        json.writeNumber(texture);'
-        print '        json.endMember();'
         print
-        print '        json.beginMember("image");'
         print '        writeTextureImage(json, target, level);'
-        print '        json.endMember();'
         print
-        print '        json.endObject();'
         print '        ++level;'
         print '    } while(true);'
-        print '    json.endArray();'
-        print '    json.endMember(); // levels'
-        print
-        print '    json.endObject();'
         print '}'
         print
 
@@ -798,7 +788,7 @@ writeDrawBuffers(JSONWriter &json, GLboolean writeDepth, GLboolean writeStencil)
     def dump_textures(self):
         print '    {'
         print '        json.beginMember("textures");'
-        print '        json.beginArray();'
+        print '        json.beginObject();'
         print '        GLint active_texture = GL_TEXTURE0;'
         print '        glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);'
         print '        GLint max_texture_coords = 0;'
@@ -807,17 +797,14 @@ writeDrawBuffers(JSONWriter &json, GLboolean writeDepth, GLboolean writeStencil)
         print '        glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_combined_texture_image_units);'
         print '        GLint max_units = std::max(max_combined_texture_image_units, max_texture_coords);'
         print '        for (GLint unit = 0; unit < max_units; ++unit) {'
-        print '            glActiveTexture(GL_TEXTURE0 + unit);'
-        print '            json.beginObject();'
+        print '            GLenum texture = GL_TEXTURE0 + unit;'
+        print '            glActiveTexture(texture);'
         for target, binding in texture_targets:
-            print '            json.beginMember("%s");' % target
             print '            writeTexture(json, %s, %s);' % (target, binding)
-            print '            json.endMember();'
-        print '            json.endObject();'
         print '        }'
         print '        glActiveTexture(active_texture);'
-        print '        json.endArray();'
-        print '        json.endMember(); // texture'
+        print '        json.endObject();'
+        print '        json.endMember(); // textures'
         print '    }'
         print
 
index 1123ead1668393be8d1615c59b842bad6665083a..64aa1532bc7083a89de2ea130489c3f7b146d8bb 100644 (file)
@@ -46,40 +46,18 @@ QImage ApiSurface::thumb() const
 }
 
 ApiTexture::ApiTexture()
-    : ApiSurface(),
-      m_unit(0),
-      m_level(0)
-{
-}
-
-int ApiTexture::unit() const
-{
-    return m_unit;
-}
-
-void ApiTexture::setUnit(int un)
-{
-    m_unit = un;
-}
-
-QString ApiTexture::target() const
-{
-    return m_target;
-}
-
-void ApiTexture::setTarget(const QString &str)
+    : ApiSurface()
 {
-    m_target = str;
 }
 
-int ApiTexture::level() const
+QString ApiTexture::label() const
 {
-    return m_level;
+    return m_label;
 }
 
-void ApiTexture::setLevel(int l)
+void ApiTexture::setLabel(const QString &str)
 {
-    m_level = l;
+    m_label = str;
 }
 
 ApiFramebuffer::ApiFramebuffer()
index 3dd0ea58fb54b2434cc94cb549fe22fe5ea1395f..bdf21a38a040d2255f0dc3282a99aa0ebfddd12a 100644 (file)
@@ -34,19 +34,11 @@ class ApiTexture : public ApiSurface
 public:
     ApiTexture();
 
-    int unit() const;
-    void setUnit(int un);
-
-    int level() const;
-    void setLevel(int l);
-
-    QString target() const;
-    void setTarget(const QString &str);
+    QString label() const;
+    void setLabel(const QString &str);
 
 private:
-    int m_unit;
-    int m_level;
-    QString m_target;
+    QString m_label;
 };
 
 class ApiFramebuffer : public ApiSurface
index e26570528574d54a2f0bbe207ec29421d5cd3406..6570368e1e13885668b92e05068d78999f00e20d 100644 (file)
@@ -610,44 +610,32 @@ ApiTraceState::ApiTraceState(const QVariantMap &parsedJson)
         m_shaderSources[type] = source;
     }
 
-    QVariantList textureUnits =
-        parsedJson[QLatin1String("textures")].toList();
-    for (int i = 0; i < textureUnits.count(); ++i) {
-        QVariantMap unit = textureUnits[i].toMap();
-        for (itr = unit.constBegin(); itr != unit.constEnd(); ++itr) {
-            QVariantMap target = itr.value().toMap();
-            if (target.count()) {
-                QVariantList levels = target[QLatin1String("levels")].toList();
-                for (int j = 0; j < levels.count(); ++j) {
-                    QVariantMap level = levels[j].toMap();
-                    QVariantMap image = level[QLatin1String("image")].toMap();
-                    QSize size(image[QLatin1String("__width__")].toInt(),
-                               image[QLatin1String("__height__")].toInt());
-                    QString cls = image[QLatin1String("__class__")].toString();
-                    QString type = image[QLatin1String("__type__")].toString();
-                    bool normalized =
-                        image[QLatin1String("__normalized__")].toBool();
-                    int numChannels =
-                        image[QLatin1String("__channels__")].toInt();
-
-                    Q_ASSERT(type == QLatin1String("uint8"));
-                    Q_ASSERT(normalized == true);
-
-                    QByteArray dataArray =
-                        image[QLatin1String("__data__")].toByteArray();
-
-                    ApiTexture tex;
-                    tex.setSize(size);
-                    tex.setNumChannels(numChannels);
-                    tex.setLevel(j);
-                    tex.setUnit(i);
-                    tex.setTarget(itr.key());
-                    tex.contentsFromBase64(dataArray);
-
-                    m_textures.append(tex);
-                }
-            }
-        }
+    QVariantMap textures =
+        parsedJson[QLatin1String("textures")].toMap();
+    for (itr = textures.constBegin(); itr != textures.constEnd(); ++itr) {
+        QVariantMap image = itr.value().toMap();
+        QSize size(image[QLatin1String("__width__")].toInt(),
+                   image[QLatin1String("__height__")].toInt());
+        QString cls = image[QLatin1String("__class__")].toString();
+        QString type = image[QLatin1String("__type__")].toString();
+        bool normalized =
+            image[QLatin1String("__normalized__")].toBool();
+        int numChannels =
+            image[QLatin1String("__channels__")].toInt();
+
+        Q_ASSERT(type == QLatin1String("uint8"));
+        Q_ASSERT(normalized == true);
+
+        QByteArray dataArray =
+            image[QLatin1String("__data__")].toByteArray();
+
+        ApiTexture tex;
+        tex.setSize(size);
+        tex.setNumChannels(numChannels);
+        tex.setLabel(itr.key());
+        tex.contentsFromBase64(dataArray);
+
+        m_textures.append(tex);
     }
 
     QVariantMap fbos =
index d9f9e38325417ac1e416ca19cad00e1cee157da2..23fa40e4edfaaec84d11047369b552ad98467303 100644 (file)
@@ -497,7 +497,7 @@ void MainWindow::fillStateForFrame()
                 int height = texture.size().height();
                 QString descr =
                     QString::fromLatin1("%1, %2 x %3")
-                    .arg(texture.target())
+                    .arg(texture.label())
                     .arg(width)
                     .arg(height);
                 item->setText(1, descr);