[Piglit] [PATCH 3/4] textureSize: Add support for testing rectangle textures in 1.40.

Eric Anholt eric at anholt.net
Mon Mar 12 17:49:56 PDT 2012


---
 tests/texturing/shaders/common.c      |    4 ++++
 tests/texturing/shaders/textureSize.c |   26 +++++++++++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/tests/texturing/shaders/common.c b/tests/texturing/shaders/common.c
index 57a5b48..848b415 100644
--- a/tests/texturing/shaders/common.c
+++ b/tests/texturing/shaders/common.c
@@ -53,6 +53,7 @@ upload_miplevel_data(GLenum target, int level, void *level_image)
 			     0, format, data_type, level_image);
 		break;
 	case GL_TEXTURE_2D:
+	case GL_TEXTURE_RECTANGLE:
 	case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
 	case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
 	case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
@@ -121,6 +122,9 @@ compute_miplevel_info()
 
 	miplevels = (int) log2f(max_dimension) + 1;
 
+	if (sampler.target == GL_TEXTURE_RECTANGLE)
+		miplevels = 1;
+
 	/* Compute the size of each miplevel */
 	level_size = malloc(miplevels * sizeof(int *));
 
diff --git a/tests/texturing/shaders/textureSize.c b/tests/texturing/shaders/textureSize.c
index ff7f675..69d4333 100644
--- a/tests/texturing/shaders/textureSize.c
+++ b/tests/texturing/shaders/textureSize.c
@@ -151,8 +151,10 @@ generate_texture()
 
 	glGenTextures(1, &tex);
 	glBindTexture(target, tex);
-	glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-	glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	if (target != GL_TEXTURE_RECTANGLE) {
+		glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+		glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	}
 	glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 	glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
@@ -176,11 +178,17 @@ generate_GLSL(enum shader_target test_stage)
 
 	static char *vs_code;
 	static char *fs_code;
-
+	char *lod_arg;
 	static const char *zeroes[3] = { "", "0, ", "0, 0, " };
 
 	const int size = sampler_size();
 
+	/* The GLSL 1.40 sampler2DRect samplers don't take a lod argument. */
+	if (sampler.target == GL_TEXTURE_RECTANGLE)
+		lod_arg = "";
+	else
+		lod_arg = ", lod";
+
 	switch (test_stage) {
 	case VS:
 		asprintf(&vs_code,
@@ -192,10 +200,10 @@ generate_GLSL(enum shader_target test_stage)
 			 "flat out ivec%d size;\n"
 			 "void main()\n"
 			 "{\n"
-			 "    size = textureSize(tex, lod);\n"
+			 "    size = textureSize(tex%s);\n"
 			 "    gl_Position = vertex;\n"
 			 "}\n",
-			 shader_version, sampler.name, size);
+			 shader_version, sampler.name, size, lod_arg);
 		asprintf(&fs_code,
 			 "#version %d\n"
 			 "#define ivec1 int\n"
@@ -223,10 +231,11 @@ generate_GLSL(enum shader_target test_stage)
 			 "uniform %s tex;\n"
 			 "void main()\n"
 			 "{\n"
-			 "    ivec%d size = textureSize(tex, lod);\n"
+			 "    ivec%d size = textureSize(tex%s);\n"
 			 "    gl_FragColor = vec4(0.01 * size,%s 1);\n"
 			 "}\n",
-			 shader_version, sampler.name, size, zeroes[3 - size]);
+			 shader_version, sampler.name, size, lod_arg,
+			 zeroes[3 - size]);
 		break;
 	default:
 		assert(!"Should not get here.");
@@ -286,8 +295,7 @@ piglit_init(int argc, char **argv)
 		fail_and_show_usage();
 
 	/* Not implemented yet */
-	assert(sampler.target != GL_TEXTURE_CUBE_MAP_ARRAY &&
-	       sampler.target != GL_TEXTURE_RECTANGLE);
+	assert(sampler.target != GL_TEXTURE_CUBE_MAP_ARRAY);
 
 	require_GL_features(test_stage);
 
-- 
1.7.9.1



More information about the Piglit mailing list