[Piglit] [PATCH 3/7] util: Refactor depth level setup

Topi Pohjolainen topi.pohjolainen at intel.com
Thu Apr 28 19:17:06 UTC 2016


Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
 tests/util/piglit-util-gl.c | 87 +++++++++++++++++++++++++--------------------
 1 file changed, 49 insertions(+), 38 deletions(-)

diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 5e96c33..d09ce8e 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -2647,6 +2647,52 @@ generate_depth_layer(GLenum internalformat, int w, int h, int layer, void *data)
 	}
 }
 
+static void
+setup_depth_level(GLenum target, GLenum internalformat, GLenum format,
+                  GLenum type, int w, int h, int d, int level)
+{
+	int layer;
+	void *data = malloc(w * h * 4 * sizeof(GLfloat));
+
+	switch (target) {
+	case GL_TEXTURE_1D:
+		generate_depth_layer(internalformat, w, h, 0, data);
+		glTexImage1D(target, level,
+			     internalformat,
+			     w, 0,
+			     format, type, data);
+		break;
+
+	case GL_TEXTURE_1D_ARRAY:
+	case GL_TEXTURE_2D:
+	case GL_TEXTURE_RECTANGLE:
+		generate_depth_layer(internalformat, w, h, 0, data);
+		glTexImage2D(target, level,
+			     internalformat,
+			     w, h, 0,
+			     format, type, data);
+		break;
+
+	case GL_TEXTURE_2D_ARRAY:
+		glTexImage3D(target, level,
+			     internalformat,
+			     w, h, d, 0,
+			     format, type, NULL);
+		for (layer = 0; layer < d; layer++) {
+			generate_depth_layer(internalformat, w, h, layer, data);
+			glTexSubImage3D(target, level,
+					0, 0, layer, w, h, 1,
+					format, type, data);
+		}
+		break;
+
+	default:
+		assert(0);
+	}
+
+	free(data);
+}
+
 /**
  * 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,
@@ -2663,8 +2709,7 @@ generate_depth_layer(GLenum internalformat, int w, int h, int layer, void *data)
 GLuint
 piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d, GLboolean mip)
 {
-	void *data;
-	int size, level, layer;
+	int size, level;
 	GLuint tex;
 	GLenum type, format;
 
@@ -2683,7 +2728,6 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
 		glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
 				GL_NEAREST);
 	}
-	data = malloc(w * h * 4 * sizeof(GLfloat));
 
 	if (internalformat == GL_DEPTH_STENCIL_EXT ||
 	    internalformat == GL_DEPTH24_STENCIL8_EXT) {
@@ -2698,40 +2742,8 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
 	}
 
 	for (level = 0, size = w > h ? w : h; size > 0; level++, size >>= 1) {
-		generate_depth_layer(internalformat, w, h, 0, data);
-
-		switch (target) {
-		case GL_TEXTURE_1D:
-			glTexImage1D(target, level,
-				     internalformat,
-				     w, 0,
-				     format, type, data);
-			break;
-
-		case GL_TEXTURE_1D_ARRAY:
-		case GL_TEXTURE_2D:
-		case GL_TEXTURE_RECTANGLE:
-			glTexImage2D(target, level,
-				     internalformat,
-				     w, h, 0,
-				     format, type, data);
-			break;
-
-		case GL_TEXTURE_2D_ARRAY:
-			glTexImage3D(target, level,
-				     internalformat,
-				     w, h, d, 0,
-				     format, type, NULL);
-			for (layer = 0; layer < d; layer++) {
-				glTexSubImage3D(target, level,
-						0, 0, layer, w, h, 1,
-						format, type, data);
-			}
-			break;
-
-		default:
-			assert(0);
-		}
+		setup_depth_level(target, internalformat, format, type,
+                                  w, h, d, level);
 
 		if (!mip)
 			break;
@@ -2743,7 +2755,6 @@ piglit_depth_texture(GLenum target, GLenum internalformat, int w, int h, int d,
 		    h > 1)
 			h >>= 1;
 	}
-	free(data);
 	return tex;
 }
 
-- 
2.5.5



More information about the Piglit mailing list