[Piglit] [PATCH] Add test to verify GL errors in glGenerateMipmap

Anuj Phogat anuj.phogat at gmail.com
Fri Nov 2 14:15:44 PDT 2012


It does error checking for glGenerateMipmap() with various texture internal
formats.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 tests/all.tests                    |    1 +
 tests/texturing/CMakeLists.gl.txt  |    1 +
 tests/texturing/genmipmap-errors.c |  299 ++++++++++++++++++++++++++++++++++++
 3 files changed, 301 insertions(+), 0 deletions(-)
 create mode 100644 tests/texturing/genmipmap-errors.c

diff --git a/tests/all.tests b/tests/all.tests
index 341d021..6fe0b45 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -562,6 +562,7 @@ add_plain_test(texturing, 'depth-cube-map')
 add_plain_test(texturing, 'fragment-and-vertex-texturing')
 add_plain_test(texturing, 'fxt1-teximage')
 add_plain_test(texturing, 'gen-teximage')
+add_plain_test(texturing, 'genmipmap-errors')
 add_plain_test(texturing, 'gen-compressed-teximage')
 add_plain_test(texturing, 'gen-nonzero-unit')
 add_plain_test(texturing, 'gen-texsubimage')
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index 8567fa8..237a0f8 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -28,6 +28,7 @@ piglit_add_executable (gen-compressed-teximage gen-compressed-teximage.c)
 piglit_add_executable (gen-nonzero-unit gen-nonzero-unit.c)
 piglit_add_executable (gen-teximage gen-teximage.c)
 piglit_add_executable (gen-texsubimage gen-texsubimage.c)
+piglit_add_executable (genmipmap-errors genmipmap-errors.c)
 piglit_add_executable (getteximage-formats getteximage-formats.c)
 piglit_add_executable (getteximage-simple getteximage-simple.c)
 piglit_add_executable (getteximage-luminance getteximage-luminance.c)
