[Piglit] [PATCH] Add functions to probe int, uint rgba buffer data

Anuj Phogat anuj.phogat at gmail.com
Mon Dec 19 13:59:01 PST 2011


Added functions are: piglit_probe_rect_color_rgba_int() and
piglit_probe_rect_color_rgba_uint()

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
Thanks for the comments Brian. Here is the updated patch.

 tests/spec/gl-3.0/api/clearbuffer-common.c |   29 +++++++++++++
 tests/spec/gl-3.0/api/clearbuffer-common.h |    4 ++
 tests/util/piglit-util-gl.c                |   64 ++++++++++++++++++++++++++++
 tests/util/piglit-util.h                   |    2 +
 4 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.c b/tests/spec/gl-3.0/api/clearbuffer-common.c
index 0c1fc06..285417e 100644
--- a/tests/spec/gl-3.0/api/clearbuffer-common.c
+++ b/tests/spec/gl-3.0/api/clearbuffer-common.c
@@ -173,6 +173,35 @@ simple_probe(bool color, const float *color_value,
 	return pass;
 }
 
+/* Read pixel color values from float, integer or unsigned integer color
+ * buffer types
+ */
+bool
+probe_rect_color(int x, int y, int w, int h, GLenum type, const GLvoid *refcolor)
+{
+	assert( type == GL_INT || type == GL_UNSIGNED_INT || type == GL_FLOAT);
+
+	if (type == GL_FLOAT) {
+		if (!piglit_probe_rect_rgba(x, y,
+					    w, h,
+					    (GLfloat*)refcolor))
+			return false;
+	}
+	else if (type == GL_UNSIGNED_INT) {
+		if (!piglit_probe_rect_rgba_uint(x, y,
+					    w, h,
+					    (GLuint*)refcolor))
+			return false;
+	}
+	else if (type == GL_INT) {
+		if (!piglit_probe_rect_rgba_int(x, y,
+					    w, h,
+					    (GLint*)refcolor))
+			return false;
+	}
+	return true;
+}
+
 enum piglit_result
 piglit_display(void)
 {
diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.h b/tests/spec/gl-3.0/api/clearbuffer-common.h
index e5afc51..6ffcf3a 100644
--- a/tests/spec/gl-3.0/api/clearbuffer-common.h
+++ b/tests/spec/gl-3.0/api/clearbuffer-common.h
@@ -31,3 +31,7 @@ extern bool
 simple_probe(bool color, const float *color_value,
 	     bool stencil, int stencil_value,
 	     bool depth, float depth_value);
+
+extern bool
+probe_rect_color(int x, int y, int width, int height,
+		 GLenum type, const GLvoid *refcolor);
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 2a88ef5..defcc05 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -142,6 +142,70 @@ piglit_probe_rect_rgba(int x, int y, int w, int h, const float *expected)
 }
 
 int
+piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int *expected)
+{
+	int i, j, p;
+	GLint *probe;
+	GLint *pixels = malloc(w*h*4*sizeof(int));
+
+	glReadPixels(x, y, w, h, GL_RGBA_INTEGER, GL_INT, pixels);
+
+	for (j = 0; j < h; j++) {
+		for (i = 0; i < w; i++) {
+			probe = &pixels[(j*w+i)*4];
+
+			for (p = 0; p < 4; ++p) {
+				if (fabs(probe[p] - expected[p]) >= piglit_tolerance[p]) {
+					printf("Probe at (%d,%d)\n", x+i, y+j);
+					printf("  Expected: %d %d %d %d\n",
+					       expected[0], expected[1], expected[2], expected[3]);
+					printf("  Observed: %d %d %d %d\n",
+					       probe[0], probe[1], probe[2], probe[3]);
+
+					free(pixels);
+					return 0;
+				}
+			}
+		}
+	}
+
+	free(pixels);
+	return 1;
+}
+
+int
+piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int *expected)
+{
+	int i, j, p;
+	GLuint *probe;
+	GLuint *pixels = malloc(w*h*4*sizeof(unsigned int));
+
+	glReadPixels(x, y, w, h, GL_RGBA_INTEGER, GL_UNSIGNED_INT, pixels);
+
+	for (j = 0; j < h; j++) {
+		for (i = 0; i < w; i++) {
+			probe = &pixels[(j*w+i)*4];
+
+			for (p = 0; p < 4; ++p) {
+				if (fabs(probe[p] - expected[p]) >= piglit_tolerance[p]) {
+					printf("Probe at (%d,%d)\n", x+i, y+j);
+					printf("  Expected: %u %u %u %u\n",
+					       expected[0], expected[1], expected[2], expected[3]);
+					printf("  Observed: %u %u %u %u\n",
+					       probe[0], probe[1], probe[2], probe[3]);
+
+					free(pixels);
+					return 0;
+				}
+			}
+		}
+	}
+
+	free(pixels);
+	return 1;
+}
+
+int
 piglit_probe_image_rgb(int x, int y, int w, int h, const float *image)
 {
 	int i, j, p;
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 15eb42a..964b0f8 100755
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -193,6 +193,8 @@ int piglit_probe_pixel_rgb(int x, int y, const float* expected);
 int piglit_probe_pixel_rgba(int x, int y, const float* expected);
 int piglit_probe_rect_rgb(int x, int y, int w, int h, const float* expected);
 int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
+int piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int* expected);
+int piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int* expected);
 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_texel_rect_rgb(int target, int level, int x, int y,
-- 
1.7.7.4



More information about the Piglit mailing list