[Piglit] [PATCH 5/8] shader_runner: Add ability to create textures with per-miplevel colors.

Kenneth Graunke kenneth at whitecape.org
Wed Apr 4 01:51:26 PDT 2012


For basic mipmapped texture testing, it's often useful to create
textures where each miplevel has a unique color.

The next commit will use this to simplify an existing test case, and
subsequent commits will introduce new tests based on this functionality.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 tests/shaders/shader_runner.c |    4 ++++
 tests/util/piglit-util-gl.c   |   39 +++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util.h      |    1 +
 3 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index ee49e41..d5cc220 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -1264,6 +1264,10 @@ piglit_display(void)
 			glActiveTexture(GL_TEXTURE0 + tex);
 			piglit_rgbw_texture(GL_RGBA, w, h, GL_FALSE, GL_FALSE, GL_UNSIGNED_NORMALIZED);
 			glEnable(GL_TEXTURE_2D);
+		} else if (sscanf(line, "texture miptree %d", &tex) == 1) {
+			glActiveTexture(GL_TEXTURE0 + tex);
+			piglit_miptree_texture();
+			glEnable(GL_TEXTURE_2D);
 		} else if (sscanf(line,
 				  "texture checkerboard %d %d ( %d , %d ) "
 				  "( %f , %f , %f , %f ) "
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 4270cd6..269ed4d 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -959,6 +959,45 @@ piglit_checkerboard_texture(GLuint tex, unsigned level,
 }
 
 /**
+ * Generates a 8x8 mipmapped texture whose layers contain solid r, g, b, and w.
+ */
+GLuint
+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);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+			GL_NEAREST_MIPMAP_NEAREST);
+
+	for (level = 0; level < 4; ++level) {
+		size = 8 >> level;
+
+		data = malloc(size*size*4*sizeof(GLfloat));
+		for (i = 0; i < size * size; ++i) {
+			memcpy(data + 4 * i, color_wheel[level],
+			       4 * sizeof(GLfloat));
+		}
+		glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA,
+			     size, size, 0, GL_RGBA, GL_FLOAT, data);
+		free(data);
+	}
+	return tex;
+}
+
+/**
  * Generates a texture with the given internalFormat, w, h with a
  * teximage of r, g, b w quadrants.
  *
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 775dfe2..66fdb2a 100755
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -253,6 +253,7 @@ GLuint piglit_checkerboard_texture(GLuint tex, unsigned level,
     unsigned width, unsigned height,
     unsigned horiz_square_size, unsigned vert_square_size,
     const float *black, const float *white);
+GLuint piglit_miptree_texture();
 GLuint piglit_rgbw_texture(GLenum format, 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);
-- 
1.7.7.6



More information about the Piglit mailing list