[Piglit] [PATCH 1/1] Tests for compressed cubemaps

Eleni Maria Stea estea at igalia.com
Tue Jan 8 13:23:07 UTC 2019


The compressed-cubemap.c tests the rendering of compressed cubemaps.
The compressed-cubemap-teximage.c tests that compressed cubemaps created
using dumped compressed 2D faces have the same values with compressed
cubemaps that have been generated using TexImage.
---
 tests/texturing/CMakeLists.gl.txt             |   2 +
 tests/texturing/compressed-cubemap-teximage.c | 372 ++++++++++++++
 tests/texturing/compressed-cubemap.c          | 477 ++++++++++++++++++
 3 files changed, 851 insertions(+)
 create mode 100644 tests/texturing/compressed-cubemap-teximage.c
 create mode 100644 tests/texturing/compressed-cubemap.c

diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
index e5d41e432..526e68452 100644
--- a/tests/texturing/CMakeLists.gl.txt
+++ b/tests/texturing/CMakeLists.gl.txt
@@ -15,6 +15,8 @@ piglit_add_executable (array-texture array-texture.c)
 piglit_add_executable (bptc-modes bptc-modes.c)
 piglit_add_executable (bptc-float-modes bptc-float-modes.c)
 piglit_add_executable (compressedteximage compressedteximage.c)
+piglit_add_executable (compressed-cubemap compressed-cubemap.c)
+piglit_add_executable (compressed-cubemap-teximage compressed-cubemap-teximage.c)
 piglit_add_executable (copytexsubimage copytexsubimage.c)
 piglit_add_executable (copyteximage copyteximage.c)
 piglit_add_executable (copyteximage-border copyteximage-border.c)
