[Piglit] [PATCH 1/5] Move some common uilities to piglit-shared-util.c

Shuang He shuang.he at intel.com
Mon Nov 22 19:22:51 PST 2010


---
 tests/util/CMakeLists.txt       |    2 +
 tests/util/piglit-shared-util.c |  468 +++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util.c        |  432 ------------------------------------
 3 files changed, 470 insertions(+), 432 deletions(-)
 create mode 100644 tests/util/piglit-shared-util.c

diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt
index f859a3f..492c4e7 100644
--- a/tests/util/CMakeLists.txt
+++ b/tests/util/CMakeLists.txt
@@ -10,6 +10,7 @@ include_directories(
 set (UTIL_SOURCES
 	fdo-bitmap.c
 	piglit-util.c
+	piglit-shared-util.c
 	shader-load.c
 	piglit-framework.c
 )
@@ -18,6 +19,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 	add_definitions ( -DUSE_GLX )
 	add_library (piglitglxutil
 		    piglit-util.c
+		    piglit-shared-util.c
 		    piglit-glx-framework.c
 		    piglit-glx-util.c
 	)
diff --git a/tests/util/piglit-shared-util.c b/tests/util/piglit-shared-util.c
new file mode 100644
index 0000000..15b63f8
--- /dev/null
+++ b/tests/util/piglit-shared-util.c
@@ -0,0 +1,468 @@
+/*
+ * Copyright (c) The Piglit project 2007
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
+ * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS 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.
+ */
+
+#if defined(_MSC_VER)
+#include <windows.h>
+#endif
+
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "piglit-util.h"
+
+/* These texture coordinates should have 1 or -1 in the major axis selecting
+ * the face, and a nearly-1-or-negative-1 value in the other two coordinates
+ * which will be used to produce the s,t values used to sample that face's
+ * image.
+ */
+GLfloat cube_face_texcoords[6][4][3] = {
+	{ /* GL_TEXTURE_CUBE_MAP_POSITIVE_X */
+		{1.0,  0.99,  0.99},
+		{1.0,  0.99, -0.99},
+		{1.0, -0.99, -0.99},
+		{1.0, -0.99,  0.99},
+	},
+	{ /* GL_TEXTURE_CUBE_MAP_POSITIVE_Y */
+		{-0.99, 1.0, -0.99},
+		{ 0.99, 1.0, -0.99},
+		{ 0.99, 1.0,  0.99},
+		{-0.99, 1.0,  0.99},
+	},
+	{ /* GL_TEXTURE_CUBE_MAP_POSITIVE_Z */
+		{-0.99,  0.99, 1.0},
+		{-0.99, -0.99, 1.0},
+		{ 0.99, -0.99, 1.0},
+		{ 0.99,  0.99, 1.0},
+	},
+	{ /* GL_TEXTURE_CUBE_MAP_NEGATIVE_X */
+		{-1.0,  0.99, -0.99},
+		{-1.0,  0.99,  0.99},
+		{-1.0, -0.99,  0.99},
+		{-1.0, -0.99, -0.99},
+	},
+	{ /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Y */
+		{-0.99, -1.0,  0.99},
+		{-0.99, -1.0, -0.99},
+		{ 0.99, -1.0, -0.99},
+		{ 0.99, -1.0,  0.99},
+	},
+	{ /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Z */
+		{ 0.99,  0.99, -1.0},
+		{-0.99,  0.99, -1.0},
+		{-0.99, -0.99, -1.0},
+		{ 0.99, -0.99, -1.0},
+	},
+};
+
+const char *cube_face_names[6] = {
+	"POSITIVE_X",
+	"POSITIVE_Y",
+	"POSITIVE_Z",
+	"NEGATIVE_X",
+	"NEGATIVE_Y",
+	"NEGATIVE_Z",
+};
+
+const GLenum cube_face_targets[6] = {
+	GL_TEXTURE_CUBE_MAP_POSITIVE_X,
+	GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+	GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+	GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+	GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+	GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+};
+
+/** Returns the line in the program string given the character position. */
+int FindLine(const char *program, int position)
+{
+	int i, line = 1;
+	for (i = 0; i < position; i++) {
+		if (program[i] == '0')
+			return -1; /* unknown line */
+		if (program[i] == '\n')
+			line++;
+	}
+	return line;
+}
+
+void
+piglit_report_result(enum piglit_result result)
+{
+	fflush(stderr);
+
+	if (result == PIGLIT_SUCCESS) {
+		printf("PIGLIT: {'result': 'pass' }\n");
+		fflush(stdout);
+		exit(0);
+	} else if (result == PIGLIT_SKIP) {
+		printf("PIGLIT: {'result': 'skip' }\n");
+		fflush(stdout);
+		exit(0);
+	} else if (result == PIGLIT_WARN) {
+		printf("PIGLIT: {'result': 'warn' }\n");
+		fflush(stdout);
+		exit(0);
+	} else {
+		printf("PIGLIT: {'result': 'fail' }\n");
+		fflush(stdout);
+		exit(1);
+	}
+}
+
+/**
+ * Convenience function to compile a GLSL shader from a file.
+ */
+GLuint
+piglit_compile_shader(GLenum target, char *filename)
+{
+	GLuint prog;
+	struct stat st;
+	int err;
+	GLchar *prog_string;
+	FILE *f;
+	const char *source_dir;
+	char filename_with_path[FILENAME_MAX];
+
+	source_dir = getenv("PIGLIT_SOURCE_DIR");
+	if (source_dir == NULL) {
+		source_dir = SOURCE_DIR;
+	}
+
+	snprintf(filename_with_path, FILENAME_MAX - 1,
+		 "%s/tests/%s", source_dir, filename);
+	filename_with_path[FILENAME_MAX - 1] = 0;
+
+	err = stat(filename_with_path, &st);
+	if (err == -1) {
+		fprintf(stderr, "Couldn't stat program %s: %s\n", filename, strerror(errno));
+		fprintf(stderr, "You can override the source dir by setting the PIGLIT_SOURCE_DIR environment variable.\n");
+		exit(1);
+	}
+
+	prog_string = malloc(st.st_size + 1);
+	if (prog_string == NULL) {
+		fprintf(stderr, "malloc\n");
+		exit(1);
+	}
+
+	f = fopen(filename_with_path, "r");
+	if (f == NULL) {
+		fprintf(stderr, "Couldn't open program: %s\n", strerror(errno));
+		exit(1);
+	}
+	fread(prog_string, 1, st.st_size, f);
+	prog_string[st.st_size] = '\0';
+	fclose(f);
+
+	prog = piglit_compile_shader_text(target, prog_string);
+
+	free(prog_string);
+
+	return prog;
+}
+
+/**
+ * Convenience function to compile a GLSL shader.
+ */
+GLuint
+piglit_compile_shader_text(GLenum target, const char *text)
+{
+	GLuint prog;
+	GLint ok;
+
+	prog = glCreateShader(target);
+	glShaderSource(prog, 1, (const GLchar **) &text, NULL);
+	glCompileShader(prog);
+
+	glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
+
+	{
+		GLchar *info;
+		GLint size;
+
+		glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
+		info = malloc(size);
+
+		glGetShaderInfoLog(prog, size, NULL, info);
+		if (!ok) {
+			fprintf(stderr, "Failed to compile %s: %s\n",
+				target == GL_FRAGMENT_SHADER ? "FS" : "VS",
+				info);
+		}
+		else if (0) {
+			/* Enable this to get extra compilation info.
+			 * Even if there's no compilation errors, the info
+			 * log may have some remarks.
+			 */
+			fprintf(stderr, "Shader compiler warning: %s\n", info);
+		}
+		free(info);
+	}
+
+	return prog;
+}
+
+static GLboolean
+link_check_status(GLint prog, FILE *output)
+{
+	GLchar *info = NULL;
+	GLint size;
+	GLint ok;
+
+	glGetProgramiv(prog, GL_LINK_STATUS, &ok);
+
+	/* Some drivers return a size of 1 for an empty log.  This is the size
+	 * of a log that contains only a terminating NUL character.
+	 */
+	glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
+	if (size > 1) {
+		info = malloc(size);
+		glGetProgramInfoLog(prog, size, NULL, info);
+	}
+
+	if (!ok) {
+		fprintf(output, "Failed to link: %s\n",
+			(info != NULL) ? info : "<empty log>");
+	}
+	else if (0 && info != NULL) {
+		/* Enable this to get extra linking info.
+		 * Even if there's no link errors, the info log may
+		 * have some remarks.
+		 */
+		printf("Linker warning: %s\n", info);
+	}
+
+	free(info);
+
+	return ok;
+}
+
+GLboolean
+piglit_link_check_status(GLint prog)
+{
+	return link_check_status(prog, stderr);
+}
+
+/**
+ * Check link status
+ *
+ * Similar to piglit_link_check_status except it logs error messages
+ * to standard output instead of standard error.  This is useful for
+ * tests that want to produce negative link results.
+ *
+ * \sa piglit_link_check_status
+ */
+GLboolean
+piglit_link_check_status_quiet(GLint prog)
+{
+	return link_check_status(prog, stdout);
+}
+
+
+GLint piglit_link_simple_program(GLint vs, GLint fs)
+{
+	GLint prog;
+
+	prog = glCreateProgram();
+	if (fs)
+		glAttachShader(prog, fs);
+	if (vs)
+		glAttachShader(prog, vs);
+	glLinkProgram(prog);
+
+	piglit_link_check_status(prog);
+
+	return prog;
+}
+
+/**
+ * Generates a texture with the given internalFormat, w, h with a
+ * teximage of r, g, b w quadrants.
+ *
+ * Note that for compressed teximages, where the blocking would be
+ * problematic, we assign the whole layers at w == 4 to red, w == 2 to
+ * green, and w == 1 to blue.
+ */
+GLuint
+piglit_rgbw_texture(GLenum format, int w, int h, GLboolean mip,
+		    GLboolean alpha)
+{
+	GLfloat *data;
+	int size, x, y, level;
+	GLuint tex;
+	float red[4]   = {1.0, 0.0, 0.0, 0.0};
+	float green[4] = {0.0, 1.0, 0.0, 0.25};
+	float blue[4]  = {0.0, 0.0, 1.0, 0.5};
+	float white[4] = {1.0, 1.0, 1.0, 1.0};
+
+	if (!alpha) {
+		red[3] = 1.0;
+		green[3] = 1.0;
+		blue[3] = 1.0;
+		white[3] = 1.0;
+	}
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	if (mip) {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+				GL_LINEAR_MIPMAP_NEAREST);
+	} else {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+				GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+				GL_NEAREST);
+	}
+	data = malloc(w * h * 4 * sizeof(GLfloat));
+
+	/* XXX: Do we want non-square textures?  Surely some day. */
+	assert(w == h);
+
+	for (level = 0, size = w; size > 0; level++, size >>= 1) {
+		for (y = 0; y < size; y++) {
+			for (x = 0; x < size; x++) {
+				const float *color;
+
+				if (x < size / 2 && y < size / 2)
+					color = red;
+				else if (y < size / 2)
+					color = green;
+				else if (x < size / 2)
+					color = blue;
+				else
+					color = white;
+
+				switch (format) {
+				case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+				case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+				case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+				case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+				case GL_COMPRESSED_RGB_FXT1_3DFX:
+				case GL_COMPRESSED_RGBA_FXT1_3DFX:
+					if (size == 4)
+						color = red;
+					else if (size == 2)
+						color = green;
+					else if (size == 1)
+						color = blue;
+					break;
+				default:
+					break;
+				}
+
+				memcpy(data + (y * size + x) * 4, color,
+				       4 * sizeof(float));
+			}
+		}
+		glTexImage2D(GL_TEXTURE_2D, level,
+			     format,
+			     size, size, 0,
+			     GL_RGBA, GL_FLOAT, data);
+
+		if (!mip)
+			break;
+	}
+	free(data);
+	return tex;
+}
+
+GLuint
+piglit_depth_texture(GLenum internalformat, int w, int h, GLboolean mip)
+{
+	void *data;
+	float *f = NULL;
+	unsigned int  *i = NULL;
+	int size, x, y, level;
+	GLuint tex;
+	GLenum type, format;
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	if (mip) {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+				GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+				GL_LINEAR_MIPMAP_NEAREST);
+	} else {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+				GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+				GL_NEAREST);
+	}
+	data = malloc(w * h * 4 * sizeof(GLfloat));
+
+	/* XXX: Do we want non-square textures?  Surely some day. */
+	assert(w == h);
+
+	if (internalformat == GL_DEPTH_STENCIL_EXT ||
+	    internalformat == GL_DEPTH24_STENCIL8_EXT) {
+		format = GL_DEPTH_STENCIL_EXT;
+		type = GL_UNSIGNED_INT_24_8_EXT;
+		i = data;
+	} else {
+		format = GL_DEPTH_COMPONENT;
+		type = GL_FLOAT;
+		f = data;
+	}
+
+	for (level = 0, size = w; size > 0; level++, size >>= 1) {
+		for (y = 0; y < size; y++) {
+			for (x = 0; x < size; x++) {
+				float val = (float)(x) / (w - 1);
+				if (f)
+					f[y * size + x] = val;
+				else
+					i[y * size + x] = 0xffffff00 * val;
+			}
+		}
+		glTexImage2D(GL_TEXTURE_2D, level,
+			     internalformat,
+			     size, size, 0,
+			     format, type, data);
+
+		if (!mip)
+			break;
+	}
+	free(data);
+	return tex;
+}
+
+#ifndef HAVE_STRCHRNUL
+char *strchrnul(const char *s, int c)
+{
+	char *t = strchr(s, c);
+
+	return (t == NULL) ? ((char *) s + strlen(s)) : t;
+}
+#endif
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 31ca6ef..f485c35 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -35,107 +35,9 @@
 
 #include "piglit-util.h"
 
