[Piglit] [v9 02/13] framework: gl-profile style image probe for gles
Topi Pohjolainen
topi.pohjolainen at intel.com
Fri Aug 9 03:42:56 PDT 2013
As GLES reads pixels as non-normalized integers compare the
integers directly instead of transforming to floats first.
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
tests/util/piglit-util-gl-common.h | 2 ++
tests/util/piglit-util-gles.c | 63 ++++++++++++++++++++++++++++++++++++++
2 files changed, 65 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..8c2eadc 100644
--- a/tests/util/piglit-util-gles.c
+++ b/tests/util/piglit-util-gles.c
@@ -162,6 +162,69 @@ 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:
+ case GL_LUMINANCE_ALPHA:
+ 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.1.2
More information about the Piglit
mailing list