[1/2] ext_texture_integer: add error-checking test

Submitted by Brian Paul on June 27, 2014, 8:54 p.m.

Details

Message ID 1403902472-24655-1-git-send-email-brianp@vmware.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Brian Paul June 27, 2014, 8:54 p.m.
This is based on the previous integer-errors test, but tests
many more glTexImage internalFormat / format / type combinations.
---
 tests/all.py                                     |    1 +
 tests/spec/ext_texture_integer/CMakeLists.gl.txt |    1 +
 tests/spec/ext_texture_integer/errors.c          |  240 ++++++++++++++++++++++
 3 files changed, 242 insertions(+)
 create mode 100644 tests/spec/ext_texture_integer/errors.c

Patch hide | download patch | download mbox

diff --git a/tests/all.py b/tests/all.py
index 17d5d9b..6ce99f1 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -2659,6 +2659,7 @@  spec['EXT_texture_integer'] = ext_texture_integer
 ext_texture_integer['api-drawpixels'] = concurrent_test('ext_texture_integer-api-drawpixels')
 ext_texture_integer['api-teximage'] = concurrent_test('ext_texture_integer-api-teximage')
 ext_texture_integer['api-readpixels'] = concurrent_test('ext_texture_integer-api-readpixels')
+ext_texture_integer['errors'] = concurrent_test('ext_texture_integer-errors')
 ext_texture_integer['fbo-blending'] = concurrent_test('ext_texture_integer-fbo-blending')
 ext_texture_integer['fbo-blending GL_ARB_texture_rg'] = concurrent_test('ext_texture_integer-fbo-blending GL_ARB_texture_rg')
 ext_texture_integer['fbo_integer_precision_clear'] = plain_test('ext_texture_integer-fbo_integer_precision_clear')
