[Piglit] [PATCH] fbo-depth: remove hard-coded BUF_SIZE, use piglit_probe_rect_depth()

Brian Paul brianp at vmware.com
Mon Apr 28 16:42:36 PDT 2014


Instead of fixed BUF_SIZE use the current window size.
Instead of hand-rolled depth buffer probing, use piglit_probe_rect_depth()
---
 tests/fbo/fbo-depth.c |  112 ++++++++++++++++++++++---------------------------
 1 file changed, 50 insertions(+), 62 deletions(-)

diff --git a/tests/fbo/fbo-depth.c b/tests/fbo/fbo-depth.c
index 532c6db..e21715a 100644
--- a/tests/fbo/fbo-depth.c
+++ b/tests/fbo/fbo-depth.c
@@ -30,14 +30,10 @@
 
 #include "piglit-util-gl-common.h"
 
-#define BUF_SIZE 123
-
 PIGLIT_GL_TEST_CONFIG_BEGIN
 
 	config.supports_gl_compat_version = 10;
 
-	config.window_width = BUF_SIZE;
-	config.window_height = BUF_SIZE;
 	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE;
 
 PIGLIT_GL_TEST_CONFIG_END
@@ -78,7 +74,8 @@ static enum piglit_result test_clear(void)
 	/* Add a colorbuffer. */
 	glGenRenderbuffersEXT(1, &cb);
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, cb);
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, BUF_SIZE, BUF_SIZE);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8,
+				 piglit_width, piglit_height);
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
 
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0,
@@ -106,12 +103,14 @@ static enum piglit_result test_clear(void)
 
 	glDisable(GL_DEPTH_TEST);
 
-	res = piglit_probe_rect_rgb(0, 0, BUF_SIZE, BUF_SIZE, green) ? PIGLIT_PASS : PIGLIT_FAIL;
+	res = piglit_probe_rect_rgb(0, 0, piglit_width, piglit_height, green)
+		? PIGLIT_PASS : PIGLIT_FAIL;
 
 	/* Display the colorbuffer. */
 	if (!piglit_automatic) {
 		glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, piglit_winsys_fbo);
-		glBlitFramebufferEXT(0, 0, BUF_SIZE, BUF_SIZE, 0, 0, BUF_SIZE, BUF_SIZE,
+		glBlitFramebufferEXT(0, 0, piglit_width, piglit_height,
+				     0, 0, piglit_width, piglit_height,
 				     GL_COLOR_BUFFER_BIT, GL_NEAREST);
 	}
 
