[Piglit] [PATCH 8/8] Convert some raw glReadPixels to use piglit probes

Chris Forbes chrisf at ijw.co.nz
Sat Sep 1 18:17:33 PDT 2012


V2: don't introduce bogus indentation; use real bools

Reviewed-by: Paul Berry <stereotype441 at gmail.com>
---
 tests/shaders/fp-incomplete-tex.c | 45 ++++++++-------------------------------
 tests/shaders/fp-kil.c            | 45 ++++++++-------------------------------
 tests/texturing/crossbar.c        | 34 +++++++----------------------
 3 files changed, 26 insertions(+), 98 deletions(-)

diff --git a/tests/shaders/fp-incomplete-tex.c b/tests/shaders/fp-incomplete-tex.c
index 66375c1..87a66e3 100644
--- a/tests/shaders/fp-incomplete-tex.c
+++ b/tests/shaders/fp-incomplete-tex.c
@@ -128,54 +128,27 @@ static const struct {
 	}
 };
 
-static int DoTest( void )
+static bool DoTest( void )
 {
-	int idx;
-	GLfloat dmax;
+	int idx = 0;
+	bool pass = true;
 
-	dmax = 0;
-
-	idx = 0;
 	while(Probes[idx].name) {
-		GLfloat probe[4];
-		GLfloat delta[4];
-		int i;
-
-		glReadPixels((int)(Probes[idx].x * piglit_width / 3),
-			     (int)(Probes[idx].y * piglit_height / 2),
-			     1, 1,
-		GL_RGBA, GL_FLOAT, probe);
-
-		printf("%20s (%3.1f,%3.1f): %f,%f,%f,%f",
-		       Probes[idx].name,
-		       Probes[idx].x, Probes[idx].y,
-		       probe[0], probe[1], probe[2], probe[3]);
-
-		for(i = 0; i < 4; ++i) {
-			delta[i] = probe[i] - Probes[idx].expected[i];
-
-			if (delta[i] > dmax) dmax = delta[i];
-			else if (-delta[i] > dmax) dmax = -delta[i];
-		}
-
-		printf("   Delta: %f,%f,%f,%f\n", delta[0], delta[1], delta[2], delta[3]);
-
+		pass = piglit_probe_pixel_rgba(
+			(int)(Probes[idx].x * piglit_width / 3),
+			(int)(Probes[idx].y * piglit_height / 2),
+			Probes[idx].expected) && pass;
 		idx++;
 	}
 
-	printf("Max delta: %f\n", dmax);
-
-	if (dmax >= 0.02)
-		return 0;
-	else
-		return 1;
+	return pass;
 }
 
 
 enum piglit_result
 piglit_display(void)
 {
-	int pass;
+	bool pass;
 
 	DoFrame();
 	pass = DoTest();
diff --git a/tests/shaders/fp-kil.c b/tests/shaders/fp-kil.c
index d82b59e..cb25e5f 100644
--- a/tests/shaders/fp-kil.c
+++ b/tests/shaders/fp-kil.c
@@ -203,53 +203,26 @@ static const struct {
 	}
 };
 
-static int DoTest( void )
+static bool DoTest( void )
 {
-	int idx;
-	GLfloat dmax;
+	int idx = 0;
+	bool pass = true;
 
-	dmax = 0;
-
-	idx = 0;
 	while(Probes[idx].name) {
-		GLfloat probe[4];
-		GLfloat delta[4];
-		int i;
-
-		glReadPixels((int)(Probes[idx].x*piglit_width/2),
-		             (int)(Probes[idx].y*piglit_height/2),
-		             1, 1,
-		             GL_RGBA, GL_FLOAT, probe);
-
-		printf("%20s (%3.1f,%3.1f): %f,%f,%f,%f",
-		       Probes[idx].name,
-		       Probes[idx].x, Probes[idx].y,
-		       probe[0], probe[1], probe[2], probe[3]);
-
-		for(i = 0; i < 4; ++i) {
-			delta[i] = probe[i] - Probes[idx].expected[i];
-
-			if (delta[i] > dmax) dmax = delta[i];
-			else if (-delta[i] > dmax) dmax = -delta[i];
-		}
-
-		printf("   Delta: %f,%f,%f,%f\n", delta[0], delta[1], delta[2], delta[3]);
-
+		pass = piglit_probe_pixel_rgba(
+			(int)(Probes[idx].x*piglit_width/2),
+			(int)(Probes[idx].y*piglit_height/2),
+			Probes[idx].expected) && pass;
 		idx++;
 	}
 
-	printf("Max delta: %f\n", dmax);
-
-	if (dmax >= 0.02)
-		return 0;
-	else
-		return 1;
+	return pass;
 }
 
 enum piglit_result
 piglit_display(void)
 {
-	int pass;
+	bool pass;
 
 	piglit_gen_ortho_projection(0.0, 2.0, 0.0, 2.0, -2.0, 6.0, GL_FALSE);
 
diff --git a/tests/texturing/crossbar.c b/tests/texturing/crossbar.c
index 497ff31..9bdaae8 100644
--- a/tests/texturing/crossbar.c
+++ b/tests/texturing/crossbar.c
@@ -110,37 +110,19 @@ static void DoFrame( void )
 
 }
 
-static int DoTest( void )
+static bool DoTest( void )
 {
+   const static float expected[] = {0.5f, 0.5f, 0.5f};
+   bool pass = true;
    int i;
-   GLfloat probe[NUM_TESTS+1][4];
-   GLfloat dr, dg, db;
-   GLfloat dmax;
 
-   glReadBuffer( GL_BACK );
-
-   dmax = 0;
    for( i = 0; i <= NUM_TESTS; ++i ) {
-      glReadPixels(piglit_width*(2*i+1)/((NUM_TESTS+1)*2), piglit_height/2, 1, 1, GL_RGBA, GL_FLOAT, probe[i]);
-      printf("Probe %i: %f,%f,%f\n", i, probe[i][0], probe[i][1], probe[i][2]);
-      dr = probe[i][0] - 0.5f;
-      dg = probe[i][1] - 0.5f;
-      db = probe[i][2] - 0.5f;
-      printf("   Delta: %f,%f,%f\n", dr, dg, db);
-      if (dr > dmax) dmax = dr;
-      else if (-dr > dmax) dmax = -dr;
-      if (dg > dmax) dmax = dg;
-      else if (-dg > dmax) dmax = -dg;
-      if (db > dmax) dmax = db;
-      else if (-db > dmax) dmax = -db;
+	   pass = piglit_probe_pixel_rgb(piglit_width*(2*i+1)/((NUM_TESTS+1)*2),
+			   piglit_height/2,
+			   expected) && pass;
    }
 
-   printf("Max delta: %f\n", dmax);
-
-   if (dmax >= 0.07) // roughly 1/128
-      return 0;
-   else
-      return 1;
+   return pass;
 }
 
 enum piglit_result
@@ -151,7 +133,7 @@ piglit_display(void)
       piglit_present_results();
       return PIGLIT_PASS;
    } else {
-      int success, retry;
+      bool success, retry;
 
       printf("\nFirst frame\n-----------\n");
       DoFrame();
-- 
1.7.12



More information about the Piglit mailing list