diff --git a/tests/spec/ext_texture_integer/CMakeLists.gl.txt b/tests/spec/ext_texture_integer/CMakeLists.gl.txt
index 44d9399..c4c1483 100644
--- a/tests/spec/ext_texture_integer/CMakeLists.gl.txt
+++ b/tests/spec/ext_texture_integer/CMakeLists.gl.txt
@@ -18,5 +18,6 @@  piglit_add_executable (ext_texture_integer-texture_integer_glsl130 texture-integ
 piglit_add_executable (ext_texture_integer-api-drawpixels api-drawpixels.c)
 piglit_add_executable (ext_texture_integer-api-readpixels api-readpixels.c)
 piglit_add_executable (ext_texture_integer-api-teximage api-teximage.c)
+piglit_add_executable (ext_texture_integer-errors errors.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/ext_texture_integer/errors.c b/tests/spec/ext_texture_integer/errors.c
new file mode 100644
index 0000000..57de2d7
--- /dev/null
+++ b/tests/spec/ext_texture_integer/errors.c
@@ -0,0 +1,240 @@ 
+/* Copyright 2012 VMware, Inc.
+ *
+ * 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 errors.c
+ * Do error checking for functions taking signed/unsigned integer
+ * (non-normalized) formats, such as glTex[Sub]Image, glDrawPixels and
+ * glReadPixels.
+ */
+
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 20;
+	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static bool
+test_api_errors(void)
+{
+	/* clear any prev errors */
+	while (glGetError())
+		;
+
+	/* use a new tex obj */
+	glBindTexture(GL_TEXTURE_2D, 42);
+
+	/* Check that glDrawPixels of integer data is illegal */
+	{
+		static const GLfloat pixel[4] = {0, 0, 0, 0};
+
+		glDrawPixels(1, 1, GL_RGBA_INTEGER_EXT, GL_INT, pixel);
+		if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+			return false;
+	}
+
+	/* Check glTexImage for invalid internalFormat/format/type combos */
+	{
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16UI_EXT, 1, 1, 0,
+			     GL_RGBA_INTEGER, GL_FLOAT, NULL);
+		if (!piglit_check_gl_error(GL_INVALID_ENUM))
+			return false;
+
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0,
+			     GL_RGBA_INTEGER, GL_SHORT, NULL);
+		if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+			return false;
+	}
+
+	/* Check glTexSubImage for invalid format/type combination */
+	{
+		/* make valid texture image here */
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI_EXT, 8, 8, 0,
+			     GL_RGBA_INTEGER, GL_UNSIGNED_INT, NULL);
+		if (!piglit_check_gl_error(GL_NO_ERROR))
+			return false;
+
+		glTexSubImage2D(GL_TEXTURE_2D, 0,
+				0, 0, 4, 4,
+				GL_RGBA_INTEGER, GL_FLOAT, NULL);
+		if (!piglit_check_gl_error(GL_INVALID_ENUM))
+			return false;
+	}
+
+	/* Check for GL_INVALID_OPERATION when trying to copy framebuffer pixels
+	 * to an integer texture when the framebuffer is not an integer format.
+	 */
+	{
+		/* make valid texture image here */
+		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16UI_EXT, 4, 4, 0,
+			     GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, NULL);
+		if (!piglit_check_gl_error(GL_NO_ERROR))
+			return false;
+
+		glCopyTexSubImage2D(GL_TEXTURE_2D, 0,
+				    0, 0, 0, 0, 4, 4);
+		if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+			return false;
+	}
+
+	/* Is GL_INVALID_ENUM generated by glReadPixels? */
+	{
+		GLfloat buf[64];
+		glReadPixels(0, 0, 4, 4, GL_RGBA_INTEGER, GL_FLOAT, buf);
+		if (!piglit_check_gl_error(GL_INVALID_ENUM))
+			return false;
+	}
+
+	/* Is GL_INVALID_OPERATION generated by glReadPixels? */
+	{
+		GLuint buf[64];
+		glReadPixels(0, 0, 4, 4, GL_RGBA_INTEGER, GL_UNSIGNED_INT, buf);
+		if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+			return false;
+	}
+
+	return true;
+}
+
+
+/**
+ * Test specific combinations of (internalFormat, format, type) with
+ * glTexImage to see that they're accepted (no GL errors).
+ */
+static bool
+test_teximage_format_combos(void)
+{
+	static const GLenum intformats[] = {
+		GL_ALPHA8UI_EXT,
+		GL_INTENSITY8UI_EXT,
+		GL_LUMINANCE8UI_EXT,
+		GL_LUMINANCE_ALPHA8UI_EXT,
+		GL_RGB8UI_EXT,
+		GL_RGBA8UI_EXT,
+
+		GL_ALPHA8I_EXT,
+		GL_INTENSITY8I_EXT,
+		GL_LUMINANCE8I_EXT,
+		GL_LUMINANCE_ALPHA8I_EXT,
+		GL_RGB8I_EXT,
+		GL_RGBA8I_EXT,
+
+		GL_ALPHA16UI_EXT,
+		GL_INTENSITY16UI_EXT,
+		GL_LUMINANCE16UI_EXT,
+		GL_LUMINANCE_ALPHA16UI_EXT,
+		GL_RGB16UI_EXT,
+		GL_RGBA16UI_EXT,
+
+		GL_ALPHA16I_EXT,
+		GL_INTENSITY16I_EXT,
+		GL_LUMINANCE16I_EXT,
+		GL_LUMINANCE_ALPHA16I_EXT,
+		GL_RGB16I_EXT,
+		GL_RGBA16I_EXT,
+
+		GL_ALPHA32UI_EXT,
+		GL_INTENSITY32UI_EXT,
+		GL_LUMINANCE32UI_EXT,
+		GL_LUMINANCE_ALPHA32UI_EXT,
+		GL_RGB32UI_EXT,
+		GL_RGBA32UI_EXT,
+
+		GL_ALPHA32I_EXT,
+		GL_INTENSITY32I_EXT,
+		GL_LUMINANCE32I_EXT,
+		GL_LUMINANCE_ALPHA32I_EXT,
+		GL_RGB32I_EXT,
+		GL_RGBA32I_EXT
+	};
+	static const GLenum formats[] = {
+		GL_RED_INTEGER_EXT,
+		GL_GREEN_INTEGER_EXT,
+		GL_BLUE_INTEGER_EXT,
+		GL_ALPHA_INTEGER_EXT,
+		GL_RGB_INTEGER_EXT,
+		GL_BGR_INTEGER_EXT,
+		GL_RGBA_INTEGER_EXT,
+		GL_BGRA_INTEGER_EXT,
+		GL_LUMINANCE_INTEGER_EXT,
+		GL_LUMINANCE_ALPHA_INTEGER_EXT
+	};
+	static const GLenum types[] = {
+		GL_BYTE,
+		GL_UNSIGNED_BYTE,
+		GL_SHORT,
+		GL_UNSIGNED_SHORT,
+		GL_INT,
+		GL_UNSIGNED_INT
+	};
+	unsigned i, j, k;
+	GLenum err;
+	bool pass = GL_TRUE;
+
+	for (i = 0; i < ARRAY_SIZE(intformats); i++)
+	for (j = 0; j < ARRAY_SIZE(formats); j++)
+	for (k = 0; k < ARRAY_SIZE(types); k++) {
+		glTexImage2D(GL_TEXTURE_2D, 0, intformats[i],
+			     16, 16, 0,
+			     formats[j], types[k], NULL);
+		err = glGetError();
+		if (err != GL_NO_ERROR) {
+			fprintf(stderr,
+				"fail: glTexImage2D(%s, %s, %s)"
+				" generated error %s\n",
+				piglit_get_gl_enum_name(intformats[i]),
+				piglit_get_gl_enum_name(formats[j]),
+				piglit_get_gl_enum_name(types[k]),
+				piglit_get_gl_enum_name(err));
+			pass = false;
+		}
+	}
+
+	return pass;
+}
+
+
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	bool pass;
+
+	piglit_require_extension("GL_EXT_texture_integer");
+
+	pass = test_api_errors();
+
+	pass = pass && test_teximage_format_combos();
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}