<div dir="ltr"><div><div>Looks good.<br><br></div>Reviewed-by: Brian Paul <<a href="mailto:brianp@vmware.com">brianp@vmware.com</a>><br><br></div>Sorry for being slow.  I'm on vacation this week.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 16, 2016 at 8:25 AM, Marek Olšák <span dir="ltr"><<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Marek Olšák <<a href="mailto:marek.olsak@amd.com">marek.olsak@amd.com</a>><br>
<br>
v2: int -> bool, unify all new functions into one<br>
---<br>
 tests/util/piglit-util-gl.c | 94 +++++++++++++++++++++++++++++++++++++++++++++<br>
 1 file changed, 94 insertions(+)<br>
<br>
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c<br>
index e8a47c5..09eb99d 100644<br>
--- a/tests/util/piglit-util-gl.c<br>
+++ b/tests/util/piglit-util-gl.c<br>
@@ -1060,6 +1060,23 @@ piglit_read_pixels_float(GLint x, GLint y, GLsizei width, GLsizei height,<br>
        return pixels;<br>
 }<br>
<br>
+static bool<br>
+piglit_can_probe_ubyte()<br>
+{<br>
+       int r,g,b,a;<br>
+<br>
+       glGetIntegerv(GL_RED_BITS, &r);<br>
+       glGetIntegerv(GL_GREEN_BITS, &g);<br>
+       glGetIntegerv(GL_BLUE_BITS, &b);<br>
+       glGetIntegerv(GL_ALPHA_BITS, &a);<br>
+<br>
+       /* it could be LUMINANCE32F, etc. */<br>
+       if (!r && !g && !b && !a)<br>
+               return false;<br>
+<br>
+       return r <= 8 && g <= 8 && b <= 8 && a <= 8;<br>
+}<br>
+<br>
 int<br>
 piglit_probe_pixel_rgb_silent(int x, int y, const float* expected, float *out_probe)<br>
 {<br>
@@ -1158,6 +1175,74 @@ piglit_probe_pixel_rgba(int x, int y, const float* expected)<br>
        return 0;<br>
 }<br>
<br>
+static void<br>
+piglit_array_float_to_ubyte(int n, const float *f, GLubyte *b)<br>
+{<br>
+       int i;<br>
+<br>
+       for (i = 0; i < n; i++)<br>
+               b[i] = f[i] * 255;<br>
+}<br>
+<br>
+static void<br>
+piglit_array_float_to_ubyte_roundup(int n, const float *f, GLubyte *b)<br>
+{<br>
+       int i;<br>
+<br>
+       for (i = 0; i < n; i++)<br>
+               b[i] = ceil(f[i] * 255);<br>
+}<br>
+<br>
+static bool<br>
+piglit_probe_rect_ubyte(int x, int y, int w, int h, int num_components,<br>
+                       const float *fexpected, bool silent)<br>
+{<br>
+       int i, j, p;<br>
+       GLubyte *probe;<br>
+       GLubyte *pixels;<br>
+       GLubyte tolerance[4];<br>
+       GLubyte expected[4];<br>
+<br>
+       piglit_array_float_to_ubyte_roundup(num_components, piglit_tolerance, tolerance);<br>
+       piglit_array_float_to_ubyte(num_components, fexpected, expected);<br>
+<br>
+       /* RGBA readbacks are likely to be faster */<br>
+       pixels = malloc(w*h*4);<br>
+       glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);<br>
+<br>
+       for (j = 0; j < h; j++) {<br>
+               for (i = 0; i < w; i++) {<br>
+                       probe = &pixels[(j*w+i)*4];<br>
+<br>
+                       for (p = 0; p < num_components; ++p) {<br>
+                               if (abs((int)probe[p] - (int)expected[p]) >= tolerance[p]) {<br>
+                                       if (!silent) {<br>
+                                               printf("Probe color at (%i,%i)\n", x+i, y+j);<br>
+                                               if (num_components == 4) {<br>
+                                                       printf("  Expected: %u %u %u %u\n",<br>
+                                                              expected[0], expected[1],<br>
+                                                              expected[2], expected[3]);<br>
+                                                       printf("  Observed: %u %u %u %u\n",<br>
+                                                              probe[0], probe[1], probe[2], probe[3]);<br>
+                                               } else {<br>
+                                                       printf("  Expected: %u %u %u\n",<br>
+                                                              expected[0], expected[1],<br>
+                                                              expected[2]);<br>
+                                                       printf("  Observed: %u %u %u\n",<br>
+                                                              probe[0], probe[1], probe[2]);<br>
+                                               }<br>
+                                       }<br>
+                                       free(pixels);<br>
+                                       return false;<br>
+                               }<br>
+                       }<br>
+               }<br>
+       }<br>
+<br>
+       free(pixels);<br>
+       return true;<br>
+}<br>
+<br>
 int<br>
 piglit_probe_rect_rgb_silent(int x, int y, int w, int h, const float *expected)<br>
 {<br>
@@ -1165,6 +1250,9 @@ piglit_probe_rect_rgb_silent(int x, int y, int w, int h, const float *expected)<br>
        GLfloat *probe;<br>
        GLfloat *pixels;<br>
<br>
+       if (piglit_can_probe_ubyte())<br>
+               return piglit_probe_rect_ubyte(x, y, w, h, 3, expected, true);<br>
+<br>
        pixels = piglit_read_pixels_float(x, y, w, h, GL_RGB, NULL);<br>
<br>
        for (j = 0; j < h; j++) {<br>
@@ -1223,6 +1311,9 @@ piglit_probe_rect_rgb(int x, int y, int w, int h, const float *expected)<br>
        GLfloat *probe;<br>
        GLfloat *pixels;<br>
<br>
+       if (piglit_can_probe_ubyte())<br>
+               return piglit_probe_rect_ubyte(x, y, w, h, 3, expected, false);<br>
+<br>
        pixels = piglit_read_pixels_float(x, y, w, h, GL_RGBA, NULL);<br>
<br>
        for (j = 0; j < h; j++) {<br>
@@ -1290,6 +1381,9 @@ piglit_probe_rect_rgba(int x, int y, int w, int h, const float *expected)<br>
        GLfloat *probe;<br>
        GLfloat *pixels;<br>
<br>
+       if (piglit_can_probe_ubyte())<br>
+               return piglit_probe_rect_ubyte(x, y, w, h, 4, expected, false);<br>
+<br>
        pixels = piglit_read_pixels_float(x, y, w, h, GL_RGBA, NULL);<br>
<br>
        for (j = 0; j < h; j++) {<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0<br>
<br>
_______________________________________________<br>
Piglit mailing list<br>
<a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/piglit" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</font></span></blockquote></div><br></div>