[Piglit] [PATCH 1/9] util: Add probe function to test for two colors.
Fabian Bieler
fabianbieler at fastmail.fm
Mon Jun 24 15:30:38 PDT 2013
Add piglit_probe_rect_two_rgba.
This probe functions tests that all pixels in a rectangle are one of two
specified colors.
This is useful to test that two draw operations behave identically:
To use it clear the framebuffer, enable blending and make each draw operation
paint one color channel.
Then call piglit_probe_rect_two_rgba to determine that the framebuffer is either
the clear color or the combined color of both operations.
---
tests/util/piglit-util-gl-common.c | 51 ++++++++++++++++++++++++++++++++++++++
tests/util/piglit-util-gl-common.h | 2 ++
2 files changed, 53 insertions(+)
diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c
index 82ae820..0a01d5c 100644
--- a/tests/util/piglit-util-gl-common.c
+++ b/tests/util/piglit-util-gl-common.c
@@ -440,6 +440,57 @@ piglit_probe_rect_halves_equal_rgba(int x, int y, int w, int h)
/**
+ * Checks that all pixels in a rectangular part of the framebuffer are one of
+ * two colors.
+ * \param x, y, w, h the rectangle to test
+ * \param expected1, expected2 the two expected colors
+ * \return 1 if all pixels in the rectangle are one of the expected colors,
+ * 0 otherwise.
+ */
+int
+piglit_probe_rect_two_rgba(int x, int y, int w, int h,
+ const float* expected1, const float* expected2)
+{
+ int i, j, p;
+ GLubyte *probe;
+ GLubyte *pixels = malloc(w*h*4*sizeof(GLubyte));
+
+ glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
+ probe = &pixels[(j*w+i)*4];
+
+ for (p = 0; p < 4; ++p) {
+ if ((fabs(probe[p]/255.0 - expected1[p]) <
+ piglit_tolerance[p]) ||
+ (fabs(probe[p]/255.0 - expected2[p]) <
+ piglit_tolerance[p]))
+ continue;
+
+ printf("Probe color at (%i,%i)\n", x+i, y+j);
+ printf(" Expected: %f %f %f %f\n",
+ expected1[0], expected1[1],
+ expected1[2], expected1[3]);
+ printf(" or: %f %f %f %f\n",
+ expected2[0], expected2[1],
+ expected2[2], expected2[3]);
+ printf(" Observed: %f %f %f %f\n",
+ probe[0]/255.0, probe[1]/255.0,
+ probe[2]/255.0, probe[3]/255.0);
+
+ free(pixels);
+ return 0;
+ }
+ }
+ }
+
+ free(pixels);
+ return 1;
+}
+
+
+/**
* Return block size info for a specific texture compression format.
* \param bw returns the block width, in pixels
* \param bh returns the block height, in pixels
diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index aa21391..02eeae7 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -145,6 +145,8 @@ int piglit_probe_rect_depth(int x, int y, int w, int h, float expected);
int piglit_probe_pixel_stencil(int x, int y, unsigned expected);
int piglit_probe_rect_stencil(int x, int y, int w, int h, unsigned expected);
int piglit_probe_rect_halves_equal_rgba(int x, int y, int w, int h);
+int piglit_probe_rect_two_rgba(int x, int y, int w, int h,
+ const float* expected1, const float* expected2);
int piglit_use_fragment_program(void);
int piglit_use_vertex_program(void);
--
1.8.1.2
More information about the Piglit
mailing list