[Piglit] [PATCH 15/16] Unify piglit_rgbw_texture between GL and GLES; drop piglit-util-gles.c

Josh Triplett josh at joshtriplett.org
Thu Jul 3 12:38:12 PDT 2014


With the image generation factored out to piglit_rgbw_image and
piglit_rgbw_image_ubyte, the remainder of the implementation becomes
common between GL and GLES.

This eliminates the last helper function from piglit-util-gles.c, so
drop it.

Signed-off-by: Josh Triplett <josh at joshtriplett.org>
---
 tests/util/CMakeLists.gles1.txt    |   5 -
 tests/util/CMakeLists.gles2.txt    |   1 -
 tests/util/CMakeLists.gles3.txt    |   1 -
 tests/util/piglit-util-gl-common.c | 209 +++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl.c        | 166 -----------------------------
 tests/util/piglit-util-gles.c      | 126 ----------------------
 6 files changed, 209 insertions(+), 299 deletions(-)
 delete mode 100644 tests/util/piglit-util-gles.c

diff --git a/tests/util/CMakeLists.gles1.txt b/tests/util/CMakeLists.gles1.txt
index fe38404..4342cf2 100644
--- a/tests/util/CMakeLists.gles1.txt
+++ b/tests/util/CMakeLists.gles1.txt
@@ -1,8 +1,3 @@
-set(UTIL_GL_SOURCES
-	${UTIL_GL_SOURCES}
-	piglit-util-gles.c
-	)
-
 include_directories(
 	${UTIL_GL_INCLUDES}
 	)
diff --git a/tests/util/CMakeLists.gles2.txt b/tests/util/CMakeLists.gles2.txt
index 2ce87e5..0faedb5 100644
--- a/tests/util/CMakeLists.gles2.txt
+++ b/tests/util/CMakeLists.gles2.txt
@@ -5,7 +5,6 @@ set(UTIL_GL_SOURCES
 	piglit-dispatch-init.c
 	piglit-shader.c
 	piglit-shader-gles2.c
-	piglit-util-gles.c
 	minmax-test.c
 	)
 
diff --git a/tests/util/CMakeLists.gles3.txt b/tests/util/CMakeLists.gles3.txt
index 9572b59..50abd08 100644
--- a/tests/util/CMakeLists.gles3.txt
+++ b/tests/util/CMakeLists.gles3.txt
@@ -4,7 +4,6 @@ list(APPEND UTIL_GL_SOURCES
 	piglit-dispatch-init.c
 	piglit-shader.c
 	piglit-shader-gles2.c # Compatible with gles3.
-	piglit-util-gles.c
 	piglit-vbo.cpp
 	)
 
diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c
index 537e19c..94e0816 100644
--- a/tests/util/piglit-util-gl-common.c
+++ b/tests/util/piglit-util-gl-common.c
@@ -2066,3 +2066,212 @@ piglit_miptree_texture()
 	}
 	return tex;
 }
