[Piglit] [PATCH 3/3] hiz: Add tests for stencil buffer reads

Chad Versace chad at chad-versace.us
Thu May 19 07:55:15 PDT 2011


Add the following tests:
    hiz-stencil-read-fbo-d0-s8.c
    hiz-stencil-read-fbo-d24-s8.c
    hiz-stencil-read-fbo-d24s8.c
    hiz-stencil-read-window-depth0.c
    hiz-stencil-read-window-depth1.c

Signed-off-by: Chad Versace <chad.versace at intel.com>
---
 tests/all.tests             |    5 ++
 tests/hiz/CMakeLists.gl.txt |    5 ++
 tests/hiz/hiz-util.c        |  136 +++++++++++++++++++++++++++++++++++++++++++
 tests/hiz/hiz-util.h        |   32 ++++++++++-
 4 files changed, 176 insertions(+), 2 deletions(-)

diff --git a/tests/all.tests b/tests/all.tests
index 927e7cc..94f43b8 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1043,6 +1043,11 @@ add_plain_test(hiz, 'hiz-depth-test-fbo-d24-s8')
 add_plain_test(hiz, 'hiz-depth-test-fbo-d24s8')
 add_plain_test(hiz, 'hiz-depth-test-window-stencil0')
 add_plain_test(hiz, 'hiz-depth-test-window-stencil1')
+add_plain_test(hiz, 'hiz-stencil-read-fbo-d0-s8')
+add_plain_test(hiz, 'hiz-stencil-read-fbo-d24-s8')
+add_plain_test(hiz, 'hiz-stencil-read-fbo-d24s8')
+add_plain_test(hiz, 'hiz-stencil-read-window-depth0')
+add_plain_test(hiz, 'hiz-stencil-read-window-depth1')
 add_plain_test(hiz, 'hiz-stencil-test-fbo-d0-s8')
 add_plain_test(hiz, 'hiz-stencil-test-fbo-d24-s8')
 add_plain_test(hiz, 'hiz-stencil-test-fbo-d24s8')
diff --git a/tests/hiz/CMakeLists.gl.txt b/tests/hiz/CMakeLists.gl.txt
index d9ba5b2..98222c5 100644
--- a/tests/hiz/CMakeLists.gl.txt
+++ b/tests/hiz/CMakeLists.gl.txt
@@ -29,6 +29,11 @@ add_executable(hiz-depth-test-fbo-d24-s8 hiz-depth-test-fbo-d24-s8.c)
 add_executable(hiz-depth-test-fbo-d24s8 hiz-depth-test-fbo-d24s8.c)
 add_executable(hiz-depth-test-window-stencil0 hiz-depth-test-window-stencil0.c)
 add_executable(hiz-depth-test-window-stencil1 hiz-depth-test-window-stencil1.c)
+add_executable(hiz-stencil-read-fbo-d0-s8 hiz-stencil-read-fbo-d0-s8.c)
+add_executable(hiz-stencil-read-fbo-d24-s8 hiz-stencil-read-fbo-d24-s8.c)
+add_executable(hiz-stencil-read-fbo-d24s8 hiz-stencil-read-fbo-d24s8.c)
+add_executable(hiz-stencil-read-window-depth0 hiz-stencil-read-window-depth0.c)
+add_executable(hiz-stencil-read-window-depth1 hiz-stencil-read-window-depth1.c)
 add_executable(hiz-stencil-test-fbo-d0-s8 hiz-stencil-test-fbo-d0-s8.c)
 add_executable(hiz-stencil-test-fbo-d24-s8 hiz-stencil-test-fbo-d24-s8.c)
 add_executable(hiz-stencil-test-fbo-d24s8 hiz-stencil-test-fbo-d24s8.c)
diff --git a/tests/hiz/hiz-util.c b/tests/hiz/hiz-util.c
index 60df8c9..0ef382e 100644
--- a/tests/hiz/hiz-util.c
+++ b/tests/hiz/hiz-util.c
@@ -64,6 +64,12 @@ hiz_probe_depth_buffer(const float expected_depths[])
 	hiz_probe_common(piglit_probe_rect_depth, expected_depths);
 }
 
+bool
+hiz_probe_stencil_buffer(const unsigned expected_stencil[])
+{
+	hiz_probe_common(piglit_probe_rect_stencil, expected_stencil);
+}
+
 
 GLuint
 hiz_make_fbo(const struct hiz_fbo_options *options)
@@ -406,3 +412,133 @@ hiz_run_test_stencil_test_window()
 }
 
 /** \} */
