]> git.cworth.org Git - apitrace/blobdiff - retrace/glstate_images.cpp
glstate: Dump more object labels.
[apitrace] / retrace / glstate_images.cpp
index 6efc0a677ba24c1e287d776b0a9378cab6c56e61..b055002977d3c351e7b0cf014b45455df1ac6160 100644 (file)
@@ -59,11 +59,6 @@ OSStatus CGSGetSurfaceBounds(CGSConnectionID, CGWindowID, CGSSurfaceID, CGRect *
 #endif /* __APPLE__ */
 
 
-/* Change thi to one to force interpreting depth buffers as RGBA, which enables
- * visualizing full dynamic range, until we can transmit HDR images to the GUI */
-#define DEPTH_AS_RGBA 0
-
-
 namespace glstate {
 
 
@@ -511,6 +506,10 @@ internalFormatDescs[] = {
 };
 
 
+/**
+ * Choose the glReadPixels/glGetTexImage format appropriate for the given
+ * internalFormat.
+ */
 static GLenum
 getFormat(GLenum internalFormat)
 {
@@ -539,11 +538,11 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
 
     json.beginMember(label);
 
-    GLenum format = getFormat(desc.internalFormat);;
+    GLenum format = getFormat(desc.internalFormat);
     if (context.ES && format == GL_DEPTH_COMPONENT) {
         format = GL_RED;
     }
-    GLuint channels = _gl_format_channels(format);;
+    GLuint channels = _gl_format_channels(format);
 
     image::Image *image = new image::Image(desc.width, desc.height*desc.depth, channels, true);
 
@@ -935,15 +934,15 @@ getDrawBufferImage() {
     }
 
     GLenum type = GL_UNSIGNED_BYTE;
+    image::ChannelType channelType = image::TYPE_UNORM8;
 
-#if DEPTH_AS_RGBA
     if (format == GL_DEPTH_COMPONENT) {
-        type = GL_UNSIGNED_INT;
-        channels = 4;
+        type = GL_FLOAT;
+        channels = 1;
+        channelType = image::TYPE_FLOAT;
     }
-#endif
 
-    image::Image *image = new image::Image(desc.width, desc.height, channels, true);
+    image::Image *image = new image::Image(desc.width, desc.height, channels, true, channelType);
     if (!image) {
         return NULL;
     }
@@ -1002,15 +1001,15 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format,
     Context context;
 
     GLenum type = GL_UNSIGNED_BYTE;
+    image::ChannelType channelType = image::TYPE_UNORM8;
 
-#if DEPTH_AS_RGBA
     if (format == GL_DEPTH_COMPONENT) {
-        type = GL_UNSIGNED_INT;
-        channels = 4;
+        type = GL_FLOAT;
+        channels = 1;
+        channelType = image::TYPE_FLOAT;
     }
-#endif
 
-    image::Image *image = new image::Image(width, height, channels, true);
+    image::Image *image = new image::Image(width, height, channels, true, channelType);
 
     while (glGetError() != GL_NO_ERROR) {}
 
@@ -1194,7 +1193,7 @@ dumpDrawableImages(JSONWriter &json, Context &context)
  * In the case of a color attachment, it assumes it is already bound for read.
  */
 static void
-dumpFramebufferAttachment(JSONWriter &json, Context &context, GLenum target, GLenum attachment, GLenum format)
+dumpFramebufferAttachment(JSONWriter &json, Context &context, GLenum target, GLenum attachment, GLenum format = GL_NONE)
 {
     ImageDesc desc;
     if (!getFramebufferAttachmentDesc(context, target, attachment, desc)) {
@@ -1203,6 +1202,11 @@ dumpFramebufferAttachment(JSONWriter &json, Context &context, GLenum target, GLe
 
     assert(desc.samples == 0);
 
+    if (format == GL_NONE) {
+        assert(desc.internalFormat != GL_NONE);
+        format = getFormat(desc.internalFormat);
+    }
+
     json.beginMember(enumToString(attachment));
     dumpReadBufferImage(json, desc.width, desc.height, format, desc.internalFormat);
     json.endMember();
@@ -1235,12 +1239,7 @@ dumpFramebufferAttachments(JSONWriter &json, Context &context, GLenum target)
                 std::cerr << "warning: unexpected GL_DRAW_BUFFER" << i << " = " << draw_buffer << "\n";
                 attachment = GL_COLOR_ATTACHMENT0;
             }
-            GLint alpha_size = 0;
-            glGetFramebufferAttachmentParameteriv(target, attachment,
-                                                  GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE,
-                                                  &alpha_size);
-            GLenum format = alpha_size ? GL_RGBA : GL_RGB;
-            dumpFramebufferAttachment(json, context, target, attachment, format);
+            dumpFramebufferAttachment(json, context, target, attachment);
         }
     }