[Piglit] [PATCH 06/11] max-texture-size: Remove loop over boolean value.

Kenneth Graunke kenneth at whitecape.org
Sun Feb 2 03:13:54 PST 2014


I don't particularly care for this pattern:

   for (boolean = 1; boolean >= 0; boolean--)

This patch pulls the body of that loop out into a helper function, and
calls it twice.  One could argue that my use of function pointers is a
bit arcane and ugly, too, but I think I prefer it in this case.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 tests/texturing/max-texture-size.c | 46 ++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 27 deletions(-)

diff --git a/tests/texturing/max-texture-size.c b/tests/texturing/max-texture-size.c
index 483980b..d1284f8 100644
--- a/tests/texturing/max-texture-size.c
+++ b/tests/texturing/max-texture-size.c
@@ -388,39 +388,31 @@ out:
 }
 
 static bool
-ValidateTexSize(GLenum target, GLenum internalformat, bool useProxy)
+for_targets_and_formats(bool(*test)(GLenum, GLenum))
 {
-	if (useProxy)
-		return test_proxy_texture_size(target, internalformat);
-	else
-		return test_non_proxy_texture_size(target, internalformat);
+	bool pass = true;
+	int i, j;
+	for (i = 0; i < ARRAY_SIZE(target); i++) {
+		for (j = 0; j < ARRAY_SIZE(internalformat); j++) {
+			/* Skip floating point formats if
+			 * GL_ARB_texture_float is not supported
+			 */
+			if ((internalformat[j] == GL_RGBA16F ||
+			    internalformat[j] == GL_RGBA32F) &&
+			    !piglit_is_extension_supported("GL_ARB_texture_float"))
+				continue;
+			 pass = test(target[i], internalformat[j]) && pass;
+		}
+	}
+	return pass;
 }
 
 void
 piglit_init(int argc, char **argv)
 {
-	GLboolean pass = true;
-	int i, j, useProxy;
-
-	for (useProxy = 1; useProxy >= 0; useProxy--) {
-		for (i = 0; i < ARRAY_SIZE(target); i++) {
-			for (j = 0; j < ARRAY_SIZE(internalformat); j++) {
-				/* Skip floating point formats if
-				 * GL_ARB_texture_float is not supported
-				 */
-				if ((internalformat[j] == GL_RGBA16F ||
-				    internalformat[j] == GL_RGBA32F) &&
-				    !piglit_is_extension_supported(
-				    "GL_ARB_texture_float"))
-					continue;
-				/* Test using proxy textures */
-				 pass = ValidateTexSize (target[i],
-							 internalformat[j],
-							 useProxy)
-					&& pass;
-			}
-		}
-	}
+	bool pass = for_targets_and_formats(test_proxy_texture_size) &&
+		    for_targets_and_formats(test_non_proxy_texture_size);
+
 	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
 }
 
-- 
1.8.5.2



More information about the Piglit mailing list