]> git.cworth.org Git - apitrace/blobdiff - retrace/glstate_images.cpp
glstate: Cleanup the read buffer selection code slightly.
[apitrace] / retrace / glstate_images.cpp
index f46028588bb23f62ae27d83d847cca7436e38a35..598d56cceb8e2746bec9e22fc519609d33667b64 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <algorithm>
 #include <iostream>
-#include <sstream>
 
 #include "image.hpp"
 #include "json.hpp"
@@ -388,7 +387,6 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
     }
 
     char label[512];
-
     GLint active_texture = GL_TEXTURE0;
     glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
     snprintf(label, sizeof label, "%s, %s, level = %d",
@@ -396,8 +394,6 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
 
     json.beginMember(label);
 
-    json.beginObject();
-
     GLuint channels;
     GLenum format;
     if (!context.ES && isDepthFormat(desc.internalFormat)) {
@@ -408,15 +404,6 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
        channels = 4;
     }
 
-    // Tell the GUI this is no ordinary object, but an image
-    json.writeStringMember("__class__", "image");
-
-    json.writeIntMember("__width__", desc.width);
-    json.writeIntMember("__height__", desc.height);
-    json.writeIntMember("__depth__", desc.depth);
-
-    json.writeStringMember("__format__", formatToString(desc.internalFormat));
-
     image::Image *image = new image::Image(desc.width, desc.height*desc.depth, channels, true);
 
     context.resetPixelPackState();
@@ -429,15 +416,11 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
 
     context.restorePixelPackState();
 
-    json.beginMember("__data__");
-    std::stringstream ss;
-    image->writePNG(ss);
-    const std::string & s = ss.str();
-    json.writeBase64(s.data(), s.size());
-    json.endMember(); // __data__
+    json.writeImage(image, formatToString(desc.internalFormat), desc.depth);
 
     delete image;
-    json.endObject();
+
+    json.endMember(); // label
 }
 
 
@@ -762,13 +745,22 @@ getDrawBufferImage() {
             if (draw_buffer == GL_NONE) {
                 return NULL;
             }
+        } else {
+            // GL_COLOR_ATTACHMENT0 is implied
+            draw_buffer = GL_COLOR_ATTACHMENT0;
         }
 
         if (!getFramebufferAttachmentDesc(context, framebuffer_target, draw_buffer, desc)) {
             return NULL;
         }
     } else {
-        if (!context.ES) {
+        if (context.ES) {
+            // XXX: Draw buffer is always FRONT for single buffer context, BACK
+            // for double buffered contexts. There is no way to know which (as
+            // GL_DOUBLEBUFFER state is also unavailable), so always assume
+            // double-buffering.
+            draw_buffer = GL_BACK;
+        } else {
             glGetIntegerv(GL_DRAW_BUFFER, &draw_buffer);
             if (draw_buffer == GL_NONE) {
                 return NULL;
@@ -849,17 +841,6 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format,
 
     Context context;
 
-    json.beginObject();
-
-    // Tell the GUI this is no ordinary object, but an image
-    json.writeStringMember("__class__", "image");
-
-    json.writeIntMember("__width__", width);
-    json.writeIntMember("__height__", height);
-    json.writeIntMember("__depth__", 1);
-
-    json.writeStringMember("__format__", formatToString(internalFormat));
-
     GLenum type = GL_UNSIGNED_BYTE;
 
 #if DEPTH_AS_RGBA
@@ -878,15 +859,9 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format,
 
     context.restorePixelPackState();
 
-    json.beginMember("__data__");
-    std::stringstream ss;
-    image->writePNG(ss);
-    const std::string & s = ss.str();
-    json.writeBase64(s.data(), s.size());
-    json.endMember(); // __data__
+    json.writeImage(image, formatToString(internalFormat));
 
     delete image;
-    json.endObject();
 }
 
 
@@ -1002,16 +977,21 @@ dumpDrawableImages(JSONWriter &json, Context &context)
 
     GLint draw_buffer = GL_NONE;
     if (context.ES) {
+        // XXX: Draw buffer is always FRONT for single buffer context, BACK for
+        // double buffered contexts. There is no way to know which (as
+        // GL_DOUBLEBUFFER state is also unavailable), so always assume
+        // double-buffering.
         draw_buffer = GL_BACK;
     } else {
         glGetIntegerv(GL_DRAW_BUFFER, &draw_buffer);
-        glReadBuffer(draw_buffer);
     }
 
     if (draw_buffer != GL_NONE) {
+        // Read from current draw buffer
         GLint read_buffer = GL_NONE;
         if (!context.ES) {
             glGetIntegerv(GL_READ_BUFFER, &read_buffer);
+            glReadBuffer(draw_buffer);
         }
 
         GLint alpha_bits = 0;
@@ -1024,6 +1004,7 @@ dumpDrawableImages(JSONWriter &json, Context &context)
         dumpReadBufferImage(json, width, height, format);
         json.endMember();
 
+        // Restore original read buffer
         if (!context.ES) {
             glReadBuffer(read_buffer);
         }