]> git.cworth.org Git - apitrace/blobdiff - glstate.cpp
Return format info for both textures and framebuffers.
[apitrace] / glstate.cpp
index db1128a9229e2fe8865a7b6713de781410d8b929..0dff118b87dc5558d6f64480a1e0ec9bd2528c90 100644 (file)
@@ -205,10 +205,33 @@ dumpProgramObj(JSONWriter &json, GLhandleARB programObj)
     }
 }
 
+/*
+ * When fetching the uniform name of an array we usually get name[0]
+ * so we need to cut the trailing "[0]" in order to properly construct
+ * array names later. Otherwise we endup with stuff like
+ * uniformArray[0][0],
+ * uniformArray[0][1],
+ * instead of
+ * uniformArray[0],
+ * uniformArray[1].
+ */
+static std::string
+resolveUniformName(const GLchar *name,  GLint size)
+{
+    std::string qualifiedName(name);
+    if (size > 1) {
+        std::string::size_type nameLength = qualifiedName.length();
+        static const char * const arrayStart = "[0]";
+        static const int arrayStartLen = 3;
+        if (qualifiedName.rfind(arrayStart) == (nameLength - arrayStartLen)) {
+            qualifiedName = qualifiedName.substr(0, nameLength - 3);
+        }
+    }
+    return qualifiedName;
+}
 
 static void
 dumpUniform(JSONWriter &json, GLint program, GLint size, GLenum type, const GLchar *name) {
-    
     GLenum elemType;
     GLint numElems;
     __gl_uniform_size(type, elemType, numElems);
@@ -223,9 +246,11 @@ dumpUniform(JSONWriter &json, GLint program, GLint size, GLenum type, const GLch
 
     GLint i, j;
 
+    std::string qualifiedName = resolveUniformName(name, size);
+
     for (i = 0; i < size; ++i) {
         std::stringstream ss;
-        ss << name;
+        ss << qualifiedName;
 
         if (size > 1) {
             ss << '[' << i << ']';
@@ -301,9 +326,11 @@ dumpUniformARB(JSONWriter &json, GLhandleARB programObj, GLint size, GLenum type
 
     GLint i, j;
 
+    std::string qualifiedName = resolveUniformName(name, size);
+
     for (i = 0; i < size; ++i) {
         std::stringstream ss;
-        ss << name;
+        ss << qualifiedName;
 
         if (size > 1) {
             ss << '[' << i << ']';
@@ -541,6 +568,9 @@ static inline void
 dumpTextureImage(JSONWriter &json, GLenum target, GLint level)
 {
     GLint width, height = 1, depth = 1;
+    GLint format;
+
+    glGetTexLevelParameteriv(target, level, GL_TEXTURE_INTERNAL_FORMAT, &format);
 
     width = 0;
     glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
@@ -561,7 +591,8 @@ dumpTextureImage(JSONWriter &json, GLenum target, GLint level)
 
         GLint active_texture = GL_TEXTURE0;
         glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
-        snprintf(label, sizeof label, "%s, %s, level = %i", enumToString(active_texture), enumToString(target), level);
+        snprintf(label, sizeof label, "%s, %s, %s, %d level",
+                 enumToString(active_texture), enumToString(target), enumToString(format), level);
 
         json.beginMember(label);
 
@@ -792,6 +823,25 @@ getTextureLevelSize(GLint texture, GLint level, GLint *width, GLint *height)
 }
 
 
+static GLint
+getTextureLevelFormat(GLint texture, GLint level)
+{
+    GLenum target;
+    GLint bound_texture = 0;
+    if (!bindTexture(texture, target, bound_texture)) {
+        return GL_NONE;
+    }
+
+    GLint format = GL_NONE;
+    glGetTexLevelParameteriv(target, level, GL_TEXTURE_INTERNAL_FORMAT, &format);
+
+    glBindTexture(target, bound_texture);
+
+    return format;
+}
+
+
+
 static bool
 getRenderbufferSize(GLint renderbuffer, GLint *width, GLint *height)
 {
@@ -844,6 +894,47 @@ getFramebufferAttachmentSize(GLenum target, GLenum attachment, GLint *width, GLi
 }
 
 
+
+static GLint
+getFramebufferAttachmentFormat(GLenum target, GLenum attachment)
+{
+    GLint object_type = GL_NONE;
+    glGetFramebufferAttachmentParameteriv(target, attachment,
+                                          GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
+                                          &object_type);
+    if (object_type == GL_NONE) {
+        return GL_NONE;
+    }
+
+    GLint object_name = 0;
+    glGetFramebufferAttachmentParameteriv(target, attachment,
+                                          GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
+                                          &object_name);
+    if (object_name == 0) {
+        return GL_NONE;
+    }
+
+    if (object_type == GL_RENDERBUFFER) {
+        GLint format = GL_NONE;
+        glGetRenderbufferParameteriv(object_name, GL_RENDERBUFFER_INTERNAL_FORMAT,
+                                     &format);
+        return format;
+    } else if (object_type == GL_TEXTURE) {
+        GLint texture_level = 0;
+        glGetFramebufferAttachmentParameteriv(target, attachment,
+                                              GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL,
+                                              &texture_level);
+
+        GLint format = getTextureLevelFormat(object_name, texture_level);
+        return format;
+    } else {
+        std::cerr << "warning: unexpected GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = " << object_type << "\n";
+        return GL_NONE;
+    }
+}
+
+
+
 image::Image *
 getDrawBufferImage(GLenum format) {
     GLint channels = __gl_format_channels(format);
@@ -1131,7 +1222,15 @@ dumpFramebufferAttachment(JSONWriter &json, GLenum target, GLenum attachment, GL
         return;
     }
 
-    json.beginMember(enumToString(attachment));
+    GLint internalFormat = getFramebufferAttachmentFormat(target, attachment);
+    std::stringstream ss;
+    ss << enumToString(attachment);
+    if (internalFormat != GL_NONE) {
+        ss << ", ";
+        ss << enumToString(internalFormat);
+    }
+
+    json.beginMember(ss.str());
     dumpReadBufferImage(json, width, height, format);
     json.endMember();
 }