[Piglit] [PATCH 1/2] getteximage-targets: test glGetTexImage with all texture targets

Marek Olšák maraeo at gmail.com
Fri Dec 21 07:11:10 PST 2012


---
 tests/all.tests                       |   11 ++
 tests/texturing/CMakeLists.gl.txt     |    1 +
 tests/texturing/getteximage-targets.c |  220 +++++++++++++++++++++++++++++++++
 3 files changed, 232 insertions(+)
 create mode 100644 tests/texturing/getteximage-targets.c

diff --git a/tests/all.tests b/tests/all.tests
index c823bcf..87d8990 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -545,6 +545,8 @@ add_plain_test(gl11, 'texredefine')
 add_plain_test(gl11, 'texsubimage')
 add_plain_test(gl11, 'texture-al')
 add_concurrent_test(gl11, 'triangle-guardband-viewport')
+add_concurrent_test(gl11, 'getteximage-targets 1D')
+add_concurrent_test(gl11, 'getteximage-targets 2D')
 
 gl10 = Group()
 spec['!OpenGL 1.0'] = gl10
@@ -568,6 +570,7 @@ add_plain_test(gl12, 'tex3d')
 add_plain_test(gl12, 'tex3d-maxsize')
 add_plain_test(gl12, 'teximage-errors')
 add_plain_test(gl12, 'texture-packed-formats')
+add_concurrent_test(gl12, 'getteximage-targets 3D')
 
 gl13 = Group()
 spec['!OpenGL 1.3'] = gl13
