summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Bieler <fabianbieler@fastmail.fm>2017-12-29 15:41:02 +0100
committerFabian Bieler <fabianbieler@fastmail.fm>2018-01-16 20:10:43 +0100
commit748b62a81d1b77cd5a78988245a32cf24566c205 (patch)
tree7f3b644b271699a11dbab13faa4464cd7c46c298
parent096b19c7ca88012c7169f1fe06219600afadbdfa (diff)
util-gl: Add piglit_probe_rect_two_rgb.
Read color data from the given rectangle and compare its RGB value to the given two expected values. Print a log message if the color value deviates from both expected values. Return true if the color values match, false otherwise. This is useful to compare two renders drawn on top of each other with blending. Reviewed-by: Brian Paul <brianp@vmware.com>
-rw-r--r--tests/util/piglit-util-gl.c50
-rw-r--r--tests/util/piglit-util-gl.h3
2 files changed, 53 insertions, 0 deletions
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 8fe5f9849..87ea665ea 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -1519,6 +1519,56 @@ print_pixel_float(const float *pixel, unsigned components)
printf(" %f", pixel[p]);
}
+static bool
+compare_pixels_float(const float *color1, const float *color2,
+ int components)
+{
+ for (int p = 0; p < components; ++p)
+ if (fabsf(color1[p] - color2[p]) > piglit_tolerance[p])
+ return false;
+ return true;
+}
+
+/**
+ * Read color data from the given rectangle and compare its RGB value to the
+ * given two expected values.
+ *
+ * Print a log message if the color value deviates from both expected values.
+ * \return true if the color values match, false otherwise
+ */
+bool
+piglit_probe_rect_two_rgb(int x, int y, int w, int h,
+ const float *expected1, const float *expected2)
+{
+ /* RGBA readbacks are likely to be faster */
+ float *pixels = piglit_read_pixels_float(x, y, w, h, GL_RGBA, NULL);
+
+ for (int j = 0; j < h; j++) {
+ for (int i = 0; i < w; i++) {
+ float *probe = &pixels[(j * w + i) * 4];
+
+ if (compare_pixels_float(probe, expected1, 3) ||
+ compare_pixels_float(probe, expected2, 3))
+ continue;
+
+ printf("Probe color at (%i,%i)\n", x + i, y + j);
+ printf(" Expected either:");
+ print_pixel_float(expected1, 3);
+ printf("\n or:");
+ print_pixel_float(expected2, 3);
+ printf("\n Observed:");
+ print_pixel_float(probe, 3);
+ printf("\n");
+
+ free(pixels);
+ return false;
+ }
+ }
+
+ free(pixels);
+ return true;
+}
+
/**
* Compute the appropriate tolerance for comparing images of the given
* base format.
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 73a38f7ff..7b1cee564 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -152,6 +152,9 @@ int piglit_probe_rect_rgb_silent(int x, int y, int w, int h, const float *expect
int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
int piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int* expected);
int piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int* expected);
+bool piglit_probe_rect_two_rgb(int x, int y, int w, int h,
+ const float *expected1,
+ const float *expected2);
void piglit_compute_probe_tolerance(GLenum format, float *tolerance);
/**