-/* These texture coordinates should have 1 or -1 in the major axis selecting
- * the face, and a nearly-1-or-negative-1 value in the other two coordinates
- * which will be used to produce the s,t values used to sample that face's
- * image.
- */
-GLfloat cube_face_texcoords[6][4][3] = {
-	{ /* GL_TEXTURE_CUBE_MAP_POSITIVE_X */
-		{1.0,  0.99,  0.99},
-		{1.0,  0.99, -0.99},
-		{1.0, -0.99, -0.99},
-		{1.0, -0.99,  0.99},
-	},
-	{ /* GL_TEXTURE_CUBE_MAP_POSITIVE_Y */
-		{-0.99, 1.0, -0.99},
-		{ 0.99, 1.0, -0.99},
-		{ 0.99, 1.0,  0.99},
-		{-0.99, 1.0,  0.99},
-	},
-	{ /* GL_TEXTURE_CUBE_MAP_POSITIVE_Z */
-		{-0.99,  0.99, 1.0},
-		{-0.99, -0.99, 1.0},
-		{ 0.99, -0.99, 1.0},
-		{ 0.99,  0.99, 1.0},
-	},
-	{ /* GL_TEXTURE_CUBE_MAP_NEGATIVE_X */
-		{-1.0,  0.99, -0.99},
-		{-1.0,  0.99,  0.99},
-		{-1.0, -0.99,  0.99},
-		{-1.0, -0.99, -0.99},
-	},
-	{ /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Y */
-		{-0.99, -1.0,  0.99},
-		{-0.99, -1.0, -0.99},
-		{ 0.99, -1.0, -0.99},
-		{ 0.99, -1.0,  0.99},
-	},
-	{ /* GL_TEXTURE_CUBE_MAP_NEGATIVE_Z */
-		{ 0.99,  0.99, -1.0},
-		{-0.99,  0.99, -1.0},
-		{-0.99, -0.99, -1.0},
-		{ 0.99, -0.99, -1.0},
-	},
-};
-
-const char *cube_face_names[6] = {
-	"POSITIVE_X",
-	"POSITIVE_Y",
-	"POSITIVE_Z",
-	"NEGATIVE_X",
-	"NEGATIVE_Y",
-	"NEGATIVE_Z",
-};
-
-const GLenum cube_face_targets[6] = {
-	GL_TEXTURE_CUBE_MAP_POSITIVE_X,
-	GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
-	GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
-	GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
-	GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
-	GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
-};
 
 GLint piglit_ARBfp_pass_through = 0;
 