@@ -1623,6 +1626,8 @@ ext_texture_array['copyteximage 2D_ARRAY'] = PlainExecTest(['copyteximage', '-au
 add_plain_test(ext_texture_array, 'fbo-array')
 add_plain_test(ext_texture_array, 'fbo-depth-array')
 add_plain_test(ext_texture_array, 'array-texture')
+add_concurrent_test(ext_texture_array, 'getteximage-targets 1D_ARRAY')
+add_concurrent_test(ext_texture_array, 'getteximage-targets 2D_ARRAY')
 
 arb_texture_cube_map = Group()
 spec['ARB_texture_cube_map'] = arb_texture_cube_map
@@ -1633,6 +1638,7 @@ arb_texture_cube_map['cubemap npot'] = PlainExecTest(['cubemap', '-auto', 'npot'
 add_plain_test(arb_texture_cube_map, 'cubemap-shader')
 arb_texture_cube_map['cubemap-shader lod'] = PlainExecTest(['cubemap-shader', '-auto', 'lod'])
 arb_texture_cube_map['cubemap-shader bias'] = PlainExecTest(['cubemap-shader', '-auto', 'bias'])
+add_concurrent_test(arb_texture_cube_map, 'getteximage-targets CUBE')
 
 arb_texture_cube_map_array = Group()
 spec['ARB_texture_cube_map_array'] = arb_texture_cube_map_array
@@ -1642,6 +1648,7 @@ add_plain_test(arb_texture_cube_map_array, 'arb_texture_cube_map_array-cubemap')
 add_plain_test(arb_texture_cube_map_array, 'arb_texture_cube_map_array-cubemap-lod')
 add_plain_test(arb_texture_cube_map_array, 'arb_texture_cube_map_array-fbo-cubemap-array')
 add_plain_test(arb_texture_cube_map_array, 'arb_texture_cube_map_array-sampler-cube-array-shadow')
+add_concurrent_test(arb_texture_cube_map_array, 'getteximage-targets CUBE_ARRAY')
 textureSize_samplers_atcma = ['samplerCubeArray', 'isamplerCubeArray', 'usamplerCubeArray', 'samplerCubeArrayShadow' ];
 
 import_glsl_parser_tests(arb_texture_cube_map_array,
@@ -1693,6 +1700,10 @@ add_plain_test(ext_texture_compression_s3tc, 'gen-compressed-teximage')
 add_concurrent_test(ext_texture_compression_s3tc, 's3tc-errors')
 add_plain_test(ext_texture_compression_s3tc, 's3tc-teximage')
 add_plain_test(ext_texture_compression_s3tc, 's3tc-texsubimage')
+add_concurrent_test(ext_texture_compression_s3tc, 'getteximage-targets S3TC 2D')
+add_concurrent_test(ext_texture_compression_s3tc, 'getteximage-targets S3TC 2D_ARRAY')
+add_concurrent_test(ext_texture_compression_s3tc, 'getteximage-targets S3TC CUBE')
+add_concurrent_test(ext_texture_compression_s3tc, 'getteximage-targets S3TC CUBE_ARRAY')
 
 ati_texture_compression_3dc = Group()
 spec['ATI_texture_compression_3dc'] = ati_texture_compression_3dc
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index 9a9ac62..c9e5d11 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -30,6 +30,7 @@ piglit_add_executable (gen-texsubimage gen-texsubimage.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)
+piglit_add_executable (getteximage-targets getteximage-targets.c)
 piglit_add_executable (incomplete-texture incomplete-texture.c)
 piglit_add_executable (fragment-and-vertex-texturing fragment-and-vertex-texturing.c)
 piglit_add_executable (levelclamp levelclamp.c)
diff --git a/tests/texturing/getteximage-targets.c b/tests/texturing/getteximage-targets.c
new file mode 100644
index 0000000..64b7e78
--- /dev/null
+++ b/tests/texturing/getteximage-targets.c
@@ -0,0 +1,220 @@
+/*
+ * Copyright © 2012 Marek Olšák <maraeo at gmail.com>
+ *
+ * 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.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 10;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_ALPHA |
+			       PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+enum piglit_result
+piglit_display(void)
+{
+	puts("got into unreachable code");
+	return PIGLIT_FAIL;
+}
+
+static void init_layer_data(GLubyte *data)
+{
+	int x, y, i, j;
+
+	for (x = 0; x < 32; x += 4) {
+		for (y = 0; y < 32; y += 4) {
+			int r = rand() & 0xff;
+			int g = rand() & 0xff;
+			int b = rand() & 0xff;
+			int a = rand() & 0xff;
+			/* each 4x4 block constains only one color */
+			for (i = 0; i < 4; i++) {
+				for (j = 0; j < 4; j++) {
+					data[((y+j)*32 + x+i)*4 + 0] = r;
+					data[((y+j)*32 + x+i)*4 + 1] = g;
+					data[((y+j)*32 + x+i)*4 + 2] = b;
+					data[((y+j)*32 + x+i)*4 + 3] = a;
+				}
+			}
+		}
+	}
+}
+
+static void compare_layer(int layer, int num_elements, GLubyte *data, GLubyte *expected)
+{
+	int i;
+
+	for (i = 0; i < num_elements; ++i) {
+		if (abs((int)data[i] - (int)expected[i]) > 8) {
+			printf("GetTexImage() returns incorrect data in byte %i for layer %i\n",
+			       i, layer);
+			printf("    corresponding to (%i,%i), channel %i\n",
+			       (i / 4) / 32, (i / 4) % 32, i % 4);
+			printf("    expected: %i\n", expected[i]);
+			printf("    got: %i\n", data[i]);
+			piglit_report_result(PIGLIT_FAIL);
+		}
+	}
+}
+
+void piglit_init(int argc, char **argv)
+{
+	int i;
+	GLenum target = GL_TEXTURE_2D;
+	GLenum internalformat = GL_RGBA8;
+	GLubyte data[18][4096], data2[18][4096];
+
+	memset(data2, 123, sizeof(data2));
+
+	piglit_require_extension("GL_EXT_texture_compression_s3tc");
+	piglit_gen_ortho_projection(0.0, 1.0, 0.0, 1.0, -2.0, 6.0, GL_FALSE);
+
+	for (i = 1; i < argc; i++) {
+		if (strcmp(argv[i], "1D") == 0) {
+			target = GL_TEXTURE_1D;
+		}
+		if (strcmp(argv[i], "3D") == 0) {
+			target = GL_TEXTURE_3D;
+			piglit_require_gl_version(12);
+		}
+		if (strcmp(argv[i], "CUBE") == 0) {
+			target = GL_TEXTURE_CUBE_MAP;
+			piglit_require_extension("GL_ARB_texture_cube_map");
+		}
+		if (strcmp(argv[i], "1D_ARRAY") == 0) {
+			target = GL_TEXTURE_1D_ARRAY;
+			piglit_require_extension("GL_EXT_texture_array");
+		}
+		if (strcmp(argv[i], "2D_ARRAY") == 0) {
+			target = GL_TEXTURE_2D_ARRAY;
+			piglit_require_extension("GL_EXT_texture_array");
+		}
+		if (strcmp(argv[i], "CUBE_ARRAY") == 0) {
+			target = GL_TEXTURE_CUBE_MAP_ARRAY;
+			piglit_require_extension("GL_ARB_texture_cube_map_array");
+		}
+		if (strcmp(argv[i], "S3TC") == 0) {
+			internalformat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+			piglit_require_extension("GL_EXT_texture_compression_s3tc");
+			puts("Testing S3TC.");
+		}
+	}
+
+	switch (target) {
+	case GL_TEXTURE_1D:
+		puts("Testing TEXTURE_1D.");
+		init_layer_data(data[0]);
+		glTexImage1D(GL_TEXTURE_1D, 0, internalformat, 32, 0,
+			     GL_RGBA, GL_UNSIGNED_BYTE, data);
+		glGetTexImage(GL_TEXTURE_1D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);
+		piglit_check_gl_error(GL_NO_ERROR);
+		compare_layer(0, 128, data2[0], data[0]);
+		piglit_report_result(PIGLIT_PASS);
+
+	case GL_TEXTURE_2D:
+		puts("Testing TEXTURE_2D.");
+		init_layer_data(data[0]);
+		glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 32, 32, 0,
+			     GL_RGBA, GL_UNSIGNED_BYTE, data);
+		glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);
+		piglit_check_gl_error(GL_NO_ERROR);
+		compare_layer(0, 4096, data2[0], data[0]);
+		piglit_report_result(PIGLIT_PASS);
+
+	case GL_TEXTURE_3D:
+		puts("Testing TEXTURE_3D.");
+		for (i = 0; i < 16; i++) {
+			init_layer_data(data[i]);
+		}
+		glTexImage3D(GL_TEXTURE_3D, 0, internalformat,
+			     32, 32, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+		glGetTexImage(GL_TEXTURE_3D, 0,
+			      GL_RGBA, GL_UNSIGNED_BYTE, data2);
+		piglit_check_gl_error(GL_NO_ERROR);
+		for (i = 0; i < 16; i++) {
+			compare_layer(i, 4096, data2[i], data[i]);
+		}
+		piglit_report_result(PIGLIT_PASS);
+
+	case GL_TEXTURE_CUBE_MAP:
+		puts("Testing TEXTURE_CUBE_MAP.");
+		for (i = 0; i < 6; i++) {
+			init_layer_data(data[i]);
+			glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+				     internalformat, 32, 32, 0, GL_RGBA,
+				     GL_UNSIGNED_BYTE, data[i]);
+		}
+		for (i = 0; i < 6; i++) {
+			glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+				      GL_RGBA, GL_UNSIGNED_BYTE, data2[i]);
+			piglit_check_gl_error(GL_NO_ERROR);
+			compare_layer(i, 4096, data2[i], data[i]);
+		}
+		piglit_report_result(PIGLIT_PASS);
+
+	case GL_TEXTURE_1D_ARRAY:
+		puts("Testing TEXTURE_1D_ARRAY.");
+		init_layer_data(data[0]);
+		glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalformat, 32, 7, 0,
+			     GL_RGBA, GL_UNSIGNED_BYTE, data);
+		glGetTexImage(GL_TEXTURE_1D_ARRAY, 0, GL_RGBA, GL_UNSIGNED_BYTE, data2);
+		piglit_check_gl_error(GL_NO_ERROR);
+		compare_layer(0, 128*7, data2[0], data[0]);
+		piglit_report_result(PIGLIT_PASS);
+
+	case GL_TEXTURE_2D_ARRAY:
+		puts("Testing TEXTURE_2D_ARRAY.");
+		for (i = 0; i < 7; i++) {
+			init_layer_data(data[i]);
+		}
+		glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalformat,
+			     32, 32, 7, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+		glGetTexImage(GL_TEXTURE_2D_ARRAY, 0,
+			      GL_RGBA, GL_UNSIGNED_BYTE, data2);
+		piglit_check_gl_error(GL_NO_ERROR);
+		for (i = 0; i < 7; i++) {
+			compare_layer(i, 4096, data2[i], data[i]);
+		}
+		piglit_report_result(PIGLIT_PASS);
+
+	case GL_TEXTURE_CUBE_MAP_ARRAY:
+		puts("Testing TEXTURE_CUBE_MAP_ARRAY.");
+		for (i = 0; i < 18; i++) {
+			init_layer_data(data[i]);
+		}
+		glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalformat,
+			     32, 32, 18, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+		glGetTexImage(GL_TEXTURE_CUBE_MAP_ARRAY, 0,
+			      GL_RGBA, GL_UNSIGNED_BYTE, data2);
+		piglit_check_gl_error(GL_NO_ERROR);
+		for (i = 0; i < 18; i++) {
+			compare_layer(i, 4096, data2[i], data[i]);
+		}
+		piglit_report_result(PIGLIT_PASS);
+	}
+
+	puts("Invalid texture target.");
+	piglit_report_result(PIGLIT_FAIL);
+}
-- 
1.7.10.4



More information about the Piglit mailing list