--- tests/all.tests | 1 + tests/general/CMakeLists.gl.txt | 1 + tests/general/readpix-z.c | 113 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 tests/general/readpix-z.c
diff --git a/tests/all.tests b/tests/all.tests index 9d6be77..68270f4 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -315,6 +315,7 @@ add_plain_test(general, 'provoking-vertex') add_plain_test(general, 'oes-read-format') add_plain_test(general, 'quad-invariance') add_plain_test(general, 'read-front') +add_plain_test(general, 'readpix-z') add_plain_test(general, 'roundmode-getintegerv') add_plain_test(general, 'roundmode-pixelstore') add_plain_test(general, 'scissor-bitmap') diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt index b2213c4..2318709 100644 --- a/tests/general/CMakeLists.gl.txt +++ b/tests/general/CMakeLists.gl.txt @@ -90,6 +90,7 @@ piglit_add_executable (primitive-restart primitive-restart.c) piglit_add_executable (provoking-vertex provoking-vertex.c) piglit_add_executable (oes-read-format oes-read-format.c) piglit_add_executable (read-front read-front.c) +piglit_add_executable (readpix-z readpix-z.c) IF (NOT MSVC) piglit_add_executable (roundmode-getintegerv roundmode-getintegerv.c) ENDIF (NOT MSVC) diff --git a/tests/general/readpix-z.c b/tests/general/readpix-z.c new file mode 100644 index 0000000..5186768 --- /dev/null +++ b/tests/general/readpix-z.c @@ -0,0 +1,113 @@ +/* + * Copyright 2012 VMware, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * Test glReadPixels(GL_DEPTH_COMPONENT) + * Brian Paul + * June 2012 + */ + +#include "piglit-util.h" + +int piglit_width = 200, piglit_height = 200; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH; + + + +static void +draw_z_gradient(GLfloat zLeft, GLfloat zRight) +{ + GLfloat verts[4][3]; + + verts[0][0] = -1.0; verts[0][1] = -1.0; verts[0][2] = zLeft; + verts[1][0] = 1.0; verts[1][1] = -1.0; verts[1][2] = zRight; + verts[2][0] = 1.0; verts[2][1] = 1.0; verts[2][2] = zRight; + verts[3][0] = -1.0; verts[3][1] = 1.0; verts[3][2] = zLeft; + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_FLOAT, 0, verts); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); +} + + +enum piglit_result +piglit_display(void) +{ + const GLfloat epsilon = 2.0 / piglit_width; + GLfloat *buf; + bool pass = true; + int pos, i; + + /* draw full-window quad with z increasing left to right */ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); + draw_z_gradient(-1.0, 1.0); + + buf = (GLfloat *) malloc(piglit_width * sizeof(GLfloat)); + + glReadPixels(0, piglit_height / 2, piglit_width, 1, + GL_DEPTH_COMPONENT, GL_FLOAT, buf); + + pos = 0; + if (fabs(buf[pos] - 0.0) > epsilon) { + printf("Left-most Z value should be close to 0.0, found %f\n", + buf[pos]); + pass = false; + } + + pos = piglit_width / 2; + if (fabs(buf[pos] - 0.5) > epsilon) { + printf("Middle Z value should be close to 0.5, found %f\n", + buf[pos]); + pass = false; + } + + pos = piglit_width - 1; + if (fabs(buf[pos] - 1.0) > epsilon) { + printf("Left-most Z value should be close to 1.0, found %f\n", + buf[pos]); + pass = false; + } + + /* check for monotonicity */ + for (i = 1; i < piglit_width; i++) { + if (buf[i - 1] > buf[i]) { + printf("Z values aren't increasing from left to right. buf[%d]=%f > buf[%d]=%f\n", + i-1, buf[i-1], i, buf[i]); + pass = false; + break; + } + } + + free(buf); + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + + +void +piglit_init(int argc, char **argv) +{ +} -- 1.7.3.4 _______________________________________________ Piglit mailing list Piglit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/piglit