diff --git a/tests/texturing/genmipmap-errors.c b/tests/texturing/genmipmap-errors.c
new file mode 100644
index 0000000..98b0ce9
--- /dev/null
+++ b/tests/texturing/genmipmap-errors.c
@@ -0,0 +1,299 @@
+/* Copyright 2012 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.
+ */
+
+/**
+ * \file genmipmap-errors.c
+ * Do error checking for glGenerateMipmap() with various texture internal formats.
+ * GL_INVALID_OPERATION is expected in case of integer and depth-stencil textures.
+ */
+
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_width = 100;
+	config.window_height = 100;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_ALPHA | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+/**
+ * Test textures having integer internalFormat with glGenerateMipmap to
+ * verify that GL_INVALID_OPERATION is thrown by the implementation.
+ */
+static bool
+test_genmipmap_errors(void)
+{
+	GLuint tex;
+	struct {
+		GLenum intFormat, srcFormat, srcType;
+		const char *extension[2];
+	} formats[] = {
+		/* Integer internal formats */
+		{ GL_RGBA8I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGBA16I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGBA32I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGB8I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGB16I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL } },
+		{ GL_RGB32I, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RG32I, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", "GL_ARB_texture_rg"} },
+		{ GL_R32I, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", "GL_ARB_texture_rg"} },
+		{ GL_ALPHA8I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_LUMINANCE8I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_INTENSITY8I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_LUMINANCE_ALPHA8I_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+
+		{ GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGBA16UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGBA32UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGB8UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RGB16UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer" } },
+		{ GL_RGB32UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_RG32UI, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", "GL_ARB_texture_rg"} },
+		{ GL_R32UI, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", "GL_ARB_texture_rg"} },
+		{ GL_ALPHA8UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_LUMINANCE8UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_INTENSITY8UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+		{ GL_LUMINANCE_ALPHA8UI_EXT, GL_RGBA_INTEGER, GL_INT,
+		  {"GL_EXT_texture_integer", NULL} },
+
+		/* Packed depth / stencil formats */
+		{ GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8,
+		  {NULL, NULL} }
+	};
+	int i, j;
+	bool pass = GL_TRUE;
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+
+	for (i = 0; i < ARRAY_SIZE(formats); i++) {
+
+		bool is_ext_supported = true;
+		for(j = 0; j < ARRAY_SIZE(formats[i].extension); j++) {
+			if((formats[i].extension[j] != NULL) &&
+			   !piglit_is_extension_supported(formats[i].extension[j]))
+			{
+				printf("Skipping %s\n",
+				piglit_get_gl_enum_name(formats[i].intFormat));
+				is_ext_supported = false;
+			}
+		}
+		if (!is_ext_supported)
+			continue;
+
+		while (glGetError() != GL_NO_ERROR)
+			;
+		glTexImage2D(GL_TEXTURE_2D, 0, formats[i].intFormat,
+			     16, 16, 0,
+			     formats[i].srcFormat, formats[i].srcType, NULL);
+
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+		glGenerateMipmap(GL_TEXTURE_2D);
+		pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
+	}
+
+	return pass;
+}
+
+/**
+ * Test textures having non-integer / non-depth-stencil internalFormat with
+ * glGenerateMipmap to verify that no error is thrown by the implementation.
+ */
+static bool
+test_genmipmap_no_errors(void)
+{
+	GLuint tex;
+	struct {
+		GLenum intFormat, srcFormat, srcType;
+		const char *extension[2];
+	} formats[] = {
+		/* normalized formats */
+		{ GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {NULL, NULL} },
+		{ GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {NULL, NULL} },
+		{ GL_RG8, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {"GL_ARB_texture_rg", NULL} },
+		{ GL_R8, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {"GL_ARB_texture_rg", NULL} },
+
+		/* signed normalized formats */
+		{ GL_RGBA8_SNORM, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {"GL_EXT_texture_snorm", NULL} },
+		{ GL_RGB8_SNORM, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {"GL_EXT_texture_snorm", NULL} },
+		{ GL_RG8_SNORM, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {"GL_EXT_texture_snorm", "GL_ARB_texture_rg"} },
+		{ GL_R8_SNORM, GL_RGBA, GL_UNSIGNED_BYTE,
+		  {"GL_EXT_texture_snorm", "GL_ARB_texture_rg"} },
+
+		/* floating point formats */
+		{ GL_RGBA32F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_float", NULL} },
+		{ GL_RGBA16F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_float", NULL} },
+		{ GL_RGB32F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_float", NULL} },
+		{ GL_RGB16F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_float", NULL} },
+		{ GL_RG32F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_rg", "GL_ARB_texture_float"} },
+		{ GL_RG16F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_rg", "GL_ARB_texture_float"} },
+		{ GL_R32F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_rg", "GL_ARB_texture_float"} },
+		{ GL_R16F, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_rg", "GL_ARB_texture_float"} },
+
+		/* depth formats */
+		{ GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_FLOAT,
+		  {"GL_ARB_depth_texture", NULL} },
+		{ GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_FLOAT,
+		  {"GL_ARB_depth_texture", NULL} },
+		{ GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT,
+		  {"GL_ARB_depth_texture", NULL} },
+		{ GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT,
+		  {"GL_ARB_depth_buffer_float", NULL} },
+
+		/* Specific compressed formats */
+		{ GL_COMPRESSED_RED_RGTC1, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression_rgtc", NULL} },
+		{ GL_COMPRESSED_RG_RGTC2, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression_rgtc", NULL} },
+		{ GL_COMPRESSED_SIGNED_RED_RGTC1, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression_rgtc", "GL_EXT_texture_snorm"} },
+		{ GL_COMPRESSED_SIGNED_RG_RGTC2, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression_rgtc", "GL_EXT_texture_snorm"} },
+
+		{ GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", NULL} },
+		{ GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", NULL} },
+		{ GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", NULL} },
+		{ GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", NULL} },
+		{ GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", "GL_EXT_texture_sRGB"} },
+		{ GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", "GL_EXT_texture_sRGB"} },
+		{ GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", "GL_EXT_texture_sRGB"} },
+		{ GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_RGBA, GL_FLOAT,
+		  {"GL_EXT_texture_compression_s3tc", "GL_EXT_texture_sRGB"} },
+
+		{ GL_COMPRESSED_RGB_FXT1_3DFX, GL_RGBA, GL_FLOAT,
+		  {"GL_3DFX_texture_compression_FXT1", NULL} },
+
+		/* Generic compressed formats */
+		{ GL_COMPRESSED_RGB, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression", NULL} },
+		{ GL_COMPRESSED_RGBA, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression", NULL} },
+		{ GL_COMPRESSED_ALPHA, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression", NULL} },
+		{ GL_COMPRESSED_LUMINANCE, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression", NULL} },
+		{ GL_COMPRESSED_LUMINANCE_ALPHA, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression", NULL} },
+		{ GL_COMPRESSED_INTENSITY, GL_RGBA, GL_FLOAT,
+		  {"GL_ARB_texture_compression", NULL} }
+	};
+	int i, j;
+	bool pass = GL_TRUE;
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+
+	for (i = 0; i < ARRAY_SIZE(formats); i++) {
+
+		bool is_ext_supported = true;
+		for(j = 0; j < ARRAY_SIZE(formats[i].extension); j++) {
+			if((formats[i].extension[j] != NULL) &&
+			   !piglit_is_extension_supported(formats[i].extension[j]))
+			{
+				printf("Skipping %s\n",
+				piglit_get_gl_enum_name(formats[i].intFormat));
+				is_ext_supported = false;
+			}
+		}
+		if (!is_ext_supported)
+			continue;
+
+		while (glGetError() != GL_NO_ERROR)
+			;
+		glTexImage2D(GL_TEXTURE_2D, 0, formats[i].intFormat,
+			     16, 16, 0,
+			     formats[i].srcFormat, formats[i].srcType, NULL);
+
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+		glGenerateMipmap(GL_TEXTURE_2D);
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+	}
+
+	return pass;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	bool pass = true;
+
+	pass = test_genmipmap_no_errors();
+	pass = test_genmipmap_errors() && pass;
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.7.7.6



More information about the Piglit mailing list