From 18081d51fb0a0a5b1b7cb9fa2923339fae58de7b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sat, 7 May 2011 00:10:25 +0100 Subject: [PATCH] Linearize texture data in JSON. --- glstate.py | 47 ++++++++++++-------------------- gui/apisurface.cpp | 32 ++++------------------ gui/apisurface.h | 14 +++------- gui/apitracecall.cpp | 64 ++++++++++++++++++-------------------------- gui/mainwindow.cpp | 2 +- 5 files changed, 52 insertions(+), 107 deletions(-) diff --git a/glstate.py b/glstate.py index 5f7416b..2ab7f28 100644 --- a/glstate.py +++ b/glstate.py @@ -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 diff --git a/gui/apisurface.cpp b/gui/apisurface.cpp index 1123ead..64aa153 100644 --- a/gui/apisurface.cpp +++ b/gui/apisurface.cpp @@ -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() diff --git a/gui/apisurface.h b/gui/apisurface.h index 3dd0ea5..bdf21a3 100644 --- a/gui/apisurface.h +++ b/gui/apisurface.h @@ -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 diff --git a/gui/apitracecall.cpp b/gui/apitracecall.cpp index e265705..6570368 100644 --- a/gui/apitracecall.cpp +++ b/gui/apitracecall.cpp @@ -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 = diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d9f9e38..23fa40e 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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); -- 2.43.0