[Piglit] [PATCH 1/2] integer-errors: check error detection for integer-related images

Brian Paul brianp at vmware.com
Wed Jun 6 12:40:29 PDT 2012


This is basically code that was in the old integer-texture test.
This test just validates GL error detection for glReadPixels, glDrawPixels,
glTexImage, etc. with regard to signed/unsigned integer formats.
---
 tests/all.tests                         |    1 +
 tests/spec/gl-3.0/api/CMakeLists.gl.txt |    1 +
 tests/spec/gl-3.0/api/integer-errors.c  |  182 +++++++++++++++++++++++++++++++
 3 files changed, 184 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/gl-3.0/api/integer-errors.c

diff --git a/tests/all.tests b/tests/all.tests
index 93716a8..bebc12a 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -896,6 +896,7 @@ add_concurrent_test(gl30, 'clearbuffer-invalid-buffer')
 add_concurrent_test(gl30, 'clearbuffer-mixed-format')
 add_concurrent_test(gl30, 'clearbuffer-stencil')
 add_concurrent_test(gl30, 'getfragdatalocation')
+add_concurrent_test(gl30, 'integer-errors')
 gl30['minmax'] = concurrent_test('gl-3.0-minmax')
 add_concurrent_test(gl30, 'gl-3.0-required-sized-texture-formats')
 add_concurrent_test(gl30, 'gl-3.0-required-renderbuffer-attachment-formats')
diff --git a/tests/spec/gl-3.0/api/CMakeLists.gl.txt b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
index 924c17e..d916d66 100644
--- a/tests/spec/gl-3.0/api/CMakeLists.gl.txt
+++ b/tests/spec/gl-3.0/api/CMakeLists.gl.txt
@@ -20,5 +20,6 @@ piglit_add_executable (clearbuffer-invalid-buffer clearbuffer-invalid-buffer.c)
 piglit_add_executable (clearbuffer-mixed-format clearbuffer-common.c clearbuffer-mixed-format.c)
 piglit_add_executable (clearbuffer-stencil clearbuffer-common.c clearbuffer-stencil.c)
 piglit_add_executable (getfragdatalocation getfragdatalocation.c)
+piglit_add_executable (integer-errors integer-errors.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/gl-3.0/api/integer-errors.c b/tests/spec/gl-3.0/api/integer-errors.c
new file mode 100644
index 0000000..d4a1b2b
--- /dev/null
+++ b/tests/spec/gl-3.0/api/integer-errors.c
@@ -0,0 +1,182 @@
+/* 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 integer-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.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE;
+
+
+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);
+
+		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);
+
+		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)
+{
+	/* These format combinations should all work */
+	struct {
+		GLenum intFormat, srcFormat, srcType;
+	} formats[] = {
+		{ GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE },
+		{ GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_SHORT },
+		{ GL_RGBA8UI_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8 },
+		{ GL_RGBA8UI_EXT, GL_BGRA_INTEGER, GL_UNSIGNED_INT_8_8_8_8 },
+		{ GL_LUMINANCE8I_EXT, GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8 },
+		{ GL_RGB16I_EXT, GL_RGB_INTEGER, GL_UNSIGNED_SHORT_5_6_5 },
+		{ GL_RGB32I_EXT, GL_RGB_INTEGER, GL_UNSIGNED_SHORT_5_6_5 }
+	};
+	int i;
+	GLenum err;
+	bool pass = GL_TRUE;
+
+	while (glGetError() != GL_NO_ERROR)
+		;
+
+	for (i = 0; i < ARRAY_SIZE(formats); i++) {
+		glTexImage2D(GL_TEXTURE_2D, 0, formats[i].intFormat,
+			     16, 16, 0,
+			     formats[i].srcFormat, formats[i].srcType, NULL);
+		err = glGetError();
+		if (err != GL_NO_ERROR) {
+			fprintf(stderr,
+				"integer-errors failure: glTexImage2D(0x%x, 0x%x, 0x%x)"
+				" generated error 0x%x (case %d)\n",
+				formats[i].intFormat,
+				formats[i].srcFormat,
+				formats[i].srcType, err, i);
+			pass = false;
+		}
+	}
+
+	return pass;
+}
+
+
+
+enum piglit_result
+piglit_display(void)
+{
+	return PIGLIT_PASS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	bool pass;
+
+	piglit_require_gl_version(30);
+
+	pass = test_api_errors();
+
+	pass = pass && test_teximage_format_combos();
+
+	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
-- 
1.7.3.4



More information about the Piglit mailing list