[Piglit] [v10 02/13] util/gl: gl-profile style image probe for gles

Topi Pohjolainen topi.pohjolainen at intel.com
Tue Aug 20 03:16:22 PDT 2013


As GLES reads pixels as non-normalized integers compare the
integers directly instead of transforming to floats first.

v2 (Chad): fix cut-paste error from core-gl - color component
           values for separate and combined alpha/luminance

Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
---
 tests/util/piglit-util-gl-common.h |  2 ++
 tests/util/piglit-util-gles.c      | 65 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index 41f110a..60135c3 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -134,6 +134,8 @@ int piglit_probe_image_color(int x, int y, int w, int h, GLenum format, const fl
 int piglit_probe_image_rgb(int x, int y, int w, int h, const float *image);
 int piglit_probe_image_rgba(int x, int y, int w, int h, const float *image);
 int piglit_probe_image_stencil(int x, int y, int w, int h, const GLubyte *image);
+int piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format,
+			     const GLubyte *image);
 int piglit_probe_texel_rect_rgb(int target, int level, int x, int y,
 				int w, int h, const float *expected);
 int piglit_probe_texel_rgb(int target, int level, int x, int y,
diff --git a/tests/util/piglit-util-gles.c b/tests/util/piglit-util-gles.c
index 385e65e..69e42ba 100644
--- a/tests/util/piglit-util-gles.c
+++ b/tests/util/piglit-util-gles.c
@@ -162,6 +162,71 @@ piglit_probe_rect_rgb(int x, int y, int w, int h, const float *expected)
 	return 1;
 }
 
+static void
+print_pixel(const GLubyte *pixel, unsigned components)
+{
+	int p;
+	for (p = 0; p < components; ++p)
+		printf(" %u", pixel[p]);
+}
+
+unsigned
+piglit_num_components(GLenum base_format)
+{
+	switch (base_format) {
+	case GL_ALPHA:
+	case GL_LUMINANCE:
+		return 1;
+	case GL_LUMINANCE_ALPHA:
+		return 2;
+	case GL_RGB:
+		return 3;
+	case GL_RGBA:
+		return 4;
+	default:
+		printf("Unknown num_components for %s\n",
+		       piglit_get_gl_enum_name(base_format));
+		piglit_report_result(PIGLIT_FAIL);
+		return 0;
+	}
+}
+
+int
+piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format,
+			const GLubyte *image)
+{
+	const int c = piglit_num_components(format);
+	GLubyte *pixels = malloc(w * h * 4 * sizeof(GLubyte));
+	int i, j, p;
+
+	glReadPixels(x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
+
+	for (j = 0; j < h; j++) {
+		for (i = 0; i < w; i++) {
+			const GLubyte *expected = &image[(j * w + i) * c];
+			const GLubyte *probe = &pixels[(j * w + i) * c];
+
+			for (p = 0; p < c; ++p) {
+				if (probe[p] == expected[p])
+					continue;
+
+				printf("Probe at (%i,%i)\n", x + i, y + j);
+				printf("  Expected:");
+				print_pixel(expected, c);
+				printf("\n  Observed:");
+				print_pixel(probe, c);
+				printf("\n");
+
+				free(pixels);
+				return 0;
+			}
+		}
+	}
+
+	free(pixels);
+	return 1;
+}
+
 void
 piglit_escape_exit_key(unsigned char key, int x, int y)
 {
-- 
1.8.3.1



More information about the Piglit mailing list