summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>2011-03-10 22:26:16 +0100
committerMarek Olšák <maraeo@gmail.com>2011-03-10 22:52:37 +0100
commitccb8f39646f477a41d451a1df0095d9ca2ebcc22 (patch)
treebff20d54fb6718f9c565a41ef0167be06ab85fc9
parentc9365dcda8f780089066392c81328ea8d68b6fb0 (diff)
early-z: add test to check for early depth testing bugs
If early fragment tests cause the depth buffer to be also updated before the fragment shader is run, it has to be disabled whenever alpha testing is enabled or discard is used.
-rw-r--r--tests/all.tests1
-rw-r--r--tests/general/CMakeLists.gl.txt1
-rw-r--r--tests/general/early-z.c148
3 files changed, 150 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests
index a3ec4f153..b285b1e14 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -187,6 +187,7 @@ add_plain_test(general, 'framebuffer-srgb')
add_plain_test(general, 'geterror-invalid-enum')
add_plain_test(general, 'geterror-inside-begin')
add_plain_test(general, 'hiz')
+add_plain_test(general, 'early-z')
add_plain_test(general, 'isbufferobj')
add_plain_test(general, 'line-aa-width')
add_plain_test(general, 'linestipple')
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index be8097af9..55075c77e 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -53,6 +53,7 @@ add_executable (hiz hiz.c)
if (UNIX)
target_link_libraries (hiz m)
endif (UNIX)
+add_executable (early-z early-z.c)
add_executable (isbufferobj isbufferobj.c)
add_executable (linestipple linestipple.c)
add_executable (line-aa-width line-aa-width.c)
diff --git a/tests/general/early-z.c b/tests/general/early-z.c
new file mode 100644
index 000000000..b4f67205d
--- /dev/null
+++ b/tests/general/early-z.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2011 Christoph Bumiller
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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
+ * NON-INFRINGEMENT. IN NO EVENT SHALL VMWARE AND/OR THEIR SUPPLIERS
+ * 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.
+ */
+
+/**
+ * @file
+ * Test for bugs with early depth testing and early depth update.
+ */
+
+#include "piglit-util.h"
+
+
+int piglit_width = 128;
+int piglit_height = 128;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH;
+
+static const char *fpFragDepthText =
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4(gl_Color.rgb, 1.0); \n"
+ " gl_FragDepth = 0.9; \n"
+ "} \n";
+
+static const char *fpDiscardText =
+ "void main() \n"
+ "{ \n"
+ " if (gl_Color.r > 0.25) \n"
+ " discard; \n"
+ " gl_FragColor = vec4(gl_Color.rgb, 1.0); \n"
+ "} \n";
+
+static const char *fpAlphaText =
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4(gl_Color.rgb, 0.0); \n"
+ "} \n";
+
+
+static GLuint shader[3];
+static GLuint program[3];
+
+static void quad(const GLfloat z, uint32_t colour)
+{
+ glColor3ub(colour & 0xff, (colour >> 8) & 0xff, (colour >> 16) & 0xff);
+ glBegin(GL_QUADS);
+ glVertex3f(-1.0f, -1.0f, z);
+ glVertex3f(-1.0f, 1.0f, z);
+ glVertex3f( 1.0f, 1.0f, z);
+ glVertex3f( 1.0f, -1.0f, z);
+ glEnd();
+}
+
+static GLboolean
+test_early_depth(void)
+{
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClearDepth(1.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_LESS);
+
+ /* 1. (blue) depth should be adjusted to 0.9 by the FP */
+ glUseProgram(program[0]);
+ quad(0.3, 0xff0000);
+
+ /* 2. (red) should be discarded, no depth value written */
+ glUseProgram(program[1]);
+ quad(0.2, 0x0000ff);
+
+ /* 3. (white) should be discarded by the alpha test, no depth written */
+ glUseProgram(program[2]);
+ glEnable(GL_ALPHA_TEST);
+ glAlphaFunc(GL_GREATER, 0.5f);
+ quad(0.1, 0xffffff);
+ glDisable(GL_ALPHA_TEST);
+
+ /* 4. (green) should be drawn because depth is still 0.9 */
+ quad(0.7, 0x00ff00);
+
+ {
+ const GLfloat color[4] = { 0.0f, 1.0f, 0.0f, 0.0f };
+ GLint pos[4];
+
+ /* use glRasterPos to determine where to read a sample pixel */
+ glRasterPos2f(0.0f, 0.0f);
+ glGetIntegerv(GL_CURRENT_RASTER_POSITION, pos);
+
+ if (!piglit_probe_pixel_rgba(pos[0], pos[1], color)) {
+ glutSwapBuffers();
+ return GL_FALSE;
+ }
+ }
+
+ glutSwapBuffers();
+
+ return GL_TRUE;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ if (!test_early_depth())
+ return PIGLIT_FAILURE;
+
+ return PIGLIT_SUCCESS;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ int i;
+
+ shader[0] = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fpFragDepthText);
+ assert(shader[0]);
+
+ shader[1] = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fpDiscardText);
+ assert(shader[1]);
+
+ shader[2] = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fpAlphaText);
+ assert(shader[2]);
+
+ for (i = 0; i < 3; ++i)
+ program[i] = piglit_link_simple_program(shader[i], 0);
+}