-/** Returns the line in the program string given the character position. */
-int FindLine(const char *program, int position)
-{
-	int i, line = 1;
-	for (i = 0; i < position; i++) {
-		if (program[i] == '0')
-			return -1; /* unknown line */
-		if (program[i] == '\n')
-			line++;
-	}
-	return line;
-}
-
-void
-piglit_report_result(enum piglit_result result)
-{
-	fflush(stderr);
-
-	if (result == PIGLIT_SUCCESS) {
-		printf("PIGLIT: {'result': 'pass' }\n");
-		fflush(stdout);
-		exit(0);
-	} else if (result == PIGLIT_SKIP) {
-		printf("PIGLIT: {'result': 'skip' }\n");
-		fflush(stdout);
-		exit(0);
-	} else if (result == PIGLIT_WARN) {
-		printf("PIGLIT: {'result': 'warn' }\n");
-		fflush(stdout);
-		exit(0);
-	} else {
-		printf("PIGLIT: {'result': 'fail' }\n");
-		fflush(stdout);
-		exit(1);
-	}
-}
-
 void piglit_require_extension(const char *name)
 {
 	if (!glutExtensionSupported(name)) {
@@ -524,172 +426,6 @@ GLuint piglit_compile_program(GLenum target, const char* text)
 	return program;
 }
 
-/**
- * Convenience function to compile a GLSL shader from a file.
- */
-GLuint
-piglit_compile_shader(GLenum target, char *filename)
-{
-	GLuint prog;
-	struct stat st;
-	int err;
-	GLchar *prog_string;
-	FILE *f;
-	const char *source_dir;
-	char filename_with_path[FILENAME_MAX];
-
-	source_dir = getenv("PIGLIT_SOURCE_DIR");
-	if (source_dir == NULL) {
-		source_dir = SOURCE_DIR;
-	}
-
-	snprintf(filename_with_path, FILENAME_MAX - 1,
-		 "%s/tests/%s", source_dir, filename);
-	filename_with_path[FILENAME_MAX - 1] = 0;
-
-	err = stat(filename_with_path, &st);
-	if (err == -1) {
-		fprintf(stderr, "Couldn't stat program %s: %s\n", filename, strerror(errno));
-		fprintf(stderr, "You can override the source dir by setting the PIGLIT_SOURCE_DIR environment variable.\n");
-		exit(1);
-	}
-
-	prog_string = malloc(st.st_size + 1);
-	if (prog_string == NULL) {
-		fprintf(stderr, "malloc\n");
-		exit(1);
-	}
-
-	f = fopen(filename_with_path, "r");
-	if (f == NULL) {
-		fprintf(stderr, "Couldn't open program: %s\n", strerror(errno));
-		exit(1);
-	}
-	fread(prog_string, 1, st.st_size, f);
-	prog_string[st.st_size] = '\0';
-	fclose(f);
-
-	prog = piglit_compile_shader_text(target, prog_string);
-
-	free(prog_string);
-
-	return prog;
-}
-
-/**
- * Convenience function to compile a GLSL shader.
- */
-GLuint
-piglit_compile_shader_text(GLenum target, const char *text)
-{
-	GLuint prog;
-	GLint ok;
-
-	prog = glCreateShader(target);
-	glShaderSource(prog, 1, (const GLchar **) &text, NULL);
-	glCompileShader(prog);
-
-	glGetShaderiv(prog, GL_COMPILE_STATUS, &ok);
-
-	{
-		GLchar *info;
-		GLint size;
-
-		glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size);
-		info = malloc(size);
-
-		glGetShaderInfoLog(prog, size, NULL, info);
-		if (!ok) {
-			fprintf(stderr, "Failed to compile %s: %s\n",
-				target == GL_FRAGMENT_SHADER ? "FS" : "VS",
-				info);
-		}
-		else if (0) {
-			/* Enable this to get extra compilation info.
-			 * Even if there's no compilation errors, the info
-			 * log may have some remarks.
-			 */
-			fprintf(stderr, "Shader compiler warning: %s\n", info);
-		}
-		free(info);
-	}
-
-	return prog;
-}
-
-static GLboolean
-link_check_status(GLint prog, FILE *output)
-{
-	GLchar *info = NULL;
-	GLint size;
-	GLint ok;
-
-	glGetProgramiv(prog, GL_LINK_STATUS, &ok);
-
-	/* Some drivers return a size of 1 for an empty log.  This is the size
-	 * of a log that contains only a terminating NUL character.
-	 */
-	glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
-	if (size > 1) {
-		info = malloc(size);
-		glGetProgramInfoLog(prog, size, NULL, info);
-	}
-
-	if (!ok) {
-		fprintf(output, "Failed to link: %s\n",
-			(info != NULL) ? info : "<empty log>");
-	}
-	else if (0 && info != NULL) {
-		/* Enable this to get extra linking info.
-		 * Even if there's no link errors, the info log may
-		 * have some remarks.
-		 */
-		printf("Linker warning: %s\n", info);
-	}
-
-	free(info);
-
-	return ok;
-}
-
-GLboolean
-piglit_link_check_status(GLint prog)
-{
-	return link_check_status(prog, stderr);
-}
-
-/**
- * Check link status
- *
- * Similar to piglit_link_check_status except it logs error messages
- * to standard output instead of standard error.  This is useful for
- * tests that want to produce negative link results.
- *
- * \sa piglit_link_check_status
- */
-GLboolean
-piglit_link_check_status_quiet(GLint prog)
-{
-	return link_check_status(prog, stdout);
-}
-
-
-GLint piglit_link_simple_program(GLint vs, GLint fs)
-{
-	GLint prog;
-
-	prog = glCreateProgram();
-	if (fs)
-		glAttachShader(prog, fs);
-	if (vs)
-		glAttachShader(prog, vs);
-	glLinkProgram(prog);
-
-	piglit_link_check_status(prog);
-
-	return prog;
-}
-
 void
 piglit_escape_exit_key(unsigned char key, int x, int y)
 {
@@ -838,7 +574,6 @@ piglit_ortho_projection(int w, int h, GLboolean push)
         glLoadIdentity();
 }
 