diff --git a/tests/texturing/compressed-cubemap-teximage.c b/tests/texturing/compressed-cubemap-teximage.c
new file mode 100644
index 000000000..6727bea2d
--- /dev/null
+++ b/tests/texturing/compressed-cubemap-teximage.c
@@ -0,0 +1,372 @@
+/*
+ * Copyright © 2018 Igalia SL
+ *
+ * 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: Eleni Maria Stea <estea at igalia.com>
+ *
+ */
+
+/** @file compressed-cubemap-teximage.c
+ * Tests that creating cubemaps with TexImage2D gives the same results
+ * with creating compressed cubemaps from dumped compressed data.
+ */
+
+#include "cubemap-compressed-data.h"
+#include "piglit-util-gl.h"
+
+#define CUBESZ 8
+
+static int win_width = 800;
+static int win_height = 600;
+
+static const char *vsdr_src =
+	"attribute vec4 vertex;\n"
+	"attribute vec3 texcoord;\n"
+	"uniform vec2 rot;\n"
+	"varying vec3 tc;\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = vertex;\n"
+	"    tc.x = vertex.x * cos(rot.y) + sin(rot.y);\n"
+	"    tc.y = vertex.x * sin(rot.x) * sin(rot.y) + vertex.y * cos(rot.x) - sin(rot.x) * cos(rot.y);\n"
+	"    tc.z = vertex.x * cos(rot.x) * sin(rot.y) - vertex.y * sin(rot.x) - cos(rot.x) * cos(rot.y);\n"
+	"}\n";
+
+static const char *fsdr_src =
+	"uniform samplerCube tex;\n"
+	"varying vec3 tc;\n"
+	"void main()\n"
+	"{\n"
+	"    vec4 texel = textureCube(tex, tc);\n"
+	"    gl_FragColor = vec4(texel.xyz, 1.0);\n" "}\n";
+
+static int piglit_error;
+static unsigned int vbo, vao;
+static unsigned int sdrprog;
+static int uloc_rot;
+static const float tolerance[4] = { 0.1, 0.1, 0.1, 0.1 };
+
+struct
+{
+	unsigned int fmt;
+	const char *name;
+	unsigned int tex;
+	unsigned int ctex;
+	unsigned int num_channels;
+	unsigned char *data;
+	unsigned int data_size;
+} formats[] = {
+	{0x08e8c, "GL_COMPRESSED_RGBA_BPTC_UNORM", 0, 0, 4, bptc_rgba_unorm,
+		sizeof bptc_rgba_unorm},
+	{0x08e8d, "GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM", 0, 0, 3,
+		bptc_srgba_unorm, sizeof bptc_srgba_unorm},
+	{0x08e8e, "GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT", 0, 0, 3,
+		bptc_rgb_signed_float, sizeof bptc_rgb_signed_float},
+	{0x08e8f, "GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT", 0, 0, 3,
+		bptc_rgb_unsigned_float,sizeof bptc_rgb_unsigned_float},
+	{0x083f1, "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT", 0, 0, 4,
+		dxt1_rgba, sizeof dxt1_rgba},
+	{0x08c4c, "GL_COMPRESSED_SRGB_S3TC_DXT1_EXT", 0, 0, 3,
+		dxt1_srgb, sizeof dxt1_srgb},
+	{0x08c4d, "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT", 0, 0, 4,
+		dxt1_srgba, sizeof dxt1_srgba},
+	{0x08c4e, "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT", 0, 0, 4,
+		dxt3_srgba, sizeof dxt3_srgba},
+	{0x08c4f, "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT", 0, 0, 4,
+		dxt5_srgba, sizeof dxt5_srgba},
+	{0, 0, 0, 0, 0, 0, 0}
+};
+
+PIGLIT_GL_TEST_CONFIG_BEGIN config.supports_gl_compat_version = 32;
+
+	config.window_width = win_width;
+	config.window_height = win_height;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
+	config.khr_no_error_support = PIGLIT_NO_ERRORS;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static void
+cleanup()
+{
+	int i;
+	glDeleteProgram(sdrprog);
+	glDeleteBuffers(1, &vbo);
+	glDeleteVertexArrays(1, &vao);
+
+	for (i = 0; formats[i].fmt; i++) {
+		if (formats[i].tex) {
+			formats[i].tex = 0;
+			glDeleteTextures(1, &formats[i].tex);
+		}
+		if (formats[i].ctex) {
+			formats[i].ctex = 0;
+			glDeleteTextures(1, &formats[i].ctex);
+		}
+	}
+}
+
+static bool
+create_cubemaps()
+{
+	int i, j;
+	for (i = 0; formats[i].fmt; i++) {
+		int supported;
+		int face_sz;
+		int dumped_face_sz;
+		unsigned int face;
+		int err;
+
+		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+		glGetInternalformativ(GL_TEXTURE_CUBE_MAP, formats[i].fmt,
+				      GL_INTERNALFORMAT_SUPPORTED,
+				      sizeof supported, &supported);
+
+		if (!supported) {
+			printf("Skipping: %s, not supported.\n",
+			       formats[i].name);
+			continue;
+		}
+
+		dumped_face_sz = formats[i].data_size / 6;
+		face_sz = sizeof pixels / 6;
+
+		printf("Creating texture for format: %s\n", formats[i].name);
+		glGenTextures(1, &formats[i].tex);
+		glBindTexture(GL_TEXTURE_CUBE_MAP, formats[i].tex);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,
+				GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,
+				GL_CLAMP_TO_EDGE);
+
+		for (j = 0; j < 6; j++) {
+			face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + j;
+			glCompressedTexImage2D(face, 0, formats[i].fmt,
+					       CUBESZ, CUBESZ, 0,
+					       dumped_face_sz,
+					       formats[i].data +
+					       dumped_face_sz * j);
+			if ((err = glGetError()) != GL_NO_ERROR) {
+				formats[i].tex = 0;
+				glDeleteTextures(1, &formats[i].tex);
+				fprintf(stderr,
+					"OpenGL error: %d for format: %s\n",
+					err, formats[i].name);
+				return false;
+			}
+		}
+
+		printf("Creating compressed texture for format: %s\n",
+		       formats[i].name);
+		glGenTextures(1, &formats[i].ctex);
+		glBindTexture(GL_TEXTURE_CUBE_MAP, formats[i].ctex);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,
+				GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,
+				GL_CLAMP_TO_EDGE);
+
+		for (j = 0; j < 6; j++) {
+			int is_compressed = 0;
+
+			face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + j;
+
+			/* compressing ctex */
+			glTexImage2D(GL_TEXTURE_2D, 0, formats[i].fmt, CUBESZ,
+				     CUBESZ, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+				     pixels + face_sz * j);
+			glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
+						 GL_TEXTURE_COMPRESSED,
+						 &is_compressed);
+			if (!is_compressed || glGetError() != GL_NO_ERROR) {
+				fprintf(stderr,
+					"Failed to compress format: %s\n",
+					formats[i].name);
+				formats[i].ctex = 0;
+				glDeleteTextures(1, &formats[i].ctex);
+
+				formats[i].tex = 0;
+				glDeleteTextures(1, &formats[i].tex);
+				return false;
+			}
+		}
+	}
+	glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+	return true;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* quad vertices (vec2) */
+	static const float varr[] =
+		{ -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 };
+	unsigned int vsdr, fsdr;
+	int status;
+
+	piglit_require_extension("GL_ARB_texture_cube_map");
+
+	if (!create_cubemaps())
+		piglit_error = 1;
+
+	/* create vbo/vao */
+	glGenBuffers(1, &vbo);
+	glBindBuffer(GL_ARRAY_BUFFER, vbo);
+	glBufferData(GL_ARRAY_BUFFER, sizeof varr, varr, GL_STATIC_DRAW);
+
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+	glEnableVertexAttribArray(0);
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
+	glBindBuffer(GL_ARRAY_BUFFER, 0);
+	glBindVertexArray(0);
+
+	/* create shader */
+	vsdr = glCreateShader(GL_VERTEX_SHADER);
+	glShaderSource(vsdr, 1, &vsdr_src, 0);
+	glCompileShader(vsdr);
+	glGetShaderiv(vsdr, GL_COMPILE_STATUS, &status);
+	if (!status) {
+		fprintf(stderr, "Failed to compile vertex shader.\n");
+		piglit_error = 1;
+		return;
+	}
+	fsdr = glCreateShader(GL_FRAGMENT_SHADER);
+	glShaderSource(fsdr, 1, &fsdr_src, 0);
+	glCompileShader(fsdr);
+	glGetShaderiv(fsdr, GL_COMPILE_STATUS, &status);
+	if (!status) {
+		fprintf(stderr, "Failed to compile fragment shader.\n");
+		piglit_error = 1;
+		return;
+	}
+	sdrprog = glCreateProgram();
+	glAttachShader(sdrprog, vsdr);
+	glAttachShader(sdrprog, fsdr);
+	glBindAttribLocation(sdrprog, 0, "vpos");
+	glLinkProgram(sdrprog);
+	glGetProgramiv(sdrprog, GL_LINK_STATUS, &status);
+	if (!status) {
+		fprintf(stderr, "Failed to link program.\n");
+		piglit_error = 1;
+		return;
+	}
+	glUseProgram(sdrprog);
+	if ((uloc_rot = glGetUniformLocation(sdrprog, "rot")) == -1) {
+		fprintf(stderr, "failed to find uniform \"rot\"\n");
+		piglit_error = 1;
+		return;
+	}
+
+	atexit(cleanup);
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+	int i, j;
+	GLboolean pass = GL_TRUE;
+
+	/* rotation angles needed to make a pattern with
+	 * 3 X/Y/Z columns and 2 positive/negative rows */
+	static const float theta_deg[] = { -90, 180, 0, 90, 180, 180 };
+	static const float phi_deg[] = { 0, -90, 0, 0, 90, 0 };
+
+	if (piglit_error)
+		return PIGLIT_FAIL;
+
+	glBindVertexArray(vao);
+
+	for (i = 0; formats[i].fmt; i++) {
+		if (formats[i].tex) {
+			GLfloat probe[4];
+			GLfloat probe_cmp[4];
+
+			for (j = 0; j < 6; j++) {
+				float theta = theta_deg[j] / 180.0 * M_PI;
+				float phi = phi_deg[j] / 180.0 * M_PI;
+				int x = (j % 3) * win_width / 3;
+				int y = (j / 3) * win_height / 2;
+
+				glUniform2f(uloc_rot, phi, theta);	/* set rotation angles */
+
+				int vp_x = x + 2;
+				int vp_y = y + 2;
+				int vp_w = win_width / 3 - 4;
+				int vp_h = win_height / 2 - 4;
+
+				glViewport(vp_x, vp_y, vp_w, vp_h);
+
+				x += win_width / 6;
+				y += win_height / 4;
+
+				/* probing tex color values */
+				glBindTexture(GL_TEXTURE_CUBE_MAP,
+					      formats[i].tex);
+				glDrawArrays(GL_TRIANGLES, 0, 6);
+				glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT,
+					     &probe);
+
+				/* probing natively compressed ctex color values */
+				glBindTexture(GL_TEXTURE_CUBE_MAP,
+					      formats[i].ctex);
+				glDrawArrays(GL_TRIANGLES, 0, 6);
+				glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT,
+					     &probe_cmp);
+
+				pass = pass
+					&& piglit_compare_pixels(x, y,
+								 probe_cmp,
+								 probe,
+								 tolerance,
+								 formats[i].
+								 num_channels);
+				if (!pass) {
+					fprintf(stderr,
+						"Natively compressed and dumped cubefaces");
+					fprintf(stderr,
+						"colors do not match for format: %s\n",
+						formats[i].name);
+					return PIGLIT_FAIL;
+				}
+			}
+
+			glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+		}
+	}
+
+	glBindVertexArray(0);
+
+	if (glGetError() != GL_NO_ERROR)
+		return PIGLIT_FAIL;
+
+	piglit_swap_buffers();
+
+	return PIGLIT_PASS;
+}
diff --git a/tests/texturing/compressed-cubemap.c b/tests/texturing/compressed-cubemap.c
new file mode 100644
index 000000000..2f7d121d3
--- /dev/null
+++ b/tests/texturing/compressed-cubemap.c
@@ -0,0 +1,477 @@
+/*
+ * Copyright © 2018 Igalia SL
+ *
+ * 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:
+ *    Eleni Maria Stea <estea at igalia.com>
+ *
+ */
+
+/** @file compressed-cubemap.c
+ * Tests that the rendering of compressed cubemaps is working.
+ */
+
+#include "piglit-util-gl.h"
+#include "cubemap-compressed-data.h"
+
+#define CUBESZ 8
+
+static int win_width = 800;
+static int win_height = 600;
+
+static const char *vsdr_src =
+	"attribute vec4 vertex;\n"
+	"attribute vec3 texcoord;\n"
+	"uniform vec2 rot;\n"
+	"varying vec3 tc;\n"
+	"void main()\n"
+	"{\n"
+	"    gl_Position = vertex;\n"
+	"    tc.x = vertex.x * cos(rot.y) + sin(rot.y);\n"
+	"    tc.y = vertex.x * sin(rot.x) * sin(rot.y) + vertex.y * cos(rot.x) - sin(rot.x) * cos(rot.y);\n"
+	"    tc.z = vertex.x * cos(rot.x) * sin(rot.y) - vertex.y * sin(rot.x) - cos(rot.x) * cos(rot.y);\n"
+	"}\n";
+
+static const char *fsdr_src =
+	"uniform samplerCube tex;\n"
+	"varying vec3 tc;\n"
+	"void main()\n"
+	"{\n"
+	"    vec4 texel = textureCube(tex, tc);\n"
+	"    gl_FragColor = vec4(texel.xyz, 1.0);\n" "}\n";
+
+/* faces colors, used for comparison */
+static float colors[][4] = {
+	{0.0, 0.0, 1.0, 1.0}, {1.0, 0.0, 1.0, 1.0},
+	{1.0, 1.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 1.0},
+	{0.0, 1.0, 0.0, 1.0}, {0.0, 1.0, 1.0, 1.0}
+};
+
+static int piglit_error;
+static unsigned int vbo, vao;
+static unsigned int sdrprog;
+static int uloc_rot;
+static const float tolerance[4] = { 0.1, 0.1, 0.1, 0.1 };
+
+struct
+{
+	unsigned int fmt;
+	const char *name;
+	unsigned int tex;
+	unsigned int num_channels;
+	unsigned char *data;
+	unsigned int data_size;
+} formats[] = {
+	/* Supported compressed formats, that we can't compress natively */
+	{0x09270, "GL_COMPRESSED_R11_EAC", 0, 1, eac_r11,sizeof eac_r11},
+	{0x09271, "GL_COMPRESSED_SIGNED_R11_EAC", 0, 1, eac_sr11,
+		sizeof eac_sr11},
+	{0x09272, "GL_COMPRESSED_RG11_EAC", 0, 2, eac_rg11,sizeof eac_rg11},
+	{0x09273, "GL_COMPRESSED_SIGNED_RG11_EAC", 0, 2, eac_srg11,
+		sizeof eac_srg11},
+	{0x083f0, "GL_COMPRESSED_RGB_S3TC_DXT1_EXT", 0, 3, dxt1_rgb,
+		sizeof dxt1_rgb},
+	{0x083f2, "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT", 0, 4, dxt3_rgba,
+		sizeof dxt3_rgba},
+	{0x083f3, "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT", 0, 4, dxt5_rgba,
+		sizeof dxt5_rgba},
+	{0x09274, "GL_COMPRESSED_RGB8_ETC2", 0, 3, etc2_rgb,sizeof etc2_rgb},
+	{0x09275, "GL_COMPRESSED_SRGB8_ETC2", 0, 3, etc2_srgb,sizeof etc2_srgb},
+	{0x09276, "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", 0, 4,
+		etc2_rgba1, sizeof etc2_rgba1},
+	{0x09277, "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", 0, 4,
+		etc2_srgba1, sizeof etc2_srgba1},
+	{0x09278, "GL_COMPRESSED_RGBA8_ETC2_EAC", 0, 4, etc2_rgba,
+		sizeof etc2_rgba},
+	{0x09279, "GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", 0, 4,
+		etc2_srgba, sizeof etc2_srgba},
+	{0x093b0, "GL_COMPRESSED_RGBA_ASTC_4", 0, 4, astc4_rgba,
+		sizeof astc4_rgba},
+	{0x093b1, "GL_COMPRESSED_RGBA_ASTC_5", 0, 4, astc5_rgba,
+		sizeof astc5_rgba},
+	{0x093b2, "GL_COMPRESSED_RGBA_ASTC_5", 0, 4, astc5_rgba,
+		sizeof astc5_rgba},
+	{0x093b3, "GL_COMPRESSED_RGBA_ASTC_6", 0, 4, astc6_rgba,
+		sizeof astc6_rgba},
+	{0x093b4, "GL_COMPRESSED_RGBA_ASTC_6", 0, 4, astc6_rgba,
+		sizeof astc6_rgba},
+	{0x093b5, "GL_COMPRESSED_RGBA_ASTC_8", 0, 4, astc8_rgba,
+		sizeof astc8_rgba},
+	{0x093b6, "GL_COMPRESSED_RGBA_ASTC_8", 0, 4, astc8_rgba,
+		sizeof astc8_rgba},
+	{0x093b7, "GL_COMPRESSED_RGBA_ASTC_8", 0, 4, astc8_rgba,
+		sizeof astc8_rgba},
+	{0x093b8, "GL_COMPRESSED_RGBA_ASTC_10", 0, 4, astc10_rgba,
+		sizeof astc10_rgba},
+	{0x093b9, "GL_COMPRESSED_RGBA_ASTC_10", 0, 4, astc10_rgba,
+		sizeof astc10_rgba},
+	{0x093ba, "GL_COMPRESSED_RGBA_ASTC_10", 0, 4, astc10_rgba,
+		sizeof astc10_rgba},
+	{0x093bb, "GL_COMPRESSED_RGBA_ASTC_10", 0, 4, astc10_rgba,
+		sizeof astc10_rgba},
+	{0x093bc, "GL_COMPRESSED_RGBA_ASTC_12", 0, 4, astc12_rgba,
+		sizeof astc12_rgba},
+	{0x093bd, "GL_COMPRESSED_RGBA_ASTC_12", 0, 4, astc12_rgba,
+		sizeof astc12_rgba},
+	{0x093d0, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4", 0, 4, astc4_srgba,
+		sizeof astc4_srgba},
+	{0x093d1, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5", 0, 4, astc5_srgba,
+		sizeof astc5_srgba},
+	{0x093d2, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5", 0, 4, astc5_srgba,
+		sizeof astc5_srgba},
+	{0x093d3, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6", 0, 4, astc6_srgba,
+		sizeof astc6_srgba},
+	{0x093d4, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6", 0, 4, astc6_srgba,
+		sizeof astc6_srgba},
+	{0x093d5, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8", 0, 4, astc8_srgba,
+		sizeof astc8_srgba},
+	{0x093d6, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8", 0, 4, astc8_srgba,
+		sizeof astc8_srgba},
+	{0x093d7, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8", 0, 4, astc8_srgba,
+		sizeof astc8_srgba},
+	{0x093d8, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10", 0, 4, astc10_srgba,
+		sizeof astc10_srgba},
+	{0x093d9, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10", 0, 4, astc10_srgba,
+		sizeof astc10_srgba},
+	{0x093da, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10", 0, 4, astc10_srgba,
+		sizeof astc10_srgba},
+	{0x093db, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10", 0, 4, astc10_srgba,
+		sizeof astc10_srgba},
+	{0x093dc, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12", 0, 4, astc12_srgba,
+		sizeof astc12_srgba},
+	{0x093dd, "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12", 0, 4, astc12_srgba,
+		sizeof astc12_srgba},
+
+	/* natively supported compressed formats */
+	{0x08c4a, "GL_COMPRESSED_SLUMINANCE_EXT", 0, 1, 0, 0},
+	{0x08c4b, "GL_COMPRESSED_SLUMINANCE_ALPHA_EXT", 0, 2, 0, 0},
+
+	/* The following formats have the Cube Maps column empty
+	 * in the table provided by the RGTC extension, we assumed
+	 * that we don't need to support them:
+	 *
+	 * {0x08dbb, "GL_COMPRESSED_RED_RGTC1", 0, 1, 0, 0},
+	 * {0x08dbc, "GL_COMPRESSED_SIGNED_RED_RGTC1", 0, 1, 0, 0},
+	 * {0x08dbd, "GL_COMPRESSED_RG_RGTC2", 0, 2, 0, 0},
+	 * {0x08dbe, "GL_COMPRESSED_SIGNED_RG_RGTC2", 0, 2, 0, 0},
+	 *
+	 * These formats extensions don't seem to state if Cube Maps
+	 * should be supported. We are going to ignore them for the
+	 * moment:
+	 *
+	 * {0x086b0, "GL_COMPRESSED_RGB_FXT1_3DFX", 0, 3, 0, 0},
+	 * {0x086b1, "GL_COMPRESSED_RGBA_FXT1_3DFX", 0, 4, 0, 0},
+	 * {0x08c48, "GL_COMPRESSED_SRGB_EXT", 0, 3, 0, 0},
+	 * {0x08c49, "GL_COMPRESSED_SRGB_ALPHA_EXT", 0, 4, 0, 0},
+	 */
+
+	/* The following formats should support cubemaps. Nevertheless,
+	 * TexImage2D can't create valid cubemaps for them. As the purpose of
+	 * this test is to check the cubemap rendering and not the compression,
+	 * we dumped the cubemap faces on mesa and we load the data from arrays:
+	 */
+	{0x08e8c, "GL_COMPRESSED_RGBA_BPTC_UNORM", 0, 4,
+		bptc_rgba_unorm, sizeof bptc_rgba_unorm},
+	{0x08e8d, "GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM", 0, 3,
+		bptc_srgba_unorm, sizeof bptc_srgba_unorm},
+	{0x08e8e, "GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT", 0, 3,
+		bptc_rgb_signed_float, sizeof bptc_rgb_signed_float},
+	{0x08e8f, "GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT", 0, 3,
+		bptc_rgb_unsigned_float,sizeof bptc_rgb_unsigned_float},
+	{0x083f1, "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT", 0, 4, dxt1_rgba,
+		sizeof dxt1_rgba},
+	{0x08c4c, "GL_COMPRESSED_SRGB_S3TC_DXT1_EXT", 0, 3, dxt1_srgb,
+		sizeof dxt1_srgb},
+	{0x08c4d, "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT", 0, 4,
+		dxt1_srgba, sizeof dxt1_srgba},
+	{0x08c4e, "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT", 0, 4,
+		dxt3_srgba, sizeof dxt3_srgba},
+	{0x08c4f, "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT", 0, 4,
+		dxt5_srgba, sizeof dxt5_srgba},
+
+	/* Not supported formats for which we don't have dumped data.
+	 * FIXME: add some data when we add the support. In the meantime,
+	 * the test will skip them.
+	 */
+	{0x08b90, "GL_PALETTE4_RGB8_OES", 0, 3, 0, 0},
+	{0x08b91, "GL_PALETTE4_RGBA8_OES", 0, 4, 0, 0},
+	{0x08b92, "GL_PALETTE4_R5_G6_B5_OES", 0, 3, 0, 0},
+	{0x08b93, "GL_PALETTE4_RGBA4_OES", 0, 4, 0, 0},
+	{0x08b94, "GL_PALETTE4_RGB5_A1_OES", 0, 3, 0, 0},
+	{0x08b95, "GL_PALETTE8_RGB8_OES", 0, 3, 0, 0},
+	{0x08b96, "GL_PALETTE8_RGBA8_OES", 0, 4, 0, 0},
+	{0x08b97, "GL_PALETTE8_R5_G6_B5_OES", 0, 3, 0, 0},
+	{0x08b98, "GL_PALETTE8_RGBA4_OES", 0, 4, 0, 0},
+	{0x08b99, "GL_PALETTE8_RGB5_A1_OES", 0, 3, 0, 0},
+	{0, 0, 0, 0, 0, 0}
+};
+
+PIGLIT_GL_TEST_CONFIG_BEGIN config.supports_gl_compat_version = 32;
+
+	config.window_width = win_width;
+	config.window_height = win_height;
+	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
+	config.khr_no_error_support = PIGLIT_NO_ERRORS;
+
+PIGLIT_GL_TEST_CONFIG_END static void
+
+cleanup()
+{
+	int i;
+	glDeleteProgram(sdrprog);
+	glDeleteBuffers(1, &vbo);
+	glDeleteVertexArrays(1, &vao);
+
+	for (i = 0; formats[i].fmt; i++) {
+		if (formats[i].tex) {
+			glDeleteTextures(1, &formats[i].tex);
+		}
+	}
+}
+
+static bool
+create_cubemaps()
+{
+	int i, j;
+
+	for (i = 0; formats[i].fmt; i++) {
+		int supported;
+		int face_sz;
+
+		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+		glGetInternalformativ(GL_TEXTURE_CUBE_MAP, formats[i].fmt,
+				      GL_INTERNALFORMAT_SUPPORTED,
+				      sizeof supported, &supported);
+
+		if (!supported) {
+			printf("Skipping: %s, not supported.\n",
+			       formats[i].name);
+			continue;
+		}
+
+		if (formats[i].data)
+			face_sz = formats[i].data_size / 6;
+		else
+			face_sz = (sizeof pixels) / 6;
+
+		printf("Creating texture for format: %s\n", formats[i].name);
+		glGenTextures(1, &formats[i].tex);
+		glBindTexture(GL_TEXTURE_CUBE_MAP, formats[i].tex);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S,
+				GL_CLAMP_TO_EDGE);
+		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T,
+				GL_CLAMP_TO_EDGE);
+
+		for (j = 0; j < 6; j++) {
+			unsigned int face =
+				GL_TEXTURE_CUBE_MAP_POSITIVE_X + j;
+			int err;
+			int is_compressed = 0;
+
+			if (formats[i].data) {
+				glCompressedTexImage2D(face, 0,
+						       formats[i].fmt, CUBESZ,
+						       CUBESZ, 0, face_sz,
+						       formats[i].data +
+						       face_sz * j);
+				if ((err = glGetError()) != GL_NO_ERROR) {
+					formats[i].tex = 0;
+					glDeleteTextures(1, &formats[i].tex);
+					fprintf(stderr, "OpenGL error: %d\n",
+						err);
+					return false;
+				}
+			} else {
+				glTexImage2D(GL_TEXTURE_2D, 0, formats[i].fmt,
+					     CUBESZ, CUBESZ, 0, GL_RGBA,
+					     GL_UNSIGNED_BYTE,
+					     pixels + face_sz * j);
+				glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
+							 GL_TEXTURE_COMPRESSED,
+							 &is_compressed);
+				if (!is_compressed
+				    || glGetError() != GL_NO_ERROR) {
+					formats[i].tex = 0;
+					glDeleteTextures(1, &formats[i].tex);
+					break;
+				}
+			}
+		}
+		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+	}
+
+	return true;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	/* quad vertices (vec2) */
+	static const float varr[] =
+		{ -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1 };
+	unsigned int vsdr, fsdr;
+	int status;
+
+	piglit_require_extension("GL_ARB_texture_cube_map");
+
+	if (!create_cubemaps())
+		piglit_error = 1;
+
+	/* create vbo/vao */
+	glGenBuffers(1, &vbo);
+	glBindBuffer(GL_ARRAY_BUFFER, vbo);
+	glBufferData(GL_ARRAY_BUFFER, sizeof varr, varr, GL_STATIC_DRAW);
+
+	glGenVertexArrays(1, &vao);
+	glBindVertexArray(vao);
+	glEnableVertexAttribArray(0);
+	glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
+	glBindBuffer(GL_ARRAY_BUFFER, 0);
+	glBindVertexArray(0);
+
+	/* create shader */
+	vsdr = glCreateShader(GL_VERTEX_SHADER);
+	glShaderSource(vsdr, 1, &vsdr_src, 0);
+	glCompileShader(vsdr);
+	glGetShaderiv(vsdr, GL_COMPILE_STATUS, &status);
+	if (!status) {
+		fprintf(stderr, "Failed to compile vertex shader.\n");
+		piglit_error = 1;
+		return;
+	}
+	fsdr = glCreateShader(GL_FRAGMENT_SHADER);
+	glShaderSource(fsdr, 1, &fsdr_src, 0);
+	glCompileShader(fsdr);
+	glGetShaderiv(fsdr, GL_COMPILE_STATUS, &status);
+	if (!status) {
+		fprintf(stderr, "Failed to compile fragment shader.\n");
+		piglit_error = 1;
+		return;
+	}
+	sdrprog = glCreateProgram();
+	glAttachShader(sdrprog, vsdr);
+	glAttachShader(sdrprog, fsdr);
+	glBindAttribLocation(sdrprog, 0, "vpos");
+	glLinkProgram(sdrprog);
+	glGetProgramiv(sdrprog, GL_LINK_STATUS, &status);
+	if (!status) {
+		fprintf(stderr, "Failed to link program.\n");
+		piglit_error = 1;
+		return;
+	}
+	glUseProgram(sdrprog);
+	if ((uloc_rot = glGetUniformLocation(sdrprog, "rot")) == -1) {
+		fprintf(stderr, "failed to find uniform \"rot\"\n");
+		piglit_error = 1;
+		return;
+	}
+
+	atexit(cleanup);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	int i, j;
+	GLboolean pass = GL_TRUE;
+
+	/* rotation angles needed to make a pattern with
+	 * 3 X/Y/Z columns and 2 positive/negative rows */
+	static const float theta_deg[] = { -90, 180, 0, 90, 180, 180 };
+	static const float phi_deg[] = { 0, -90, 0, 0, 90, 0 };
+
+	if (piglit_error)
+		return PIGLIT_FAIL;
+
+	glBindVertexArray(vao);
+
+	for (i = 0; formats[i].fmt; i++) {
+		if (formats[i].tex) {
+			float probe[4];
+
+			glBindTexture(GL_TEXTURE_CUBE_MAP, formats[i].tex);
+
+			for (j = 0; j < 6; j++) {
+				float *color = colors[j];
+
+				float theta = theta_deg[j] / 180.0 * M_PI;
+				float phi = phi_deg[j] / 180.0 * M_PI;
+				int x = (j % 3) * win_width / 3;
+				int y = (j / 3) * win_height / 2;
+
+				glUniform2f(uloc_rot, phi, theta);	/* set rotation angles */
+
+				int vp_x = x + 2;
+				int vp_y = y + 2;
+				int vp_w = win_width / 3 - 4;
+				int vp_h = win_height / 2 - 4;
+
+				glViewport(vp_x, vp_y, vp_w, vp_h);
+				glDrawArrays(GL_TRIANGLES, 0, 6);
+
+				x += win_width / 6;
+				y += win_height / 4;
+
+				glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT,
+					     &probe);
+				pass = pass
+					&& piglit_compare_pixels(x, y, color,
+								 probe,
+								 tolerance,
+								 formats[i].
+								 num_channels);
+				if (!pass) {
+					if (formats[i].data) {
+						fprintf(stderr,
+							"Failed to render a %s cubemap.\n",
+							formats[i].name);
+						return PIGLIT_FAIL;
+					} else {
+						/* We don't return PIGLIT_FAIL for formats we lack
+						 * dumped data, because the failure
+						 * might be due to bugs in the compression.
+						 * The purpose of this test is to check the
+						 * rendering */
+						fprintf(stderr,
+							"Failed to compress or render a:\n%s cubemap.\n",
+							formats[i].name);
+						break;
+					}
+				}
+			}
+
+			glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
+		}
+	}
+
+	glBindVertexArray(0);
+
+	if (glGetError() != GL_NO_ERROR)
+		return PIGLIT_FAIL;
+
+	piglit_swap_buffers();
+
+	return PIGLIT_PASS;
+}
-- 
2.20.1



More information about the Piglit mailing list