summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura Ekstrand <laura@jlekstrand.net>2015-02-19 13:08:27 -0800
committerLaura Ekstrand <laura@jlekstrand.net>2015-04-02 17:57:42 -0700
commitc95c25381c30803260c38a85ca24383df3a64992 (patch)
tree21769be4d8c90343916f4cf3210ab751acbf2f00
parentd1d8dd35642f793a4d606de7cf8c244bced93f03 (diff)
texturing: New test for GetTexImage targets.
-rw-r--r--tests/all.py1
-rw-r--r--tests/texturing/CMakeLists.gl.txt1
-rw-r--r--tests/texturing/getteximage-targets.c229
3 files changed, 231 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py
index 787e42803..38569950d 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -1089,6 +1089,7 @@ with profile.group_manager(
g(['max-samplers'])
g(['max-samplers', 'border'])
g(['gl-2.0-active-sampler-conflict'])
+ g(['getteximage-targets']);
with profile.group_manager(
PiglitGLTest,
diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index 56302a337..5aefdd675 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -35,6 +35,7 @@ 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 (incomplete-texture incomplete-texture.c)
+piglit_add_executable (getteximage-targets getteximage-targets.c)
piglit_add_executable (fragment-and-vertex-texturing fragment-and-vertex-texturing.c)
piglit_add_executable (levelclamp levelclamp.c)
piglit_add_executable (lodbias lodbias.c)
diff --git a/tests/texturing/getteximage-targets.c b/tests/texturing/getteximage-targets.c
new file mode 100644
index 000000000..65666d0d0
--- /dev/null
+++ b/tests/texturing/getteximage-targets.c
@@ -0,0 +1,229 @@
+/*
+ * Copyright 2015 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 getteximage-targets.c
+ *
+ * Tests to make sure that glGetTexImage works correctly.
+ * The basic idea is to create some data, upload it to the
+ * driver, download it, and compare.
+ */
+
+#include "piglit-util-gl.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
+
+#define WIDTH 32
+#define HEIGHT 32
+#define IMAGE_SIZE (WIDTH * HEIGHT * 4)
+#define CHAR_LIMIT 100
+
+static GLubyte *expected;
+static bool global_pass = true;
+
+static void
+subtest(bool local_result, const char *test_name)
+{
+ global_pass = local_result && global_pass;
+ piglit_report_subtest_result(local_result ? PIGLIT_PASS : PIGLIT_FAIL,
+ test_name);
+}
+
+static void
+init_random_data(void)
+{
+ int i;
+
+ expected = malloc(18 * IMAGE_SIZE);
+ for (i = 0; i < 18 * IMAGE_SIZE; ++i) {
+ expected[i] = (GLubyte) rand();
+ }
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ srand(0);
+ init_random_data();
+}
+
+static bool
+compare_to_expected(const GLubyte *data, int num_layers)
+{
+ return memcmp(expected, data, num_layers * IMAGE_SIZE) == 0;
+}
+
+static void
+traditional_download(GLenum target, int num_layers, GLubyte *data)
+{
+ int i;
+
+ /* Download it using traditional path */
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ for (i = 0; i < num_layers; ++i) {
+ glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE,
+ data + i * IMAGE_SIZE);
+ }
+ }
+ else
+ glGetTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+}
+
+static void
+upload_subtest(GLenum target, bool use_pbo)
+{
+ GLuint tex, pbo_pack, pbo_unpack;
+ int num_layers;
+ char test_name [CHAR_LIMIT];
+ int i;
+ GLubyte *data = expected;
+ bool pass = true;
+
+ /* Prepare to read data from expected */
+ if (use_pbo) {
+ glGenBuffers(1, &pbo_unpack);
+ glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_unpack);
+ glBufferData(GL_PIXEL_UNPACK_BUFFER, 18 * IMAGE_SIZE,
+ expected, GL_STATIC_DRAW);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+ data = NULL;
+ }
+
+ /* Upload it using traditional path */
+ glGenTextures(1, &tex);
+ glBindTexture(target, tex);
+
+ switch (target) {
+
+ case GL_TEXTURE_1D:
+ num_layers = 1;
+ glTexImage1D(target, 0, GL_RGBA8, WIDTH * HEIGHT, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, data);
+ break;
+ case GL_TEXTURE_1D_ARRAY: /* FALLTHROUGH */
+ case GL_TEXTURE_RECTANGLE: /* FALLTHROUGH */
+ case GL_TEXTURE_2D:
+ num_layers = 1;
+ glTexImage2D(target, 0, GL_RGBA8, WIDTH, HEIGHT, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, data);
+ break;
+ case GL_TEXTURE_3D: /* FALLTHROUGH */
+ case GL_TEXTURE_2D_ARRAY:
+ num_layers = 3;
+ glTexImage3D(target, 0, GL_RGBA8, WIDTH, HEIGHT, num_layers,
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ num_layers = 6;
+ for (i = 0; i < num_layers; ++i) {
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
+ 0, GL_RGBA8, WIDTH, HEIGHT, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, data + i * IMAGE_SIZE);
+ }
+ break;
+ case GL_TEXTURE_CUBE_MAP_ARRAY:
+ num_layers = 18;
+ glTexImage3D(target, 0, GL_RGBA8, WIDTH, HEIGHT,
+ num_layers, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ break;
+ default:
+ printf("Bad texture target.\n");
+ piglit_report_result(PIGLIT_FAIL);
+
+ }
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ /* Download it using traditional path */
+ if (use_pbo) {
+ /* Prepare PBO */
+ GLubyte *junk = malloc(18 * IMAGE_SIZE);
+ memset(junk, 123, 18 * IMAGE_SIZE);
+ glGenBuffers(1, &pbo_pack);
+ glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo_pack);
+ glBufferData(GL_PIXEL_PACK_BUFFER, 18 * IMAGE_SIZE,
+ junk, GL_STATIC_READ);
+ free(junk);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ /* Do the transfer */
+ traditional_download(target, num_layers, (void *) 0);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ /* Map the data */
+ data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+ }
+ else {
+ data = malloc(18 * IMAGE_SIZE);
+ traditional_download(target, num_layers, data);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+ }
+
+
+ /* Perform comparison and report the results. */
+ snprintf(test_name, CHAR_LIMIT, "upload %s%s",
+ piglit_get_gl_enum_name(target), use_pbo ? " PBO" : "");
+ pass = compare_to_expected(data, num_layers) && pass;
+ subtest(pass, test_name);
+
+ /* Clean up */
+ glDeleteTextures(1, &tex);
+ if (use_pbo) {
+ glDeleteBuffers(1, &pbo_unpack);
+ glDeleteBuffers(1, &pbo_pack);
+ }
+ else
+ free(data);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ int i;
+
+ for (i = 0; i < 2; ++i) {
+ upload_subtest(GL_TEXTURE_1D, (bool) i);
+ upload_subtest(GL_TEXTURE_2D, (bool) i);
+ upload_subtest(GL_TEXTURE_3D, (bool) i);
+ if (piglit_is_extension_supported("GL_ARB_texture_rectangle"))
+ upload_subtest(GL_TEXTURE_RECTANGLE, (bool) i);
+ if (piglit_is_extension_supported("GL_EXT_texture_array")) {
+ upload_subtest(GL_TEXTURE_1D_ARRAY, (bool) i);
+ upload_subtest(GL_TEXTURE_2D_ARRAY, (bool) i);
+ }
+ upload_subtest(GL_TEXTURE_CUBE_MAP, (bool) i);
+ if (piglit_is_extension_supported(
+ "GL_ARB_texture_cube_map_array"))
+ upload_subtest(GL_TEXTURE_CUBE_MAP_ARRAY, (bool) i);
+ }
+
+
+ return global_pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}