-
 /**
  * Generate a checkerboard texture
  *
@@ -921,170 +656,3 @@ piglit_checkerboard_texture(GLuint tex, unsigned level,
 
 	return tex;
 }
-
-/**
- * Generates a texture with the given internalFormat, w, h with a
- * teximage of r, g, b w quadrants.
- *
- * Note that for compressed teximages, where the blocking would be
- * problematic, we assign the whole layers at w == 4 to red, w == 2 to
- * green, and w == 1 to blue.
- */
-GLuint
-piglit_rgbw_texture(GLenum format, int w, int h, GLboolean mip,
-		    GLboolean alpha)
-{
-	GLfloat *data;
-	int size, x, y, level;
-	GLuint tex;
-	float red[4]   = {1.0, 0.0, 0.0, 0.0};
-	float green[4] = {0.0, 1.0, 0.0, 0.25};
-	float blue[4]  = {0.0, 0.0, 1.0, 0.5};
-	float white[4] = {1.0, 1.0, 1.0, 1.0};
-
-	if (!alpha) {
-		red[3] = 1.0;
-		green[3] = 1.0;
-		blue[3] = 1.0;
-		white[3] = 1.0;
-	}
-
-	glGenTextures(1, &tex);
-	glBindTexture(GL_TEXTURE_2D, tex);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	if (mip) {
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
-				GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
-				GL_LINEAR_MIPMAP_NEAREST);
-	} else {
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
-				GL_NEAREST);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
-				GL_NEAREST);
-	}
-	data = malloc(w * h * 4 * sizeof(GLfloat));
-
-	/* XXX: Do we want non-square textures?  Surely some day. */
-	assert(w == h);
-
-	for (level = 0, size = w; size > 0; level++, size >>= 1) {
-		for (y = 0; y < size; y++) {
-			for (x = 0; x < size; x++) {
-				const float *color;
-
-				if (x < size / 2 && y < size / 2)
-					color = red;
-				else if (y < size / 2)
-					color = green;
-				else if (x < size / 2)
-					color = blue;
-				else
-					color = white;
-
-				switch (format) {
-				case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
-				case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
-				case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
-				case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
-				case GL_COMPRESSED_RGB_FXT1_3DFX:
-				case GL_COMPRESSED_RGBA_FXT1_3DFX:
-					if (size == 4)
-						color = red;
-					else if (size == 2)
-						color = green;
-					else if (size == 1)
-						color = blue;
-					break;
-				default:
-					break;
-				}
-
-				memcpy(data + (y * size + x) * 4, color,
-				       4 * sizeof(float));
-			}
-		}
-		glTexImage2D(GL_TEXTURE_2D, level,
-			     format,
-			     size, size, 0,
-			     GL_RGBA, GL_FLOAT, data);
-
-		if (!mip)
-			break;
-	}
-	free(data);
-	return tex;
-}
-
-GLuint
-piglit_depth_texture(GLenum internalformat, int w, int h, GLboolean mip)
-{
-	void *data;
-	float *f = NULL;
-	unsigned int  *i = NULL;
-	int size, x, y, level;
-	GLuint tex;
-	GLenum type, format;
-
-	glGenTextures(1, &tex);
-	glBindTexture(GL_TEXTURE_2D, tex);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	if (mip) {
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
-				GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
-				GL_LINEAR_MIPMAP_NEAREST);
-	} else {
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
-				GL_NEAREST);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
-				GL_NEAREST);
-	}
-	data = malloc(w * h * 4 * sizeof(GLfloat));
-
-	/* XXX: Do we want non-square textures?  Surely some day. */
-	assert(w == h);
-
-	if (internalformat == GL_DEPTH_STENCIL_EXT ||
-	    internalformat == GL_DEPTH24_STENCIL8_EXT) {
-		format = GL_DEPTH_STENCIL_EXT;
-		type = GL_UNSIGNED_INT_24_8_EXT;
-		i = data;
-	} else {
-		format = GL_DEPTH_COMPONENT;
-		type = GL_FLOAT;
-		f = data;
-	}
-
-	for (level = 0, size = w; size > 0; level++, size >>= 1) {
-		for (y = 0; y < size; y++) {
-			for (x = 0; x < size; x++) {
-				float val = (float)(x) / (w - 1);
-				if (f)
-					f[y * size + x] = val;
-				else
-					i[y * size + x] = 0xffffff00 * val;
-			}
-		}
-		glTexImage2D(GL_TEXTURE_2D, level,
-			     internalformat,
-			     size, size, 0,
-			     format, type, data);
-
-		if (!mip)
-			break;
-	}
-	free(data);
-	return tex;
-}
-
-#ifndef HAVE_STRCHRNUL
-char *strchrnul(const char *s, int c)
-{
-	char *t = strchr(s, c);
-
-	return (t == NULL) ? ((char *) s + strlen(s)) : t;
-}
-#endif
-- 
1.7.0.1



More information about the Piglit mailing list