[Piglit] [PATCH 1/8] util: add piglit_probe_texel_volume_rgba()

Chris Forbes chrisf at ijw.co.nz
Fri Feb 21 12:03:00 PST 2014


This is similar to piglit_probe_texel_rect_rgba except it allows
for probing a subvolume of a 3D texture, or slices of a 2D array
texture.

Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
 tests/util/piglit-util-gl-common.h |  2 ++
 tests/util/piglit-util-gl.c        | 56 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index 73f2f83..8653441 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -149,6 +149,8 @@ int piglit_probe_texel_rect_rgba(int target, int level, int x, int y,
 				 int w, int h, const float *expected);
 int piglit_probe_texel_rgba(int target, int level, int x, int y,
 			    const float* expected);
+int piglit_probe_texel_volume_rgba(int target, int level, int x, int y, int z,
+				 int w, int h, int d, 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);
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 3bb4adf..9fcc784 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -630,6 +630,62 @@ int piglit_probe_texel_rect_rgba(int target, int level, int x, int y,
 }
 
 /**
+ * Read a texel rectangle from the given location and compare its RGBA value to
+ * the given expected values.
+ *
+ * Print a log message if the color value deviates from the expected value.
+ * \return true if the color values match, false otherwise
+ */
+int piglit_probe_texel_volume_rgba(int target, int level, int x, int y, int z,
+				 int w, int h, int d, const float* expected)
+{
+	GLfloat *buffer;
+	GLfloat *probe;
+	int i, j, k, p;
+	GLint width;
+	GLint height;
+	GLint depth;
+
+	glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
+	glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
+	glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, &depth);
+	buffer = malloc(width * height * depth * 4 * sizeof(GLfloat));
+
+	glGetTexImage(target, level, GL_RGBA, GL_FLOAT, buffer);
+
+	assert(x >= 0);
+	assert(y >= 0);
+	assert(d >= 0);
+	assert(x+w <= width);
+	assert(y+h <= height);
+	assert(z+d <= depth);
+
+	for (k = z; k < z+d; ++k) {
+		for (j = y; j < y+h; ++j) {
+			for (i = x; i < x+w; ++i) {
+				probe = &buffer[(k * width * height + j * width + i) * 4];
+
+				for (p = 0; p < 4; ++p) {
+					if (fabs(probe[p] - expected[p]) >= piglit_tolerance[p]) {
+						printf("Probe color at (%i,%i,%i)\n", i, j, k);
+						printf("  Expected: %f %f %f %f\n",
+						       expected[0], expected[1], expected[2], expected[3]);
+						printf("  Observed: %f %f %f %f\n",
+						       probe[0], probe[1], probe[2], probe[3]);
+
+						free(buffer);
+						return 0;
+					}
+				}
+			}
+		}
+	}
+
+	free(buffer);
+	return 1;
+}
+
+/**
  * Read a texel from the given location and compare its RGBA value to the
  * given expected values.
  *
-- 
1.8.5.4



More information about the Piglit mailing list