[Piglit] [PATCH 1/4] util: Add a piglit_probe_image_stencil() function.
Paul Berry
stereotype441 at gmail.com
Wed Sep 5 14:59:31 PDT 2012
---
tests/util/piglit-util-gl-common.h | 1 +
tests/util/piglit-util-gl.c | 55 ++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index d2e6b3e..c5e814c 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -119,6 +119,7 @@ int piglit_compare_images_color(int x, int y, int w, int h, int num_components,
int piglit_probe_image_color(int x, int y, int w, int h, GLenum format, const float *image);
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_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-gl.c b/tests/util/piglit-util-gl.c
index e91dfc2..cfdf3fd 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -301,6 +301,33 @@ piglit_compare_images_color(int x, int y, int w, int h, int num_components,
}
/**
+ * Compare two in-memory unsigned-byte images.
+ */
+int
+piglit_compare_images_ubyte(int x, int y, int w, int h,
+ const GLubyte *expected_image,
+ const GLubyte *observed_image)
+{
+ int i, j;
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
+ const GLubyte expected = expected_image[j*w+i];
+ const GLubyte probe = observed_image[j*w+i];
+
+ if (probe != expected) {
+ printf("Probe at (%i,%i)\n", x+i, y+j);
+ printf(" Expected: %d\n", expected);
+ printf(" Observed: %d\n", probe);
+
+ return 0;
+ }
+ }
+ }
+
+ return 1;
+}
+
+/**
* Compare the contents of the current read framebuffer with the given
* in-memory floating-point image.
*/
@@ -331,6 +358,34 @@ piglit_probe_image_color(int x, int y, int w, int h, GLenum format,
return result;
}
+/**
+ * Compare the contents of the current read framebuffer's stencil
+ * buffer with the given in-memory byte image.
+ */
+int
+piglit_probe_image_stencil(int x, int y, int w, int h,
+ const GLubyte *image)
+{
+ GLubyte *pixels = malloc(w*h*sizeof(GLubyte));
+ int result;
+ GLint old_pack_alignment;
+
+ /* Temporarily set pack alignment to 1 so that glReadPixels
+ * won't put any padding at the end of the row.
+ */
+ glGetIntegerv(GL_PACK_ALIGNMENT, &old_pack_alignment);
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+
+ glReadPixels(x, y, w, h, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, pixels);
+
+ glPixelStorei(GL_PACK_ALIGNMENT, old_pack_alignment);
+
+ result = piglit_compare_images_ubyte(x, y, w, h, image, pixels);
+
+ free(pixels);
+ return result;
+}
+
int
piglit_probe_image_rgb(int x, int y, int w, int h, const float *image)
{
--
1.7.7.6
More information about the Piglit
mailing list