[Piglit] [PATCH 3/3] depthstencil-render-miplevels: Present the results in non-auto mode.

Eric Anholt eric at anholt.net
Tue Feb 26 12:39:33 PST 2013


I tried to make the presentation be the data that was originally
probed -- there's a second readpixels that's unfortunately, but we do
use separate textures so that any workaround relayouts of the probed
textures don't get tweaked in the process of displaying.
---
 tests/texturing/depthstencil-render-miplevels.cpp |  105 ++++++++++++++++++++-
 1 file changed, 102 insertions(+), 3 deletions(-)

diff --git a/tests/texturing/depthstencil-render-miplevels.cpp b/tests/texturing/depthstencil-render-miplevels.cpp
index b41fea8..2ffe07d 100644
--- a/tests/texturing/depthstencil-render-miplevels.cpp
+++ b/tests/texturing/depthstencil-render-miplevels.cpp
@@ -90,8 +90,8 @@ PIGLIT_GL_TEST_CONFIG_BEGIN
 
 	config.supports_gl_compat_version = 10;
 
-	config.window_width = 16;
-	config.window_height = 16;
+	config.window_width = 512;
+	config.window_height = 512;
 	config.window_visual = PIGLIT_GL_VISUAL_RGBA;
 
 PIGLIT_GL_TEST_CONFIG_END
@@ -109,7 +109,8 @@ bool attach_stencil_first = false;
 GLenum depth_format;
 int miplevel0_size;
 int max_miplevel;
-
+float **depth_miplevel_data;
+uint8_t **stencil_miplevel_data;
 
 /**
  * Check if the given depth/stencil/rgba texture internal format is supported.
@@ -260,6 +261,9 @@ populate_miplevel(int level)
 /**
  * Test that every pixel in the depth and stencil buffers (if present)
  * is equal to the value set by populate_miplevel.
+ *
+ * If we're going to later render our results to the screen for
+ * debugging, then save off a copy of the data we read now.
  */
 bool
 test_miplevel(int level)
@@ -272,6 +276,14 @@ test_miplevel(int level)
 		printf("Probing miplevel %d depth\n", level);
 		pass = piglit_probe_rect_depth(0, 0, dim, dim, float_value)
 			&& pass;
+
+		if (!piglit_automatic) {
+			depth_miplevel_data[level] =
+				(float *)malloc(4 * dim * dim);
+			glReadPixels(0, 0, dim, dim,
+				     GL_DEPTH_COMPONENT, GL_FLOAT,
+				     depth_miplevel_data[level]);
+		}
 	}
 
 	if (attach_stencil) {
@@ -279,6 +291,14 @@ test_miplevel(int level)
 		pass = piglit_probe_rect_stencil(0, 0, dim, dim,
 						 stencil_for_level(level))
 			&& pass;
+
+		if (!piglit_automatic) {
+			stencil_miplevel_data[level] =
+				(uint8_t *)malloc(dim * dim);
+			glReadPixels(0, 0, dim, dim,
+				     GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
+				     stencil_miplevel_data[level]);
+		}
 	}
 
 	return pass;
@@ -332,6 +352,9 @@ piglit_init(int argc, char **argv)
 		while ((miplevel0_size >> (max_miplevel + 1)) > 0)
 			++max_miplevel;
 	}
+	depth_miplevel_data = (float **)calloc(max_miplevel, sizeof(float *));
+	stencil_miplevel_data = (uint8_t **)calloc(max_miplevel,
+						   sizeof(uint8_t *));
 
 	/* argv[2]: buffer combination */
 	if (strcmp(argv[2], "s=z24_s8") == 0) {
@@ -426,6 +449,79 @@ piglit_init(int argc, char **argv)
 	}
 }
 
+static void
+render_tex_to_screen(GLuint tex, int x, int y)
+{
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glEnable(GL_TEXTURE_2D);
+
+	for (int level = 0; level <= max_miplevel; ++level) {
+		int dim = miplevel0_size >> level;
+
+		piglit_draw_rect_tex(x, y, dim, dim,
+				     0, 0, 1, 1);
+
+		y += dim + 1;
+	}
+}
+
+/**
+ * Presents the results of the rendering on the screen.
+ */
+static void
+render_results_to_screen()
+{
+	GLuint tex;
+
+	printf("\n");
+	printf("Depth is on the left, stencil is on the right.\n");
+	printf("Colors should proceed from nearly-black to nearly-red.\n");
+
+	piglit_ortho_projection(piglit_width, piglit_height, false);
+
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+	glClearColor(0.5, 0.5, 0.5, 0.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+
+	if (attach_depth) {
+		for (int level = 0; level <= max_miplevel; ++level) {
+			int dim = miplevel0_size >> level;
+
+			glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA,
+				     dim, dim,
+				     0,
+				     GL_RED, GL_FLOAT,
+				     depth_miplevel_data[level]);
+			if (!piglit_check_gl_error(GL_NO_ERROR))
+				piglit_report_result(PIGLIT_FAIL);
+		}
+
+		render_tex_to_screen(tex, 0, 1);
+	}
+
+
+	if (attach_stencil) {
+		for (int level = 0; level <= max_miplevel; ++level) {
+			int dim = miplevel0_size >> level;
+
+			glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA,
+				     dim, dim,
+				     0,
+				     GL_RED, GL_UNSIGNED_BYTE,
+				     stencil_miplevel_data[level]);
+			if (!piglit_check_gl_error(GL_NO_ERROR))
+				piglit_report_result(PIGLIT_FAIL);
+		}
+
+		render_tex_to_screen(tex, miplevel0_size + 10, 1);
+	}
+
+	piglit_present_results();
+}
+
 extern "C" enum piglit_result
 piglit_display()
 {
@@ -467,6 +563,9 @@ piglit_display()
 		pass = test_miplevel(level) && pass;
 	}
 
+	if (!piglit_automatic)
+		render_results_to_screen();
+
 	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
 }
 
-- 
1.7.10.4



More information about the Piglit mailing list