[Piglit] [PATCH] s3tc-errors: check GL_ARB_compressed_texture_pixel_storage errors

Brian Paul brianp at vmware.com
Fri Aug 15 16:04:27 PDT 2014


Basic checking that the SKIP_PIXELS, SKIP_ROWS parameters are
multiples of the block size.

And check that if a GL error is generated, the glCompressedTexSubImage2D()
call is no-op'd (to exercise a Mesa bug.)
---
 tests/texturing/s3tc-errors.c |   78 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/tests/texturing/s3tc-errors.c b/tests/texturing/s3tc-errors.c
index 0ed1279..d74d91e 100644
--- a/tests/texturing/s3tc-errors.c
+++ b/tests/texturing/s3tc-errors.c
@@ -504,12 +504,90 @@ test_formats(void)
 }
 
 
+/**
+ * Test GL_ARB_compressed_texture_pixel_storage error checking.
+ * \param return true for pass, false for failure
+ */
+static bool
+test_compressed_pixel_storage(void)
+{
+	const int width = 32, height = 16;
+	const int imageSize = (width / 4) * (height / 4) * 8;
+	const int format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
+	GLuint tex;
+	GLubyte *buf, *zeros, *ones;
+	bool pass = true;
+
+	if (!piglit_is_extension_supported("GL_ARB_compressed_texture_pixel_storage"))
+		return true;  /* not a failure */
+
+	buf = malloc(imageSize);
+	zeros = calloc(imageSize, 1);
+	ones = malloc(imageSize);
+	memset(ones, 1, imageSize);
+
+	/* Setup initial texture */
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, buf);
+
+	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+	/* Specify the S3TC block size */
+	glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_SIZE, 8);
+	glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_WIDTH, 4);
+	glPixelStorei(GL_UNPACK_COMPRESSED_BLOCK_HEIGHT, 4);
+
+	/* This should work */
+	glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
+				  format, imageSize, zeros);
+	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+	/* This should fail */
+	glPixelStorei(GL_UNPACK_SKIP_PIXELS, 3); /* illegal */
+	glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
+				  format, imageSize, ones);
+	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
+
+	/* This should fail */
+	glPixelStorei(GL_UNPACK_SKIP_PIXELS, 4); /* legal */
+	glPixelStorei(GL_UNPACK_SKIP_ROWS, 2); /* illegal */
+	glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
+				  format, imageSize, ones);
+	pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
+
+	glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
+	glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
+
+	/* Read back the compressed texture image and make sure it's still
+	 * all zeros (exercises a Mesa bug).
+	 */
+	glGetCompressedTexImage(GL_TEXTURE_2D, 0, buf);
+
+	if (memcmp(buf, zeros, imageSize)) {
+		printf("Failure: Error-generating glCompressedTexSubImage2D()"
+		       " modified the texture!\n");
+		pass = false;
+	}
+
+	glDeleteTextures(1, &tex);
+
+	free(buf);
+	free(zeros);
+	free(ones);
+
+	return pass;
+}
+
+
 enum piglit_result
 piglit_display(void)
 {
 	bool pass = test_formats();
 	pass = test_small_mipmap_level() && pass;
 	pass = test_non_power_of_two() && pass;
+	pass = test_compressed_pixel_storage() && pass;
 
 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
-- 
1.7.10.4



More information about the Piglit mailing list