[Mesa-dev] [PATCH] Add a test for GL_EXT_unpack_subimage on GLES2

Neil Roberts neil at linux.intel.com
Mon Mar 26 10:51:15 PDT 2012


The GL_EXT_unpack_subimage extension just allows GL_UNPACK_ROW_LENGTH,
GL_UNPACK_SKIP_PIXELS and GL_UNPACK_SKIP_ROWS on GLES2. This tries
setting those three values and if the extension is available it will
assert that no error is thrown, otherwise it will assert that
GL_INVALID_ENUM is thrown. It will then try to upload some texture
data with those settings in such a way that if the values were
correctly set it will have one pair of pixels otherwise it will have
another. The texture is then rendered to the framebuffer and the
pixels are compared so it can verify whether the unpack settings were
handled correctly.

As far as I can tell, this is the first GLES2 test so the patch also
creates an all_es2.tests file to contain it.
---
 tests/all_es2.tests                                |   20 ++
 tests/spec/CMakeLists.txt                          |    1 +
 .../spec/ext_unpack_subimage/CMakeLists.gles2.txt  |   18 ++
 tests/spec/ext_unpack_subimage/CMakeLists.txt      |    1 +
 .../spec/ext_unpack_subimage/ext_unpack_subimage.c |  228 ++++++++++++++++++++
 5 files changed, 268 insertions(+), 0 deletions(-)
 create mode 100644 tests/all_es2.tests
 create mode 100644 tests/spec/ext_unpack_subimage/CMakeLists.gles2.txt
 create mode 100644 tests/spec/ext_unpack_subimage/CMakeLists.txt
 create mode 100644 tests/spec/ext_unpack_subimage/ext_unpack_subimage.c

diff --git a/tests/all_es2.tests b/tests/all_es2.tests
new file mode 100644
index 0000000..64e5570
--- /dev/null
+++ b/tests/all_es2.tests
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# All GLESv2 tests that come with piglit, using default settings
+
+from framework.core import *
+from framework.exectest import *
+
+######
+# Collecting all tests
+profile = TestProfile()
+
+spec = Group()
+
+# Group ext_unpack_subimage
+ext_unpack_subimage = Group()
+spec['EXT_unpack_subimage'] = ext_unpack_subimage
+ext_unpack_subimage['basic'] = PlainExecTest(['ext_unpack_subimage', '-auto'])
+ext_unpack_subimage['basic'].runConcurrent = True
+
+profile.tests['spec'] = spec
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 93f0681..28afacc 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -49,3 +49,4 @@ add_subdirectory (ext_texture_integer)
 add_subdirectory (arb_draw_buffers)
 add_subdirectory (oes_draw_texture)
 add_subdirectory (arb_blend_func_extended)
