[Piglit] [PATCH v3 1/5] spec/ARB_copy_image: Add a simple ARB_copy_image test

Jason Ekstrand jason at jlekstrand.net
Thu Aug 7 17:35:07 PDT 2014


This is a simple sanity test for the ARB_copy_image extension.  This tests
tests the different combinations of textures and renderbuffers for intputs
and outputs to glCopyTexSubImage.

v2: Incorperated comments from Brian Paul
v3: Also copy from the texture back onto itself to test yet another path

Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com>
---
 tests/all.py                                |   6 +
 tests/spec/CMakeLists.txt                   |   1 +
 tests/spec/arb_copy_image/CMakeLists.gl.txt |  13 ++
 tests/spec/arb_copy_image/CMakeLists.txt    |   1 +
 tests/spec/arb_copy_image/simple.c          | 215 ++++++++++++++++++++++++++++
 5 files changed, 236 insertions(+)
 create mode 100644 tests/spec/arb_copy_image/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_copy_image/CMakeLists.txt
 create mode 100644 tests/spec/arb_copy_image/simple.c

diff --git a/tests/all.py b/tests/all.py
index 9d7a861..b551abe 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3332,6 +3332,12 @@ arb_copy_buffer['overlap'] = concurrent_test('arb_copy_buffer-overlap')
 arb_copy_buffer['targets'] = concurrent_test('arb_copy_buffer-targets')
 arb_copy_buffer['subdata-sync'] = concurrent_test('arb_copy_buffer-subdata-sync')
 
+arb_copy_image = {}
+spec['ARB_copy_image'] = arb_copy_image
+add_concurrent_test(arb_copy_image, 'arb_copy_image-simple --tex-to-tex')
+add_concurrent_test(arb_copy_image, 'arb_copy_image-simple --rb-to-tex')
+add_concurrent_test(arb_copy_image, 'arb_copy_image-simple --rb-to-rb')
+
 arb_half_float_vertex = {}
 spec['ARB_half_float_vertex'] = arb_half_float_vertex
 add_plain_test(arb_half_float_vertex, 'draw-vertices-half-float')
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index c7001f1..2fcb00e 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -4,6 +4,7 @@ add_subdirectory (arb_buffer_storage)
 add_subdirectory (arb_clear_buffer_object)
 add_subdirectory (arb_clear_texture)
 add_subdirectory (arb_color_buffer_float)
+add_subdirectory (arb_copy_image)
 add_subdirectory (arb_compute_shader)
 add_subdirectory (arb_debug_output)
 add_subdirectory (khr_debug)
