aboutsummaryrefslogtreecommitdiff
path: root/tests/hiz/hiz-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/hiz/hiz-util.c')
-rw-r--r--tests/hiz/hiz-util.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/tests/hiz/hiz-util.c b/tests/hiz/hiz-util.c
index 0ef382e1..7c2b9d49 100644
--- a/tests/hiz/hiz-util.c
+++ b/tests/hiz/hiz-util.c
@@ -542,3 +542,132 @@ hiz_run_test_stencil_read_window()
}
/** \} */
+
+bool
+hiz_run_test_depth_stencil_test_fbo(const struct hiz_fbo_options *fbo_options)
+{
+ bool pass = true;
+
+ GLuint fbo = 0;
+ bool has_depth_buffer = fbo_options->depth_format
+ || fbo_options->depth_stencil_format;
+ bool has_stencil_buffer = fbo_options->stencil_format
+ || fbo_options->depth_stencil_format;
+
+ const float dx = piglit_width / 3.0;
+ const float dy = piglit_height / 3.0;
+
+ static const float *expected_colors = NULL;
+
+ static const float *expected_colors_d1s0[9] = {
+ hiz_green,
+ hiz_green,
+ hiz_grey,
+
+ hiz_green,
+ hiz_green,
+ hiz_blue,
+
+ hiz_grey,
+ hiz_blue,
+ hiz_blue,
+ };
+
+ static const float *expected_colors_d0s1[9] = {
+ hiz_green,
+ hiz_green,
+ hiz_grey,
+
+ hiz_green,
+ hiz_blue,
+ hiz_grey,
+
+ hiz_grey,
+ hiz_blue,
+ hiz_grey,
+ };
+
+ static const float *expected_colors_d1s1[9] = {
+ hiz_green,
+ hiz_green,
+ hiz_grey,
+
+ hiz_green,
+ hiz_green,
+ hiz_grey,
+
+ hiz_grey,
+ hiz_blue,
+ hiz_grey,
+ };
+
+ if (has_depth_buffer && !has_stencil_buffer)
+ expected_colors = expected_colors_d1s0;
+ else if (!has_depth_buffer && has_stencil_buffer)
+ expected_colors = expected_colors_d0s1;
+ else if (has_depth_buffer && has_stencil_buffer)
+ expected_colors = expected_colors_d1s1;
+
+ 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);
+
+ /* Set up depth state. */
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LESS);
+ 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);
+ glDepthRange(hiz_clear_z, hiz_clear_z);
+ piglit_draw_rect(0 * dx, 0 * dy, /* x, y */
+ 2 * dx, 3 * dy); /* w, h */
+
+ /* Draw rect 2. */
+ glColor4fv(hiz_green);
+ glDepthRange(hiz_green_z, hiz_green_z);
+ piglit_draw_rect(0 * dx, 0 * dy, /* x, y */
+ 2 * dx, 2 * dy); /* w, h */
+
+ /* Draw rect 3. */
+ glColor4fv(hiz_blue);
+ glDepthRange(hiz_blue_z, hiz_blue_z);
+ piglit_draw_rect(1 * dx, 1 * dy, /* x, y */
+ 2 * dx, 2 * dy); /* w, h */
+
+ assert(!glGetError());
+
+ pass = hiz_probe_color_buffer(expected_colors);
+
+ 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;
+}