[Piglit] [PATCH 1/3] util: add piglit_2darray_texture() function

Brian Paul brianp at vmware.com
Thu Jul 31 16:00:19 PDT 2014


Each slice of the 2D array is a solid color (red, green, blue, white,
etc.)
---
 tests/util/piglit-util-gl.c |   79 +++++++++++++++++++++++++++++++++++++++----
 tests/util/piglit-util-gl.h |    1 +
 2 files changed, 74 insertions(+), 6 deletions(-)

diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 1a8ee18..445f135 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -35,6 +35,13 @@
  */
 static const char **gl_extensions = NULL;
 
+static const float color_wheel[4][4] = {
+	{1, 0, 0, 1}, /* red */
+	{0, 1, 0, 1}, /* green */
+	{0, 0, 1, 1}, /* blue */
+	{1, 1, 1, 1}, /* white */
+};
+
 bool piglit_is_core_profile;
 
 bool piglit_is_gles(void)
@@ -2012,12 +2019,6 @@ piglit_miptree_texture()
 	GLfloat *data;
 	int size, i, level;
 	GLuint tex;
-	const float color_wheel[4][4] = {
-		{1, 0, 0, 1}, /* red */
-		{0, 1, 0, 1}, /* green */
-		{0, 0, 1, 1}, /* blue */
-		{1, 1, 1, 1}, /* white */
-	};
 
 	glGenTextures(1, &tex);
 	glBindTexture(GL_TEXTURE_2D, tex);
@@ -2376,6 +2377,72 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
 }
 
 /**
+ * Create 2D array texture in which each slice is a different color.
+ * the color pattern is red, green, blue, white, red, green, ...
+ */
+GLuint
+piglit_2darray_texture(GLenum target, GLenum internalformat,
+		       int w, int h, int d, GLboolean mip)
+{
+	float *data;
+	int size, i, level, layer;
+	GLuint tex;
+	GLenum type = GL_FLOAT, format = GL_RGBA;
+
+	glGenTextures(1, &tex);
+	glBindTexture(target, tex);
+	glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	if (mip) {
+		glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
+				GL_LINEAR);
+		glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
+				GL_LINEAR_MIPMAP_NEAREST);
+	} else {
+		glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
+				GL_NEAREST);
+		glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
+				GL_NEAREST);
+	}
+	data = malloc(w * h * 4 * sizeof(GLfloat));
+
+	size = w > h ? w : h;
+
+	for (level = 0; size > 0; level++, size >>= 1) {
+
+		/* Create mipmap level */
+		glTexImage3D(target, level,
+			     internalformat,
+			     w, h, d, 0,
+			     format, type, NULL);
+
+		for (layer = 0; layer < d; layer++) {
+			/* Set whole layer to one color */
+			for (i = 0; i < w * h; i++) {
+				memcpy(data + 4 * i,
+				       color_wheel[layer %
+						   ARRAY_SIZE(color_wheel)],
+				       sizeof(color_wheel[0]));
+			}
+
+			glTexSubImage3D(target, level,
+					0, 0, layer, w, h, 1,
+					format, type, data);
+		}
+
+		if (!mip)
+			break;
+
+		if (w > 1)
+			w >>= 1;
+		if (h > 1)
+			h >>= 1;
+	}
+	free(data);
+	return tex;
+}
+
+/**
  * Require transform feedback.
  *
  * Transform feedback may either be provided by GL 3.0 or
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 73b658e..fa78a5b 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -203,6 +203,7 @@ GLfloat *piglit_rgbw_image(GLenum internalFormat, int w, int h,
 GLuint piglit_rgbw_texture(GLenum internalFormat, int w, int h, GLboolean mip,
 		    GLboolean alpha, GLenum basetype);
 GLuint piglit_depth_texture(GLenum target, GLenum format, int w, int h, int d, GLboolean mip);
+GLuint piglit_2darray_texture(GLenum target, GLenum format, int w, int h, int d, GLboolean mip);
 extern float piglit_tolerance[4];
 void piglit_set_tolerance_for_bits(int rbits, int gbits, int bbits, int abits);
 extern void piglit_require_transform_feedback(void);
-- 
1.7.10.4



More information about the Piglit mailing list