diff --git a/tests/spec/arb_copy_image/CMakeLists.gl.txt b/tests/spec/arb_copy_image/CMakeLists.gl.txt
new file mode 100644
index 0000000..ac8ddcc
--- /dev/null
+++ b/tests/spec/arb_copy_image/CMakeLists.gl.txt
@@ -0,0 +1,13 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+)
+
+link_libraries (
+	piglitutil_${piglit_target_api}
+	${OPENGL_gl_LIBRARY}
+)
+
+piglit_add_executable (arb_copy_image-simple simple.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_copy_image/CMakeLists.txt b/tests/spec/arb_copy_image/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_copy_image/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_copy_image/simple.c b/tests/spec/arb_copy_image/simple.c
new file mode 100644
index 0000000..1138f3f
--- /dev/null
+++ b/tests/spec/arb_copy_image/simple.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright 2014 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 simple.c
+ *
+ * A simple test of glCopyImageSubData that copies a square from one
+ * 2D texture to another and back.  This test exercises texture to texture,
+ * texture to renderbuffer, renderbuffer to texture, and renderbuffer to
+ * renderbuffer copies.  This test also exercises copying from one texture
+ * or renderbuffer to the same texture or renderbuffer
+ */
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 13;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const float green[3] = {0.0, 1.0, 0.0};
+static const float red[3] = {1.0, 0.0, 0.0};
+static const float blue[3] = {0.0, 0.0, 1.0};
+
+int renderbuffers = 0;
+
+void
+piglit_init(int argc, char **argv)
+{
+	int i;
+
+	piglit_require_extension("GL_ARB_copy_image");
+	piglit_require_extension("GL_EXT_framebuffer_object");
+
+	for (i = 0; i < argc; ++i) {
+		if (strcmp(argv[i], "--tex-to-tex") == 0)
+			renderbuffers = 0;
+		else if (strcmp(argv[i], "--tex-to-rb") == 0)
+			renderbuffers = 1;
+		else if (strcmp(argv[i], "--rb-to-rb") == 0)
+			renderbuffers = 2;
+	}
+}
+
+struct image {
+	GLuint name, fbo;
+	GLenum target;
+};
+
+static void
+image_init(struct image *image, GLenum target, GLenum internalformat)
+{
+	image->target = target;
+
+	glGenFramebuffersEXT(1, &image->fbo);
+	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, image->fbo);
+
+	if (image->target == GL_RENDERBUFFER_EXT) {
+		glGenRenderbuffersEXT(1, &image->name);
+		glBindRenderbufferEXT(GL_RENDERBUFFER, image->name);
+		glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
+					 internalformat, 64, 64);
+		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,
+					     GL_COLOR_ATTACHMENT0_EXT,
+					     image->target, image->name);
+	} else {
+		glGenTextures(1, &image->name);
+		glBindTexture(image->target, image->name);
+		glTexImage2D(image->target, 0, internalformat,
+			     64, 64, 0, internalformat, GL_BYTE, NULL);
+		glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,
+					  GL_COLOR_ATTACHMENT0_EXT,
+					  image->target, image->name, 0);
+	}
+}
+
+static void
+image_destroy(struct image *image)
+{
+	if (image->target == GL_RENDERBUFFER_EXT)
+		glDeleteRenderbuffersEXT(1, &image->name);
+	else
+		glDeleteTextures(1, &image->name);
+
+	glDeleteFramebuffers(1, &image->fbo);
+}
+
+static void
+image_fill(struct image *image, const float *color)
+{
+	glClearColor(color[0], color[1], color[2], 1.0f);
+	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, image->fbo);
+	glClear(GL_COLOR_BUFFER_BIT);
+}
+
+static void
+image_draw(struct image *image, int x, int y)
+{
+	if (image->target == GL_RENDERBUFFER_EXT) {
+		glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, image->fbo);
+		glBlitFramebufferEXT(0, 0, 64, 64, x, y, x + 64, y + 64,
+				     GL_COLOR_BUFFER_BIT, GL_NEAREST);
+	} else {
+		/* Set up or GL environment for rendering */
+		piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+		glEnable(GL_TEXTURE_2D);
+		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+
+		glBindTexture(image->target, image->name);
+		piglit_draw_rect_tex(x, y, 64, 64, 0, 0, 1, 1);
+
+		glDisable(GL_TEXTURE_2D);
+	}
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	bool pass = true;
+	struct image images[2];
+
+	if (renderbuffers >= 1)
+		images[0].target = GL_RENDERBUFFER_EXT;
+	else
+		images[0].target = GL_TEXTURE_2D;
+
+	if (renderbuffers == 2)
+		images[1].target = GL_RENDERBUFFER_EXT;
+	else
+		images[1].target = GL_TEXTURE_2D;
+
+	image_init(&images[0], images[0].target, GL_RGB);
+	image_init(&images[1], images[1].target, GL_RGB);
+
+	image_fill(&images[0], green);
+	image_fill(&images[1], red);
+
+	glCopyImageSubData(images[0].name, images[0].target, 0, 0, 0, 0,
+			   images[1].name, images[1].target, 0, 17, 11, 0,
+			   32, 32, 1);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	/* We should now have a green square on red */
+	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, images[1].fbo);
+	pass &= piglit_probe_rect_rgb(17, 11, 32, 32, green);
+	pass &= piglit_probe_rect_rgb(0, 0, 64, 11, red);
+	pass &= piglit_probe_rect_rgb(0, 11, 17, 32, red);
+	pass &= piglit_probe_rect_rgb(49, 11, 15, 32, red);
+	pass &= piglit_probe_rect_rgb(0, 43, 64, 21, red);
+
+	image_fill(&images[0], blue);
+	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, images[0].fbo);
+	pass &= piglit_probe_rect_rgb(0, 0, 64, 64, blue);
+
+	glCopyImageSubData(images[1].name, images[1].target, 0, 17, 11, 0,
+			   images[0].name, images[0].target, 0, 0, 32, 0,
+			   32, 32, 1);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	/* This should be a green square on blue (no red!) */
+	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, images[0].fbo);
+	pass &= piglit_probe_rect_rgb(0, 32, 32, 32, green);
+	pass &= piglit_probe_rect_rgb(0, 0, 64, 32, blue);
+	pass &= piglit_probe_rect_rgb(32, 32, 32, 32, blue);
+
+	glCopyImageSubData(images[0].name, images[0].target, 0, 0, 32, 0,
+			   images[0].name, images[0].target, 0, 32, 0, 0,
+			   32, 32, 1);
+	pass &= piglit_check_gl_error(GL_NO_ERROR);
+
+	/* This should be a blue/green checkerboard */
+	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, images[0].fbo);
+	pass &= piglit_probe_rect_rgb(0, 0, 32, 32, blue);
+	pass &= piglit_probe_rect_rgb(0, 32, 32, 32, green);
+	pass &= piglit_probe_rect_rgb(32, 0, 32, 32, green);
+	pass &= piglit_probe_rect_rgb(32, 32, 32, 32, blue);
+
+	if (!piglit_automatic) {
+		glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT,
+				     piglit_winsys_fbo);
+
+		image_draw(&images[1], 0, 0);
+		image_draw(&images[0], 64, 0);
+
+		piglit_present_results();
+	}
+
+	image_destroy(&images[0]);
+	image_destroy(&images[1]);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
2.0.4



More information about the Piglit mailing list