@@ -122,51 +121,33 @@ static enum piglit_result test_clear(void)
 
 static enum piglit_result compare()
 {
-	int x, y, failures = 0;
-	GLfloat depth[BUF_SIZE*BUF_SIZE];
-	GLfloat expected_depth;
-
-	/* Read buffers. */
-	glReadPixels(0, 0, BUF_SIZE, BUF_SIZE, GL_DEPTH_COMPONENT,
-		     GL_FLOAT, depth);
-
-	/* Compare results. */
-	for (y = 0; y < BUF_SIZE; y++) {
-		for (x = 0; x < BUF_SIZE; x++) {
-
-			/* Skip the middle row and column of pixels because
-			 * drawing polygons for the left/right and bottom/top
-			 * quadrants may hit the middle pixels differently
-			 * depending on minor transformation and rasterization
-			 * differences.
-			 */
-			if (x == BUF_SIZE / 2 || y == BUF_SIZE / 2)
-				continue;
-
-			if (y < BUF_SIZE/2) {
-				expected_depth = x < BUF_SIZE/2 ? 0.25 : 0.375;
-			} else {
-				expected_depth = x < BUF_SIZE/2 ? 0.625 : 0.75;
-			}
-
-			if (fabs(depth[y*BUF_SIZE+x] - expected_depth) > 0.001) {
-				failures++;
-				if (failures < 20) {
-					printf("Depth at %i,%i   Expected: %f   Observed: %f\n",
-						x, y, expected_depth, depth[y*BUF_SIZE+x]);
-				} else if (failures == 20) {
-					printf("...\n");
-				}
-			}
-		}
-	}
-	if (failures)
-		printf("Total failures: %i\n", failures);
-
-	return failures == 0 ? PIGLIT_PASS : PIGLIT_FAIL;
+	const int w = piglit_width / 2 - 1;
+	const int h = piglit_height / 2 - 1;
+	bool pass;
+
+	/* Compare results in four quadrants.
+	 * Note: we skip the middle row and column of pixels because
+	 * drawing polygons for the left/right and bottom/top
+	 * quadrants may hit the middle pixels differently
+	 * depending on minor transformation and rasterization
+	 * differences.
+	 */
+	pass = piglit_probe_rect_depth(0, 0, w, h, 0.25);
+
+	pass = piglit_probe_rect_depth(piglit_width / 2 + 1, 0, w, h, 0.375)
+		&& pass;
+
+	pass = piglit_probe_rect_depth(0, piglit_height / 2 + 1,
+				       w, h, 0.625) && pass;
+
+	pass = piglit_probe_rect_depth(piglit_width / 2 + 1,
+				       piglit_height / 2 + 1,
+				       w, h, 0.75) && pass;
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
-static enum piglit_result test_readpixels()
+static enum piglit_result test_readpixels(void)
 {
 	/* Clear. */
 	glClearDepth(0);
@@ -189,14 +170,16 @@ static enum piglit_result test_readpixels()
 static enum piglit_result test_drawpixels()
 {
 	int x, y;
-	GLfloat depth[BUF_SIZE*BUF_SIZE];
+	GLfloat *depth;
 
-	for (y = 0; y < BUF_SIZE; y++) {
-		for (x = 0; x < BUF_SIZE; x++) {
-			if (y < BUF_SIZE/2) {
-				depth[y*BUF_SIZE+x] = x < BUF_SIZE/2 ? 0.25 : 0.375;
+	depth = malloc(piglit_width * piglit_height * sizeof(GLfloat));
+
+	for (y = 0; y < piglit_height; y++) {
+		for (x = 0; x < piglit_width; x++) {
+			if (y < piglit_height/2) {
+				depth[y*piglit_width+x] = x < piglit_width/2 ? 0.25 : 0.375;
 			} else {
-				depth[y*BUF_SIZE+x] = x < BUF_SIZE/2 ? 0.625 : 0.75;
+				depth[y*piglit_width+x] = x < piglit_width/2 ? 0.625 : 0.75;
 			}
 		}
 	}
@@ -208,9 +191,12 @@ static enum piglit_result test_drawpixels()
 	/* Draw pixels. */
 	glEnable(GL_DEPTH_TEST);
 	glDepthFunc(GL_ALWAYS);
-	glDrawPixels(BUF_SIZE, BUF_SIZE, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
+	glDrawPixels(piglit_width, piglit_height,
+		     GL_DEPTH_COMPONENT, GL_FLOAT, depth);
 	glDisable(GL_DEPTH_TEST);
 
+	free(depth);
+
 	return compare();
 }
 
@@ -227,11 +213,13 @@ static enum piglit_result test_copy(void)
 	/* Set the upper-right corner to 0x3333 and copy the content to the lower-left one. */
 	piglit_draw_rect_z(-0.5, 0, 0, 1, 1);
 	if (test == BLIT)
-		glBlitFramebufferEXT(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE, BUF_SIZE,
-				     0, 0, BUF_SIZE/2, BUF_SIZE/2,
+		glBlitFramebufferEXT(piglit_width/2+1, piglit_height/2+1,
+				     piglit_width, piglit_height,
+				     0, 0, piglit_width/2, piglit_height/2,
 				     GL_DEPTH_BUFFER_BIT, GL_NEAREST);
 	else
-		glCopyPixels(BUF_SIZE/2+1, BUF_SIZE/2+1, BUF_SIZE/2, BUF_SIZE/2, GL_DEPTH);
+		glCopyPixels(piglit_width/2+1, piglit_height/2+1,
+			     piglit_width/2, piglit_height/2, GL_DEPTH);
 
 	/* Initialize the other corners. */
 	piglit_draw_rect_z(-0.25, 0, -1, 1, 1);
@@ -260,14 +248,14 @@ enum piglit_result piglit_display(void)
 	/* Create the FBO. */
 	glGenRenderbuffersEXT(1, &rb);
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb);
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, f.iformat, BUF_SIZE, BUF_SIZE);
+	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, f.iformat, piglit_width, piglit_height);
 	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
 
 	glGenFramebuffersEXT(1, &fb);
 	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
 	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT,
 				     GL_RENDERBUFFER_EXT, rb);
-	glViewport(0, 0, BUF_SIZE, BUF_SIZE);
+	glViewport(0, 0, piglit_width, piglit_height);
 	glDrawBuffer(GL_NONE);
 	glReadBuffer(GL_NONE);
 	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-- 
1.7.10.4



More information about the Piglit mailing list