]> git.cworth.org Git - apitrace/commitdiff
Ignore alpha channels in window drawables until we are able to match the traced visuals.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 20 Jan 2012 18:30:06 +0000 (18:30 +0000)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 20 Jan 2012 18:30:06 +0000 (18:30 +0000)
common/image.cpp
glretrace_main.cpp
glstate.cpp
glstate.hpp

index 0cb38ed3d5fdcce5a947ac06fd9b4583379a0a75..e69231332a7b6f413edc397b7e8e1f12764bd03f 100644 (file)
@@ -28,6 +28,8 @@
 #include <assert.h>
 #include <math.h>
 
+#include <algorithm>
+
 #include "image.hpp"
 
 
@@ -38,22 +40,28 @@ double Image::compare(Image &ref)
 {
     if (width != ref.width ||
         height != ref.height ||
-        channels != ref.channels) {
+        channels < 3 ||
+        ref.channels < 3) {
+        return 0.0;
+    }
+
+    // Ignore missing alpha when comparing RGB w/ RGBA, but enforce an equal
+    // number of channels otherwise.
+    unsigned minChannels = std::min(channels, ref.channels);
+    if (channels != ref.channels && minChannels < 3) {
         return 0.0;
     }
 
     const unsigned char *pSrc = start();
     const unsigned char *pRef = ref.start();
 
-    assert(channels >= 3);
-
     unsigned long long error = 0;
     for (unsigned y = 0; y < height; ++y) {
         for (unsigned  x = 0; x < width; ++x) {
             // FIXME: Ignore alpha channel until we are able to pick a visual
             // that matches the traces
-            for (unsigned  c = 0; c < 3; ++c) {
-                int delta = pSrc[x*channels + c] - pRef[x*channels + c];
+            for (unsigned  c = 0; c < minChannels; ++c) {
+                int delta = pSrc[x*channels + c] - pRef[x*ref.channels + c];
                 error += delta*delta;
             }
         }
@@ -63,7 +71,7 @@ double Image::compare(Image &ref)
     }
 
     double numerator = error*2 + 1;
-    double denominator = height*width*3ULL*255ULL*255ULL*2;
+    double denominator = height*width*minChannels*255ULL*255ULL*2;
     double quotient = numerator/denominator;
 
     // Precision in bits
index c2ca664239500d76d7d0dc2390533d80139a99f7..12086321bd3a2bc94ef11a1b024e62ebecbe96c2 100644 (file)
@@ -157,7 +157,7 @@ void snapshot(unsigned call_no) {
         }
     }
 
-    image::Image *src = glstate::getDrawBufferImage(GL_RGBA);
+    image::Image *src = glstate::getDrawBufferImage();
     if (!src) {
         return;
     }
index 329276ffdf0b38e9ba8e91fcb9a36241b80c91c8..d54764ce7bf5e8b6c9b8db59bc420e88bebfa5a0 100644 (file)
@@ -953,7 +953,8 @@ getFramebufferAttachmentFormat(GLenum target, GLenum attachment)
 
 
 image::Image *
-getDrawBufferImage(GLenum format) {
+getDrawBufferImage() {
+    GLenum format = GL_RGB;
     GLint channels = __gl_format_channels(format);
     if (channels > 4) {
         return NULL;
@@ -1204,7 +1205,10 @@ dumpDrawableImages(JSONWriter &json)
         glGetIntegerv(GL_READ_BUFFER, &read_buffer);
 
         GLint alpha_bits = 0;
+#if 0
+        // XXX: Ignore alpha until we are able to match the traced visual
         glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
+#endif
         GLenum format = alpha_bits ? GL_RGBA : GL_RGB;
         json.beginMember(enumToString(draw_buffer));
         dumpReadBufferImage(json, width, height, format);
@@ -1229,6 +1233,8 @@ dumpDrawableImages(JSONWriter &json)
         json.endMember();
     }
 }
+
+
 /**
  * Dump the specified framebuffer attachment.
  *
index 67044351228978d8bdc2309c54884cc59a4e2485..0a83a599a098b00828137c53ef93bf87fd897b8e 100644 (file)
@@ -52,7 +52,7 @@ void dumpParameters(JSONWriter &json);
 void dumpCurrentContext(std::ostream &os);
 
 image::Image *
-getDrawBufferImage(GLenum format);
+getDrawBufferImage(void);
 
 
 } /* namespace glstate */