aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-08-31 12:36:31 -0700
committerEric Anholt <eric@anholt.net>2010-08-31 15:41:37 -0700
commit99c3ae0b4889af94b98fd8722e4b501764741263 (patch)
tree7791e811b824ec85d9d0131bf825b1656eed788c /tests
parent7fe919561f121a46392ce1f5b1fcc6862fdefbd8 (diff)
glsl-fs-discard-02: Test that early depth writes don't happen with "discard".
Diffstat (limited to 'tests')
-rw-r--r--tests/all.tests1
-rw-r--r--tests/shaders/CMakeLists.txt1
-rw-r--r--tests/shaders/glsl-fs-discard-02.c120
-rw-r--r--tests/util/piglit-util.c33
-rw-r--r--tests/util/piglit-util.h1
5 files changed, 156 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests
index e5aa0688..bab2262f 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -275,6 +275,7 @@ add_shader_generic(shaders, 'glsl-fs-cross')
add_shader_generic(shaders, 'glsl-fs-cross-2')
add_shader_generic(shaders, 'glsl-fs-cross-3')
add_shader_generic(shaders, 'glsl-fs-discard-01')
+add_shader_generic(shaders, 'glsl-fs-discard-02')
add_shader_generic(shaders, 'glsl-fs-dot-vec2')
add_shader_generic(shaders, 'glsl-fs-exp')
add_plain_test(shaders, 'glsl-fs-exp2')
diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt
index 6452bc79..5d25ead6 100644
--- a/tests/shaders/CMakeLists.txt
+++ b/tests/shaders/CMakeLists.txt
@@ -108,6 +108,7 @@ add_executable (vpfp-generic vpfp-generic.cpp)
add_executable (vp-max-array vp-max-array.c)
add_executable (glsl-derivs glsl-derivs.c)
add_executable (glsl-deriv-varyings glsl-deriv-varyings.c)
+add_executable (glsl-fs-discard-02 glsl-fs-discard-02.c)
add_executable (glsl-fwidth glsl-fwidth.c)
add_executable (glsl-lod-bias glsl-lod-bias.c)
add_executable (glsl-preprocessor-comments glsl-preprocessor-comments.c)
diff --git a/tests/shaders/glsl-fs-discard-02.c b/tests/shaders/glsl-fs-discard-02.c
new file mode 100644
index 00000000..0ef6282e
--- /dev/null
+++ b/tests/shaders/glsl-fs-discard-02.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright © 2009 Marek Olšák (maraeo@gmail.com)
+ * Copyright © 2010 Intel Corporation
+ *
+ * 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.
+ *
+ * Authors:
+ * Marek Olšák <mareao@gmail.com>
+ * Eric Anholt <eric@anholt.net>
+ *
+ */
+
+/** @file glsl-fs-discard-02.c
+ *
+ * Tests that discarding fragments doesn't let early depth writes through.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH;
+
+static char vs_code[] =
+ "varying vec4 color;"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = gl_Vertex;\n"
+ " if (gl_Vertex.z > 0.75)\n"
+ " color = vec4(1.0, 0.0, 0.0, gl_Vertex.z);\n"
+ " else if (gl_Vertex.z > 0.25)\n"
+ " color = vec4(0.0, 1.0, 0.0, gl_Vertex.z);\n"
+ " else\n"
+ " color = vec4(0.0, 0.0, 1.0, gl_Vertex.z);\n"
+ "}\n";
+
+static char fs_code[] =
+ "varying vec4 color;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " if (color.w < 0.25)\n"
+ " discard;"
+ " gl_FragColor = vec4(color.xyz, 0.0);\n"
+ "}\n";
+
+static GLuint setup_shaders()
+{
+ GLuint vs, fs, prog;
+
+ vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
+ fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
+ prog = piglit_link_simple_program(vs, fs);
+
+ glUseProgram(prog);
+ return prog;
+}
+
+static GLboolean test()
+{
+ GLint prog, location;
+ GLboolean pass = GL_TRUE;
+ int i;
+ float red[4] = {1, 0, 0, 0};
+ float green[4] = {0, 1, 0, 0};
+
+ prog = setup_shaders();
+
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ glDepthFunc(GL_LEQUAL);
+ glEnable(GL_DEPTH_TEST);
+
+ piglit_draw_rect_z(1.0, -1, -1, 2, 2); // red
+ piglit_draw_rect_z(0.0, -1, -1, 2, 2); // discard
+ piglit_draw_rect_z(0.5, -1, -1, 2, 2); // green
+
+ assert(glGetError() == 0);
+
+ piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
+
+ return pass;
+}
+
+enum piglit_result piglit_display(void)
+{
+ GLboolean pass;
+
+ pass = test();
+
+ glutSwapBuffers();
+
+ return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
+}
+
+void piglit_init(int argc, char **argv)
+{
+ if (!GLEW_VERSION_2_0) {
+ printf("Requires OpenGL 2.0\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+}
+
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 962d76bb..ec0488ab 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -630,6 +630,39 @@ piglit_draw_rect(float x, float y, float w, float h)
}
/**
+ * Convenience function to draw an axis-aligned rectangle.
+ */
+GLvoid
+piglit_draw_rect_z(float z, float x, float y, float w, float h)
+{
+ float verts[4][4];
+
+ verts[0][0] = x;
+ verts[0][1] = y;
+ verts[0][2] = z;
+ verts[0][3] = 1.0;
+ verts[1][0] = x + w;
+ verts[1][1] = y;
+ verts[1][2] = z;
+ verts[1][3] = 1.0;
+ verts[2][0] = x + w;
+ verts[2][1] = y + h;
+ verts[2][2] = z;
+ verts[2][3] = 1.0;
+ verts[3][0] = x;
+ verts[3][1] = y + h;
+ verts[3][2] = z;
+ verts[3][3] = 1.0;
+
+ glVertexPointer(4, GL_FLOAT, 0, verts);
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ glDrawArrays(GL_QUADS, 0, 4);
+
+ glDisableClientState(GL_VERTEX_ARRAY);
+}
+
+/**
* Convenience function to draw an axis-aligned rectangle
* with texture coordinates.
*/
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index ebaf5bd4..1873a6e9 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -100,6 +100,7 @@ GLuint piglit_compile_shader_text(GLenum target, const char *text);
GLboolean piglit_link_check_status(GLint prog);
GLint piglit_link_simple_program(GLint vs, GLint fs);
GLvoid piglit_draw_rect(float x, float y, float w, float h);
+GLvoid piglit_draw_rect_z(float z, float x, float y, float w, float h);
GLvoid piglit_draw_rect_tex(float x, float y, float w, float h,
float tx, float ty, float tw, float th);
void piglit_escape_exit_key(unsigned char key, int x, int y);