+add_subdirectory (ext_unpack_subimage)
diff --git a/tests/spec/ext_unpack_subimage/CMakeLists.gles2.txt b/tests/spec/ext_unpack_subimage/CMakeLists.gles2.txt
new file mode 100644
index 0000000..de58843
--- /dev/null
+++ b/tests/spec/ext_unpack_subimage/CMakeLists.gles2.txt
@@ -0,0 +1,18 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+	${OPENGL_INCLUDE_PATH}
+	)
+
+link_libraries(
+	${OPENGL_gles2_LIBRARY}
+	${OPENGL_egl_LIBRARY}
+	glut_egl
+	piglitutil_gles2
+	)
+
+piglit_add_executable(ext_unpack_subimage
+	ext_unpack_subimage.c
+	)
+
+# vim: ft=cmake:
diff --git a/tests/spec/ext_unpack_subimage/CMakeLists.txt b/tests/spec/ext_unpack_subimage/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/ext_unpack_subimage/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/ext_unpack_subimage/ext_unpack_subimage.c b/tests/spec/ext_unpack_subimage/ext_unpack_subimage.c
new file mode 100644
index 0000000..255986e
--- /dev/null
+++ b/tests/spec/ext_unpack_subimage/ext_unpack_subimage.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright © 2012 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.
+ *
+ * Author: Neil Roberts <neil at linux.intel.com>
+ */
+
+/** @file ext_unpack_subimage.c
+ *
+ * Test GL_EXT_unpack_subimage.
+ */
+
+#include <EGL/egl.h>
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static GLboolean extension_supported;
+static GLboolean pass;
+
+static const GLubyte
+tex_data[] = {
+	/* Row 0. This is skipped if the extension is available,
+	   otherwise it makes the top and bottom texel */
+	0xff, 0x00, 0x00, 0xff, /* red */
+	0x00, 0xff, 0x00, 0xff, /* green */
+	/* Row 1. skipped */
+	0x00, 0x00, 0x00, 0xff,
+	0x00, 0x00, 0x00, 0xff,
+	/* Row 2. skipped */
+	0x00, 0x00, 0x00, 0xff,
+	0x00, 0x00, 0x00, 0xff,
+	/* Row 3. skipped */
+	0x00, 0x00, 0x00, 0xff,
+	0x00, 0x00, 0x00, 0xff,
+	/* Row 4. This is the first row used if the extension is
+	   available */
+	/* The first pixel is skipped */
+	0x00, 0x00, 0x00, 0xff,
+	/* This texel becomes the top texel */
+	0x00, 0x00, 0xff, 0xff, /* blue */
+	/* Row 5. first texel not used */
+	0x00, 0x00, 0x00, 0x00,
+	/* second texel becomes the bottom texel */
+	0x00, 0xff, 0xff, 0xff /* cyan */
+};
+
+static const char
+vertex_shader[] =
+	"attribute vec4 pos_attrib;\n"
+	"attribute vec2 tex_attrib;\n"
+	"varying vec2 tex_coord;\n"
+	"void main () {\n"
+	"gl_Position = pos_attrib;\n"
+	"tex_coord = tex_attrib;\n"
+	"}\n";
+
+static const char
+fragment_shader[] =
+	"uniform sampler2D tex;\n"
+	"varying vec2 tex_coord;\n"
+	"void main () {\n"
+	"gl_FragColor = texture2D(tex, tex_coord);\n"
+	"}\n";
+
+static void
+check_error(void)
+{
+	if (extension_supported) {
+		if (!piglit_check_gl_error(GL_NO_ERROR))
+			pass = GL_FALSE;
+	} else {
+		if (!piglit_check_gl_error(GL_INVALID_ENUM))
+			pass = GL_FALSE;
+	}
+}
+
+static GLuint
+make_shader(GLenum type,
+	    const char *source)
+{
+	GLuint shader;
+	GLint length = strlen (source);
+	GLint status;
+
+	shader = glCreateShader(type);
+	glShaderSource(shader, 1, &source, &length);
+	glCompileShader(shader);
+	glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
+
+	if (!status)
+		fprintf(stderr, "Shader compilation failed\n");
+
+	return shader;
+}
+
+static void
+make_program(const char *vertex_source,
+	     const char *fragment_source)
+{
+	GLuint program, shader;
+	GLuint uniform;
+	GLint status;
+
+	program = glCreateProgram();
+	shader = make_shader(GL_VERTEX_SHADER, vertex_source);
+	glAttachShader(program, shader);
+	shader = make_shader(GL_FRAGMENT_SHADER, fragment_source);
+	glAttachShader(program, shader);
+
+	glBindAttribLocation(program, PIGLIT_ATTRIB_POS, "pos_attrib");
+	glBindAttribLocation(program, PIGLIT_ATTRIB_TEX, "tex_attrib");
+
+	glLinkProgram(program);
+
+	glGetShaderiv(program, GL_LINK_STATUS, &status);
+	if (!status)
+		fprintf(stderr, "Program linking failed\n");
+
+	uniform = glGetUniformLocation(program, "tex");
+	glUseProgram(program);
+	glUniform1i(uniform, 0);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLuint tex;
+	static const float red[] = { 1, 0, 0, 1 };
+	static const float green[] = { 0, 1, 0, 1 };
+	static const float blue[] = { 0, 0, 1, 1 };
+	static const float cyan[] = { 0, 1, 1, 1 };
+
+	pass = GL_TRUE;
+
+	extension_supported =
+		piglit_is_extension_supported("GL_EXT_unpack_subimage");
+
+	if (!piglit_automatic) {
+		if (extension_supported)
+			printf("GL_EXT_unpack_subimage is supported\n");
+		else
+			printf("GL_EXT_unpack_subimage is not supported\n");
+	}
+
+	piglit_reset_gl_error();
+	if (!piglit_automatic)
+		printf("Trying GL_UNPACK_ROW_LENGTH\n");
+	glPixelStorei(GL_UNPACK_ROW_LENGTH, 2);
+	check_error();
+
+	piglit_reset_gl_error();
+	if (!piglit_automatic)
+		printf("Trying GL_UNPACK_SKIP_PIXELS\n");
+	glPixelStorei(GL_UNPACK_SKIP_PIXELS, 1);
+	check_error();
+
+	piglit_reset_gl_error();
+	if (!piglit_automatic)
+		printf("Trying GL_UNPACK_SKIP_ROWS\n");
+	glPixelStorei(GL_UNPACK_SKIP_ROWS, 4);
+	check_error();
+
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/* Try creating a texture with the unpacking parameters we've set */
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexImage2D(GL_TEXTURE_2D,
+		     0, /* level */
+		     GL_RGBA, /* internalFormat */
+		     1, /* width */
+		     2, /* height */
+		     0, /* border */
+		     GL_RGBA, /* format */
+		     GL_UNSIGNED_BYTE, /* type */
+		     tex_data);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+	make_program(vertex_shader, fragment_shader);
+
+	piglit_draw_rect_tex(-1, -1, 2, 2,
+			     0, 0, 1, 1);
+
+	if (extension_supported) {
+		pass &= piglit_probe_pixel_rgba(piglit_width / 2,
+						piglit_height / 4,
+						blue);
+		pass &= piglit_probe_pixel_rgba(piglit_width / 2,
+						piglit_height * 3 / 4,
+						cyan);
+	} else {
+		pass &= piglit_probe_pixel_rgba(piglit_width / 2,
+						piglit_height / 4,
+						red);
+		pass &= piglit_probe_pixel_rgba(piglit_width / 2,
+						piglit_height * 3 / 4,
+						green);
+	}
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+}
-- 
1.7.3.16.g9464b



More information about the mesa-dev mailing list