[Piglit] [PATCH 09/24] arb_direct_state_access: Added tests for CopyTextureSubImage*D.

Laura Ekstrand laura at jlekstrand.net
Mon Dec 15 17:24:12 PST 2014


---
 tests/all.py                                       |   2 +
 .../spec/arb_direct_state_access/CMakeLists.gl.txt |   2 +
 .../arb_direct_state_access/copytexturesubimage.c  | 293 +++++++++++++++++++++
 .../spec/arb_direct_state_access/texture-errors.c  | 134 ++++++++++
 4 files changed, 431 insertions(+)
 create mode 100644 tests/spec/arb_direct_state_access/copytexturesubimage.c
 create mode 100644 tests/spec/arb_direct_state_access/texture-errors.c

diff --git a/tests/all.py b/tests/all.py
index 3804cb6..48ec09f 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4314,6 +4314,8 @@ spec['ARB_direct_state_access']['create-textures'] = PiglitGLTest('arb_direct_st
 spec['ARB_direct_state_access']['texture-storage'] = PiglitGLTest('arb_direct_state_access-texture-storage', run_concurrent=True)
 spec['ARB_direct_state_access']['texunits'] = PiglitGLTest('arb_direct_state_access-texunits', run_concurrent=True)
 spec['ARB_direct_state_access']['texture-params'] = PiglitGLTest('arb_direct_state_access-texture-params', run_concurrent=True)
+spec['ARB_direct_state_access']['copytexturesubimage'] = PiglitGLTest('arb_direct_state_access-copytexturesubimage', run_concurrent=True)
+spec['ARB_direct_state_access']['texture-errors'] = PiglitGLTest('arb_direct_state_access-texture-errors', run_concurrent=True)
 
 profile.tests['hiz'] = hiz
 profile.tests['fast_color_clear'] = fast_color_clear
diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
index 1b24701..4f8f49f 100644
--- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
+++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
@@ -16,4 +16,6 @@ piglit_add_executable (arb_direct_state_access-create-textures create-textures.c
 piglit_add_executable (arb_direct_state_access-texture-storage texture-storage.c)
 piglit_add_executable (arb_direct_state_access-texunits texunits.c)
 piglit_add_executable (arb_direct_state_access-texture-params texture-params.c)
+piglit_add_executable (arb_direct_state_access-copytexturesubimage copytexturesubimage.c)
+piglit_add_executable (arb_direct_state_access-texture-errors texture-errors.c)
 # vim: ft=cmake:
diff --git a/tests/spec/arb_direct_state_access/copytexturesubimage.c b/tests/spec/arb_direct_state_access/copytexturesubimage.c
new file mode 100644
index 0000000..818257d
--- /dev/null
+++ b/tests/spec/arb_direct_state_access/copytexturesubimage.c
@@ -0,0 +1,293 @@
+/*
+ * Copyright © 2008 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.
+ *
+ * Authors:
+ *    Eric Anholt <eric at anholt.net>
+ *
+ *    Laura Ekstrand <laura at jlekstrand.net> adapted this for testing
+ *    CopyTextureSubImage* from ARB_direct_state_access.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_width = 200;
+	config.window_height = 200;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+/** Should GL_TEXTURE_RECTANGLE_ARB be tested? */
+int have_rect = 0;
+
+/** Should non-power-of-two textures be tested? */
+int have_NPOT = 0;
+
+static void rect(int x1, int y1, int x2, int y2)
+{
+	glBegin(GL_POLYGON);
+	glVertex2f(x1, y1);
+	glVertex2f(x1, y2);
+	glVertex2f(x2, y2);
+	glVertex2f(x2, y1);
+	glEnd();
+}
+static GLboolean inrect(int x, int y, int x1, int y1, int x2, int y2)
+{
+	if (x >= x1 && x < x2 && y >= y1 && y < y2)
+		return GL_TRUE;
+	else
+		return GL_FALSE;
+}
+
+static GLboolean
+check_results(int dstx, int dsty, int w, int h)
+{
+	GLfloat *results;
+	GLboolean pass = GL_TRUE;
+	int x, y;
+
+	results = malloc(w * h * 4 * sizeof(GLfloat));
+
+	/* Check the results */
+	glReadPixels(dstx, dsty, w, h, GL_RGBA, GL_FLOAT, results);
+	for (y = 0; y < h; y++) {
+		for (x = 0; x < w; x++) {
+			GLfloat expected[3];
+
+			if (inrect(x, y, 5, h/2, w - 5, h - 5)) {
+				expected[0] = 0.0;
+				expected[1] = 0.0;
+				expected[2] = 1.0;
+			} else if (inrect(x, y, 5, 5, w - 5, h/2)) {
+				expected[0] = 0.0;
+				expected[1] = 1.0;
+				expected[2] = 0.0;
+			} else {
+				expected[0] = 1.0;
+				expected[1] = 0.0;
+				expected[2] = 0.0;
+			}
+
+			if (results[(y * w + x) * 4 + 0] != expected[0] ||
+			    results[(y * w + x) * 4 + 1] != expected[1] ||
+			    results[(y * w + x) * 4 + 2] != expected[2]) {
+				printf("Expected at (%d,%d): %f,%f,%f\n",
+				       x, y,
+				       expected[0], expected[1], expected[2]);
+				printf("Probed at   (%d,%d): %f,%f,%f\n",
+				       x, y,
+				       results[(y * w + x) * 4 + 0],
+				       results[(y * w + x) * 4 + 1],
+				       results[(y * w + x) * 4 + 2]);
+				pass = GL_FALSE;
+			}
+		}
+	}
+
+	free(results);
+	return pass;
+}
+
+static GLboolean
+do_row(int srcy, int srcw, int srch, GLenum target)
+{
+	int srcx = 20;
+	int dstx = 80, dsty = srcy;
+	int dstx2 = 140, dsty2 = srcy;
+	int remain_width;
+	int remain_height;
+	GLuint texname;
+	GLboolean pass = GL_TRUE;
+
+	/* Rectangle textures use coordinates on the range [0..w]x[0..h],
+	 * where as all other textures use coordinates on the range
+	 * [0..1]x[0..1].
+	 */
+	const GLfloat tex_s_max = (target == GL_TEXTURE_RECTANGLE_ARB)
+		? (float)srcw : 1.0;
+	const GLfloat tex_t_max = (target == GL_TEXTURE_RECTANGLE_ARB)
+		? (float)srch : 1.0;
+
+
+	/* Draw the object we're going to copy */
+	glColor3f(1.0, 0.0, 0.0);
+	rect(srcx, srcy, srcx + srcw, srcy + srch);
+	glColor3f(0.0, 1.0, 0.0);
+	rect(srcx + 5, srcy + 5, srcx + srcw - 5, srcy + srch/2);
+	glColor3f(0.0, 0.0, 1.0);
+	rect(srcx + 5, srcy + srch/2, srcx + srcw - 5, srcy + srch - 5);
+
+	/* Create a texture image and copy it in */
+	glGenTextures(1, &texname);
+	glBindTexture(target, texname);
+	glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+	/* The default mode is GL_REPEAT, and this mode is invalid for
+	 * GL_TEXTURE_RECTANGLE_ARB textures.
+	 */
+	glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+	glEnable(target);
+
+	glTexImage2D(target, 0, GL_RGBA8, srcw, srch, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+	glCopyTextureSubImage2D(texname, 0,
+				0, 0, /* offset in image */
+				srcx, srcy, /* offset in readbuffer */
+				srcw, srch);
+
+	/* Draw the texture image out */
+	glBegin(GL_POLYGON);
+	glTexCoord2f(0.0, 0.0);
+	glVertex2f(dstx, dsty);
+
+	glTexCoord2f(0.0, tex_t_max);
+	glVertex2f(dstx, dsty + srch);
+
+	glTexCoord2f(tex_s_max, tex_t_max);
+	glVertex2f(dstx + srcw, dsty + srch);
+
+	glTexCoord2f(tex_s_max, 0.0);
+	glVertex2f(dstx + srcw, dsty);
+	glEnd();
+
+	glTexImage2D(target, 0, GL_RGBA8, srcw, srch, 0,
+		     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+
+	remain_width = srcw - (srcw / 2);
+	remain_height = srch - (srch / 2);
+	glCopyTextureSubImage2D(texname, 0,
+				0, 0, /* offset in image */
+				srcx, srcy, /* offset in readbuffer */
+				srcw / 2, srch / 2);
+	glCopyTextureSubImage2D(texname, 0,
+				srcw / 2, 0, /* offset in image */
+				srcx + srcw / 2, srcy, /* " in readbuffer */
+				remain_width, srch / 2);
+	glCopyTextureSubImage2D(texname, 0,
+				0, srch / 2, /* offset in image */
+				srcx, srcy + srch / 2, /* " in readbuffer */
+				srcw / 2, remain_height);
+	glCopyTextureSubImage2D(texname, 0,
+				srcw / 2, srch / 2, /* offset in image */
+				srcx + srcw / 2, srcy + srch / 2, /*" in rb */
+				remain_width, remain_height);
+
+	/* Draw the texture image out */
+	glBegin(GL_POLYGON);
+	glTexCoord2f(0.0, 0.0);
+	glVertex2f(dstx2, dsty2);
+
+	glTexCoord2f(0.0, tex_t_max);
+	glVertex2f(dstx2, dsty2 + srch);
+
+	glTexCoord2f(tex_s_max, tex_t_max);
+	glVertex2f(dstx2 + srcw, dsty2 + srch);
+
+	glTexCoord2f(tex_s_max, 0.0);
+	glVertex2f(dstx2 + srcw, dsty2);
+	glEnd();
+
+	glDisable(target);
+	glDeleteTextures(1, &texname);
+
+	printf("Checking %s, rect 1:\n", piglit_get_gl_enum_name(target));
+	pass &= check_results(dstx, dsty, srcw, srch);
+	printf("Checking %s, rect 2:\n", piglit_get_gl_enum_name(target));
+	pass &= check_results(dstx2, dsty2, srcw, srch);
+
+	return pass;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	GLboolean pass;
+	int srcy = 5;
+
+
+	glClear(GL_COLOR_BUFFER_BIT);
+
+
+	/* Test plain old 2D textures.
+	 */
+	pass = do_row(srcy, 32, 32, GL_TEXTURE_2D);
+	srcy += 33 + 5;
+
+
+	/* Test non-power-of-two 2D textures.
+	 */
+	if (have_NPOT) {
+		pass &= do_row(srcy, 31, 13, GL_TEXTURE_2D);
+		srcy += 15;
+		pass &= do_row(srcy, 11, 34, GL_TEXTURE_2D);
+		srcy += 35 + 5;
+	}
+
+
+	/* Test non-power-of-two 2D textures.
+	 */
+	if (have_rect) {
+		pass &= do_row(srcy, 31, 13, GL_TEXTURE_RECTANGLE_ARB);
+		srcy += 14;
+		pass &= do_row(srcy, 11, 34, GL_TEXTURE_RECTANGLE_ARB);
+		srcy += 35 + 5;
+	}
+
+	piglit_present_results();
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_direct_state_access");
+
+	glDisable(GL_DITHER);
+
+	glMatrixMode( GL_PROJECTION );
+	glPushMatrix();
+	glLoadIdentity();
+	glOrtho( 0, piglit_width, 0, piglit_height, -1, 1 );
+
+	glMatrixMode( GL_MODELVIEW );
+	glPushMatrix();
+	glLoadIdentity();
+
+	glClearColor(0.5, 0.5, 0.5, 1.0);
+
+	have_NPOT = (piglit_get_gl_version() >= 20
+		|| (piglit_is_extension_supported("GL_ARB_texture_non_power_of_two")));
+
+	have_rect = ((piglit_is_extension_supported("GL_ARB_texture_rectangle"))
+		|| (piglit_is_extension_supported("GL_EXT_texture_rectangle"))
+		|| (piglit_is_extension_supported("GL_NV_texture_rectangle")));
+}
diff --git a/tests/spec/arb_direct_state_access/texture-errors.c b/tests/spec/arb_direct_state_access/texture-errors.c
new file mode 100644
index 0000000..bcaa6b2
--- /dev/null
+++ b/tests/spec/arb_direct_state_access/texture-errors.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2010 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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
+ * NON-INFRINGEMENT.  IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
+ * 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
+ * Adapted from teximage-errors.c to test ARB_direct_state_access by
+ * Laura Ekstrand <laura at jlekstrand.net>.
+ * Tests glTextureSubImage functions for invalid values, error reporting.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+	config.supports_gl_core_version = 31;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+/** Test texture size errors and subtexture position errors */
+static GLboolean
+test_pos_and_sizes(void)
+{
+   GLuint name;
+
+   /* all of these should generate GL_INVALID_VALUE */
+
+   glTexImage1D(GL_TEXTURE_1D, 0, GL_RGBA, -16, 0, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, -6, -5, 0, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+   glTexImage2D(GL_TEXTURE_2D, -2, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+   glTexImage2D(GL_TEXTURE_2D, 2000, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+   /* Setup dsa. */
+   glCreateTextures(GL_TEXTURE_2D, 1, &name);
+   glBindTextureUnit(0, name); /* Since next command isn't bindless. */
+
+   /* setup valid 2D texture for subsequent TexSubImage calls */
+   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_FLOAT, NULL);
+
+   glTextureSubImage2D(name, 0, 6, 6, 100, 100, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+   glTextureSubImage2D(name, 0, -6, -6, 10, 10, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+
+   glCopyTextureSubImage2D(name, 0, -6, -6, 2, 2, 10, 10);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+   glCopyTextureSubImage2D(name, 0, 6, 6, 2, 2, 200, 200);
+   if (!piglit_check_gl_error(GL_INVALID_VALUE))
+      return GL_FALSE;
+
+   /* mipmap level 1 doesn't exist */
+   glTextureSubImage2D(name, 1, 0, 0, 8, 8, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+      return GL_FALSE;
+
+   /* mipmap level 2 doesn't exist */
+   glCopyTextureSubImage2D(name, 2, 0, 0, 0, 0, 4, 4);
+   if (!piglit_check_gl_error(GL_INVALID_OPERATION))
+      return GL_FALSE;
+
+   /* To test 1D and 3D entry points, let's try using the wrong functions. */
+   glTextureSubImage1D(name, 0, 0, 4, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_ENUM))
+      return GL_FALSE;
+
+   glTextureSubImage3D(name, 0, 0, 0, 0, 4, 4, 4, GL_RGBA, GL_FLOAT, NULL);
+   if (!piglit_check_gl_error(GL_INVALID_ENUM))
+      return GL_FALSE;
+
+   glCopyTextureSubImage1D(name, 0, 0, 0, 0, 4);
+   if (!piglit_check_gl_error(GL_INVALID_ENUM))
+      return GL_FALSE;
+
+   glCopyTextureSubImage3D(name, 0, 0, 0, 0, 0, 0, 4, 4);
+   if (!piglit_check_gl_error(GL_INVALID_ENUM))
+      return GL_FALSE;
+
+   return GL_TRUE;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+   bool pass = true;
+   pass = test_pos_and_sizes() && pass;
+
+   return pass ? PIGLIT_PASS: PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_direct_state_access");
+}
-- 
2.1.0



More information about the Piglit mailing list