[Piglit] [PATCH 2/3] util: Add stencil probe functions

Chad Versace chad at chad-versace.us
Thu May 19 07:55:14 PDT 2011


Add functions:
    piglit_probe_pixel_stencil
    piglit_probe_rect_stencil

Signed-off-by: Chad Versace <chad.versace at intel.com>
---
 tests/util/piglit-util-gl.c |   39 +++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util.h    |    2 ++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 77a9cc4..7a2a45b 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -323,6 +323,45 @@ int piglit_probe_rect_depth(int x, int y, int w, int h, float expected)
 	return 1;
 }
 
+int piglit_probe_pixel_stencil(int x, int y, unsigned expected)
+{
+	GLuint probe;
+	glReadPixels(x, y, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_INT, &probe);
+
+	if (probe == expected)
+		return 1;
+
+	printf("Probe at (%i, %i)\n", x, y);
+	printf("  Expected: %u\n", expected);
+	printf("  Observed: %u\n", probe);
+
+	return 0;
+}
+
+int piglit_probe_rect_stencil(int x, int y, int w, int h, unsigned expected)
+{
+	int i, j;
+	GLuint *pixels = malloc(w*h*sizeof(GLuint));
+
+	glReadPixels(x, y, w, h, GL_STENCIL_INDEX, GL_UNSIGNED_INT, pixels);
+
+	for (j = 0; j < h; j++) {
+		for (i = 0; i < w; i++) {
+			GLuint probe = pixels[j * w + i];
+			if (probe != expected) {
+				printf("Probe at (%i, %i)\n", x + i, y + j);
+				printf("  Expected: %u\n", expected);
+				printf("  Observed: %u\n", probe);
+				free(pixels);
+				return 0;
+			}
+		}
+	}
+
+	free(pixels);
+	return 1;
+}
+
 /**
  * Read a texel rectangle from the given location and compare its RGBA value to
  * the given expected values.
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 8e7b262..f16d785 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -123,6 +123,8 @@ int piglit_probe_texel_rgba(int target, int level, int x, int y,
 			    const float* expected);
 int piglit_probe_pixel_depth(int x, int y, float expected);
 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_use_fragment_program(void);
-- 
1.7.5.1



More information about the Piglit mailing list