+
+/* ------------------------------------------------------------------------ */
+
+/**
+ * \name hiz_run_stencil_read utilties
+ *
+ * Utilities for testing the reading of the stencil buffer.
+ *
+ * \{
+ */
+
+/**
+ * Common functionality needed by hiz_run_test_stencil_read_fbo() and
+ * hiz_run_test_stencil_read_window().
+ */
+static bool
+hiz_run_test_stencil_read_common()
+{
+	static const float *expected_colors[9] = {
+		hiz_green,
+		hiz_green,
+		hiz_grey,
+
+		hiz_green,
+		hiz_blue,
+		hiz_grey,
+
+		hiz_grey,
+		hiz_blue,
+		hiz_grey,
+	};
+
+	static const unsigned expected_stencil[9] = {
+		5,
+		5,
+		3,
+
+		5,
+		6,
+		4,
+
+		4,
+		5,
+		4,
+	};
+
+	const float dx = piglit_width / 3.0;
+	const float dy = piglit_height / 3.0;
+
+	/* Set up depth state. */
+	glDisable(GL_DEPTH_TEST);
+	glClearDepth(hiz_clear_z);
+
+	/* Set up stencil state. */
+	glEnable(GL_STENCIL_TEST);
+	glClearStencil(3); /* 3 is a good canary. */
+	glStencilFunc(GL_LESS, 3, ~0);
+	glStencilOp(GL_INCR, GL_INCR, GL_INCR);
+
+	glClearColor(hiz_grey[0], hiz_grey[1], hiz_grey[2], hiz_grey[3]);
+	glClear(GL_COLOR_BUFFER_BIT
+		| GL_DEPTH_BUFFER_BIT
+		| GL_STENCIL_BUFFER_BIT);
+
+	glViewport(0, 0, piglit_width, piglit_height);
+	piglit_ortho_projection(piglit_width, piglit_height, false);
+
+	/* Draw rect 1. */
+	glColor4fv(hiz_grey);
+	piglit_draw_rect(0 * dx, 0 * dy, /* x, y */
+			 2 * dx, 3 * dy); /* w, h */
+
+	/* Draw rect 2. */
+	glColor4fv(hiz_green);
+	piglit_draw_rect(0 * dx, 0 * dy,  /* x, y */
+			 2 * dx, 2 * dy); /* w, h */
+
+	/* Draw rect 3. */
+	glColor4fv(hiz_blue);
+	piglit_draw_rect(1 * dx, 1 * dy,   /* x, y */
+		         2 * dx, 2 * dy);  /* w, h */
+
+	assert(!glGetError());
+
+	if (!hiz_probe_color_buffer(expected_colors))
+		return false;
+	return hiz_probe_stencil_buffer(expected_stencil);
+}
+
+bool
+hiz_run_test_stencil_read_fbo(const struct hiz_fbo_options *fbo_options)
+{
+	bool pass = true;
+	GLuint fbo = 0;
+
+	piglit_require_extension("GL_ARB_framebuffer_object");
+
+	/* Create and bind FBO. */
+	fbo = hiz_make_fbo(fbo_options);
+	assert(fbo != 0);
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+	glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
+
+	pass = hiz_run_test_stencil_read_common();
+
+	if (!piglit_automatic) {
+		/* Blit the FBO to the window FB so we can see the results. */
+		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+		glBlitFramebuffer(0, 0, piglit_width, piglit_height,
+			          0, 0, piglit_width, piglit_height,
+			          GL_COLOR_BUFFER_BIT, GL_NEAREST);
+		glutSwapBuffers();
+		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
+	}
+
+	hiz_delete_fbo(fbo);
+
+	return pass;
+}
+
+bool
+hiz_run_test_stencil_read_window()
+{
+	bool pass = hiz_run_test_stencil_read_common();
+	if (!piglit_automatic)
+		glutSwapBuffers();
+	return pass;
+}
+
+/** \} */
diff --git a/tests/hiz/hiz-util.h b/tests/hiz/hiz-util.h
index 7b95f1f..ac8c621 100644
--- a/tests/hiz/hiz-util.h
+++ b/tests/hiz/hiz-util.h
@@ -71,6 +71,14 @@ bool hiz_probe_color_buffer(const float *expected_colors[]);
  */
 bool hiz_probe_depth_buffer(const float expected_depths[]);
 
+/**
+ * \brief Probe the stencil buffer.
+ * \param expected_stencil Array of 9 ints.
+ * \return True if all probes pass.
+ * \see hiz_probe_color_buffer()
+ */
+bool hiz_probe_stencil_buffer(const unsigned expected_stencil[]);
+
 GLuint hiz_make_fbo(const struct hiz_fbo_options *options);
 
 /**
@@ -111,11 +119,31 @@ bool hiz_run_test_depth_test_window();
 bool hiz_run_test_stencil_test_fbo(const struct hiz_fbo_options *options);
 
 /**
- * Check that stencil tests work correctly when rendering to the window
+ * Check that stencil testing works correctly when rendering to the window
  * framebuffer.
  *
- * \param options Perform the test with an FBO with the given formats.
  * \return True if test passed.
  * \see hiz_run_test_stencil_test_fbo()
  */
 bool hiz_run_test_stencil_test_window();
+
+/**
+ * \brief Test reading the stencil buffer of an FBO.
+ *
+ * First, probe the color buffer to check that stencil testing worked as
+ * expected. If it did not, then immediately report test failure and do not
+ * probe the stencil buffer. If stencil testing misbehaved, we cannot expect
+ * the stencil buffer to hold the expected values.
+ *
+ * \param options Perform the test with an FBO with the given formats.
+ * \return True if test passed.
+ */
+bool hiz_run_test_stencil_read_fbo(const struct hiz_fbo_options *options);
+
+/**
+ * \brief Test reading the stencil buffer of the window framebuffer.
+ *
+ * \return True if test passed.
+ * \see hiz_run_test_stencil_read_fbo()
+ */
+bool hiz_run_test_stencil_read_window();
-- 
1.7.5.1



More information about the Piglit mailing list