[Piglit] [PATCH] texture: add a 1:1 linear texture test case

Yuanhan Liu yuanhan.liu at linux.intel.com
Thu Oct 20 01:46:52 PDT 2011


To test that the 1:1 texture with filter set to linear is sampled
correctly.

v2: comments from Eric:
    Add the forgotten glClear operation,
    Change GL_CLAMP to GL_CMAP_TO_EDGE,
    Put swap buffer after glReadPixels,
    Show some feedback if failed,
    This patch needs GL_ARB_texture_rectangle.

v3: comments from Eric:
    Use 'add_concurrent_test' instead to reduce test time,
    Fix a typo,
    Use piglit_draw_rect_tex helper function to make code simpler.

Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
---
 tests/all.tests                      |    1 +
 tests/texturing/1-1-linear-texture.c |  139 ++++++++++++++++++++++++++++++++++
 tests/texturing/CMakeLists.gl.txt    |    1 +
 3 files changed, 141 insertions(+), 0 deletions(-)
 create mode 100644 tests/texturing/1-1-linear-texture.c

diff --git a/tests/all.tests b/tests/all.tests
index 0248164..760487a 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -609,6 +609,7 @@ add_plain_test(glx, 'glx-pixmap-crosscheck')
 glx['glx-pixmap-crosscheck'].runConcurrent = True
 
 texturing = Group()
+add_concurrent_test(texturing, '1-1-linear-texture')
 add_plain_test(texturing, 'array-texture')
 add_plain_test(texturing, 'copytexsubimage')
 add_plain_test(texturing, 'copyteximage')
diff --git a/tests/texturing/1-1-linear-texture.c b/tests/texturing/1-1-linear-texture.c
new file mode 100644
index 0000000..18f6f88
--- /dev/null
+++ b/tests/texturing/1-1-linear-texture.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright © 2011 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Yuanhan Liu <yuanhan.liu at linux.intel.com>
+ *
+ */
+
+/*
+ * Tests that the 1:1 texture with filter set to linear is sampled correctly.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100;
+int piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+#define DATA_SIZE	(piglit_width * piglit_height * 4)
+
+static void * make_tex_data(void)
+{
+	int i;
+	GLubyte *data = malloc(DATA_SIZE);
+
+	for (i = 0; i < DATA_SIZE; i++) {
+		if (i % 4 == 3)
+			data[i] = 255;
+		else
+			data[i] = random() % 256;
+	}
+
+	return data;
+}
+
+static GLboolean test(GLubyte *expected_data, GLubyte *data, int size)
+{
+	int i;
+	int err_count = 0;
+	GLubyte R0, G0, B0, A0;
+	GLubyte R1, G1, B1, A1;
+
+	for (i = 0; i < size; i += 4) {
+		R0 = expected_data[i + 0];
+		G0 = expected_data[i + 1];
+		B0 = expected_data[i + 2];
+		A0 = expected_data[i + 3];
+
+		R1 = data[i + 0];
+		G1 = data[i + 1];
+		B1 = data[i + 2];
+		A1 = data[i + 3];
+
+		if (R0 != R1 || G0 != G1 || B0 != B1 || A0 != A1) {
+			err_count++;
+			if (err_count <= 10) {
+				int x = (i / 4) % piglit_width;
+				int y = (i / 4) / piglit_width;
+				fprintf(stderr, "Error pixel at (%2d, %2d): "
+				                "got (%3d, %3d, %3d, %3d), "
+						"expected (%3d, %3d, %3d, %3d)\n",
+						x, y,
+						R1, G1, B1, A1,
+						R0, G0, B0, A0);
+			}
+		}
+	}
+
+	if (err_count) {
+		fprintf(stderr, "Got %d error pixels(%d total), "
+			        "just first %d pixels shown\n",
+				err_count, size / 4,
+				err_count > 10 ? 10 : err_count);
+	}
+
+	return err_count == 0;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLuint tex;
+	GLboolean pass;
+	GLubyte *tex_data = make_tex_data();
+	GLubyte *out_data = malloc(DATA_SIZE);
+
+	glClearColor(0.0, 0.0, 0.0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, piglit_width, piglit_height,
+	             0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
+
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+	glEnable(GL_TEXTURE_2D);
+
+	piglit_draw_rect_tex(-1, -1, 2, 2, 0, 0, 1, 1);
+
+	glReadPixels(0, 0, piglit_width, piglit_height, GL_RGBA, 
+	             GL_UNSIGNED_BYTE, out_data);
+	piglit_present_results();
+	pass = test(tex_data, out_data, DATA_SIZE);
+
+	free(tex_data);
+	free(out_data);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_texture_rectangle");
+}
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index 1c6526a..3392020 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -13,6 +13,7 @@ link_libraries (
 	${GLUT_glut_LIBRARY}
 )
 
+add_executable (1-1-linear-texture 1-1-linear-texture.c)
 add_executable (array-texture array-texture.c)
 add_executable (copytexsubimage copytexsubimage.c)
 add_executable (copyteximage copyteximage.c)
-- 
1.7.4.4



More information about the Piglit mailing list