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

Yuanhan Liu yuanhan.liu at linux.intel.com
Sun Oct 16 20:48:57 PDT 2011


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

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

diff --git a/tests/all.tests b/tests/all.tests
index 2098e38..9880863 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -602,6 +602,7 @@ add_plain_test(glx, 'glx-pixmap-crosscheck')
 glx['glx-pixmap-crosscheck'].runConcurrent = True
 
 texturing = Group()
+add_plain_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..348f180
--- /dev/null
+++ b/tests/texturing/1-1-linear-texture.c
@@ -0,0 +1,104 @@
+/*
+ * 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;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLuint tex;
+	GLboolean pass;
+	void *tex_data = make_tex_data();
+	void *out_data = malloc(DATA_SIZE);
+
+	glClearColor(0.0, 0.0, 0.0, 1.0);
+
+	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);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+
+	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+	glEnable(GL_TEXTURE_2D);
+
+	glBegin(GL_QUADS);
+	  glTexCoord2f(0.0, 0.0);
+	  glVertex2f(-1.0, -1.0);
+	  glTexCoord2f(1.0, 0.0);
+	  glVertex2f(1.0, -1.0);
+	  glTexCoord2f(1.0, 1.0);
+	  glVertex2f(1.0,  1.0);
+	  glTexCoord2f(0.0, 1.0);
+	  glVertex2f(-1.0,  1.0);
+	glEnd();
+	glutSwapBuffers();
+
+	glReadPixels(0, 0, piglit_width, piglit_height, GL_RGBA, 
+	             GL_UNSIGNED_BYTE, out_data);
+
+	pass = memcmp(tex_data, out_data, DATA_SIZE) == 0;
+
+	free(tex_data);
+	free(out_data);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+}
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