+
+/**
+ * Generates an image of the given size with quadrants of red, green,
+ * blue and white.
+ * 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.
+ *
+ * \param internalFormat  either GL_RGBA or a specific compressed format
+ * \param w  the width in texels
+ * \param h  the height in texels
+ * \param alpha  if TRUE, use varied alpha values, else all alphas = 1
+ * \param basetype  either GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED
+ *                  or GL_FLOAT
+ */
+GLfloat *
+piglit_rgbw_image(GLenum internalFormat, int w, int h,
+		  GLboolean alpha, GLenum basetype)
+{
+	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};
+	GLfloat *data;
+	int x, y;
+
+	if (!alpha) {
+		red[3] = 1.0;
+		green[3] = 1.0;
+		blue[3] = 1.0;
+		white[3] = 1.0;
+	}
+
+	switch (basetype) {
+	case GL_UNSIGNED_NORMALIZED:
+		break;
+
+	case GL_SIGNED_NORMALIZED:
+		for (x = 0; x < 4; x++) {
+			red[x] = red[x] * 2 - 1;
+			green[x] = green[x] * 2 - 1;
+			blue[x] = blue[x] * 2 - 1;
+			white[x] = white[x] * 2 - 1;
+		}
+		break;
+
+	case GL_FLOAT:
+		for (x = 0; x < 4; x++) {
+			red[x] = red[x] * 10 - 5;
+			green[x] = green[x] * 10 - 5;
+			blue[x] = blue[x] * 10 - 5;
+			white[x] = white[x] * 10 - 5;
+		}
+		break;
+
+	default:
+		assert(0);
+	}
+
+	data = malloc(w * h * 4 * sizeof(GLfloat));
+
+	for (y = 0; y < h; y++) {
+		for (x = 0; x < w; x++) {
+			const int size = w > h ? w : h;
+			const float *color;
+
+			if (x < w / 2 && y < h / 2)
+				color = red;
+			else if (y < h / 2)
+				color = green;
+			else if (x < w / 2)
+				color = blue;
+			else
+				color = white;
+
+			switch (internalFormat) {
+			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:
+			case GL_COMPRESSED_RED_RGTC1:
+			case GL_COMPRESSED_SIGNED_RED_RGTC1:
+			case GL_COMPRESSED_RG_RGTC2:
+			case GL_COMPRESSED_SIGNED_RG_RGTC2:
+			case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
+			case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
+			case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
+			case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
+				if (size == 4)
+					color = red;
+				else if (size == 2)
+					color = green;
+				else if (size == 1)
+					color = blue;
+				break;
+			default:
+				break;
+			}
+
+			memcpy(data + (y * w + x) * 4, color,
+			       4 * sizeof(float));
+		}
+	}
+
+	return data;
+}
+
+static GLubyte *
+piglit_rgbw_image_ubyte(int w, int h, GLboolean alpha)
+{
+	GLubyte red[4]   = {255, 0, 0, 0};
+	GLubyte green[4] = {0, 255, 0, 64};
+	GLubyte blue[4]  = {0, 0, 255, 128};
+	GLubyte white[4] = {255, 255, 255, 255};
+	GLubyte *data;
+	int x, y;
+
+	if (!alpha) {
+		red[3] = 255;
+		green[3] = 255;
+		blue[3] = 255;
+		white[3] = 255;
+	}
+
+	data = malloc(w * h * 4 * sizeof(GLubyte));
+
+	for (y = 0; y < h; y++) {
+		for (x = 0; x < w; x++) {
+			const GLubyte *color;
+
+			if (x < w / 2 && y < h / 2)
+				color = red;
+			else if (y < h / 2)
+				color = green;
+			else if (x < w / 2)
+				color = blue;
+			else
+				color = white;
+
+			memcpy(data + (y * w + x) * 4, color,
+			       4 * sizeof(GLubyte));
+		}
+	}
+
+	return data;
+}
+
+/**
+ * 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 internalFormat, int w, int h, GLboolean mip,
+		    GLboolean alpha, GLenum basetype)
+{
+	GLenum data_format;
+	int size, level;
+	GLuint tex;
+
+	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_format = piglit_is_gles() ? GL_UNSIGNED_BYTE : GL_FLOAT;
+
+	for (level = 0, size = w > h ? w : h; size > 0; level++, size >>= 1) {
+		void *data;
+
+		if (piglit_is_gles())
+			data = piglit_rgbw_image_ubyte(w, h, alpha);
+		else
+			data = piglit_rgbw_image(internalFormat, w, h,
+			                         alpha, basetype);
+
+		glTexImage2D(GL_TEXTURE_2D, level,
+			     internalFormat,
+			     w, h, 0,
+			     GL_RGBA, data_format, data);
+		free(data);
+
+		if (!mip)
+			break;
+
+		if (w > 1)
+			w >>= 1;
+		if (h > 1)
+			h >>= 1;
+	}
+
+	return tex;
+}
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 5e20b01..5f6b41b 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -35,172 +35,6 @@
 
 #include "piglit-util-gl-common.h"
 
-
-/**
- * Generates an image of the given size with quadrants of red, green,
- * blue and white.
- * 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.
- *
- * \param internalFormat  either GL_RGBA or a specific compressed format
- * \param w  the width in texels
- * \param h  the height in texels
- * \param alpha  if TRUE, use varied alpha values, else all alphas = 1
- * \param basetype  either GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED
- *                  or GL_FLOAT
- */
-GLfloat *
-piglit_rgbw_image(GLenum internalFormat, int w, int h,
-		  GLboolean alpha, GLenum basetype)
-{
-	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};
-	GLfloat *data;
-	int x, y;
-
-	if (!alpha) {
-		red[3] = 1.0;
-		green[3] = 1.0;
-		blue[3] = 1.0;
-		white[3] = 1.0;
-	}
-
-	switch (basetype) {
-	case GL_UNSIGNED_NORMALIZED:
-		break;
-
-	case GL_SIGNED_NORMALIZED:
-		for (x = 0; x < 4; x++) {
-			red[x] = red[x] * 2 - 1;
-			green[x] = green[x] * 2 - 1;
-			blue[x] = blue[x] * 2 - 1;
-			white[x] = white[x] * 2 - 1;
-		}
-		break;
-
-	case GL_FLOAT:
-		for (x = 0; x < 4; x++) {
-			red[x] = red[x] * 10 - 5;
-			green[x] = green[x] * 10 - 5;
-			blue[x] = blue[x] * 10 - 5;
-			white[x] = white[x] * 10 - 5;
-		}
-		break;
-
-	default:
-		assert(0);
-	}
-
-	data = malloc(w * h * 4 * sizeof(GLfloat));
-
-	for (y = 0; y < h; y++) {
-		for (x = 0; x < w; x++) {
-			const int size = w > h ? w : h;
-			const float *color;
-
-			if (x < w / 2 && y < h / 2)
-				color = red;
-			else if (y < h / 2)
-				color = green;
-			else if (x < w / 2)
-				color = blue;
-			else
-				color = white;
-
-			switch (internalFormat) {
-			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:
-			case GL_COMPRESSED_RED_RGTC1:
-			case GL_COMPRESSED_SIGNED_RED_RGTC1:
-			case GL_COMPRESSED_RG_RGTC2:
-			case GL_COMPRESSED_SIGNED_RG_RGTC2:
-			case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
-			case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
-			case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
-			case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
-				if (size == 4)
-					color = red;
-				else if (size == 2)
-					color = green;
-				else if (size == 1)
-					color = blue;
-				break;
-			default:
-				break;
-			}
-
-			memcpy(data + (y * w + x) * 4, color,
-			       4 * sizeof(float));
-		}
-	}
-
-	return data;
-}
-
-
-/**
- * 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 internalFormat, int w, int h, GLboolean mip,
-		    GLboolean alpha, GLenum basetype)
-{
-	int size, level;
-	GLuint tex;
-
-	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);
-	}
-
-	for (level = 0, size = w > h ? w : h; size > 0; level++, size >>= 1) {
-		GLfloat *data =
-			piglit_rgbw_image(internalFormat, w, h,
-					  alpha, basetype);
-
-		glTexImage2D(GL_TEXTURE_2D, level,
-			     internalFormat,
-			     w, h, 0,
-			     GL_RGBA, GL_FLOAT, data);
-
-		free(data);
-
-		if (!mip)
-			break;
-
-		if (w > 1)
-			w >>= 1;
-		if (h > 1)
-			h >>= 1;
-	}
-
-	return tex;
-}
-
-
 /**
  * Create a depth texture.  The depth texture will be a gradient which varies
  * from 0.0 at the left side to 1.0 at the right side.  For a 2D array texture,
diff --git a/tests/util/piglit-util-gles.c b/tests/util/piglit-util-gles.c
deleted file mode 100644
index e4b3ec4..0000000
--- a/tests/util/piglit-util-gles.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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(_WIN32)
-#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-gl-common.h"
-
-static GLubyte *
-piglit_rgbw_image_ubyte(int w, int h, GLboolean alpha)
-{
-	GLubyte red[4]   = {255, 0, 0, 0};
-	GLubyte green[4] = {0, 255, 0, 64};
-	GLubyte blue[4]  = {0, 0, 255, 128};
-	GLubyte white[4] = {255, 255, 255, 255};
-	GLubyte *data;
-	int x, y;
-
-	if (!alpha) {
-		red[3] = 255;
-		green[3] = 255;
-		blue[3] = 255;
-		white[3] = 255;
-	}
-
-	data = malloc(w * h * 4 * sizeof(GLubyte));
-
-	for (y = 0; y < h; y++) {
-		for (x = 0; x < w; x++) {
-			const GLubyte *color;
-
-			if (x < w / 2 && y < h / 2)
-				color = red;
-			else if (y < h / 2)
-				color = green;
-			else if (x < w / 2)
-				color = blue;
-			else
-				color = white;
-
-			memcpy(data + (y * w + x) * 4, color,
-			       4 * sizeof(GLubyte));
-		}
-	}
-
-	return data;
-}
-
-/**
- * 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, GLenum basetype)
-{
-	int size, level;
-	GLuint tex;
-
-	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);
-	}
-
-	for (level = 0, size = w > h ? w : h; size > 0; level++, size >>= 1) {
-		GLubyte *data = piglit_rgbw_image_ubyte(w, h, alpha);
-		glTexImage2D(GL_TEXTURE_2D, level,
-			     format,
-			     w, h, 0,
-			     GL_RGBA, GL_UNSIGNED_BYTE, data);
-		free(data);
-
-		if (!mip)
-			break;
-
-		if (w > 1)
-			w >>= 1;
-		if (h > 1)
-			h >>= 1;
-	}
-	return tex;
-}
-- 
2.0.1



More information about the Piglit mailing list