2 * Copyright © 2009 Marek Olšák (maraeo@gmail.com)
3 * Copyright © 2010 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Marek Olšák <mareao@gmail.com>
26 * Eric Anholt <eric@anholt.net>
30 /** @file glsl-fs-discard-02.c
32 * Tests that discarding fragments doesn't let early depth writes through.
35 #include "piglit-util.h"
37 int piglit_width
= 100, piglit_height
= 100;
38 int piglit_window_mode
= GLUT_RGB
| GLUT_ALPHA
| GLUT_DOUBLE
| GLUT_DEPTH
;
40 static char vs_code
[] =
45 " gl_Position = gl_Vertex;\n"
46 " if (gl_Vertex.z > 0.75)\n"
47 " color = vec4(1.0, 0.0, 0.0, gl_Vertex.z);\n"
48 " else if (gl_Vertex.z > 0.25)\n"
49 " color = vec4(0.0, 1.0, 0.0, gl_Vertex.z);\n"
51 " color = vec4(0.0, 0.0, 1.0, gl_Vertex.z);\n"
54 static char fs_code
[] =
55 "varying vec4 color;\n"
59 " if (color.w < 0.25)\n"
61 " gl_FragColor = vec4(color.xyz, 0.0);\n"
64 static GLuint
setup_shaders()
68 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_code
);
69 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fs_code
);
70 prog
= piglit_link_simple_program(vs
, fs
);
76 static GLboolean
test()
79 GLboolean pass
= GL_TRUE
;
81 float red
[4] = {1, 0, 0, 0};
82 float green
[4] = {0, 1, 0, 0};
84 prog
= setup_shaders();
86 glClear(GL_DEPTH_BUFFER_BIT
);
88 glDepthFunc(GL_LEQUAL
);
89 glEnable(GL_DEPTH_TEST
);
91 piglit_draw_rect_z(1.0, -1, -1, 2, 2); // red
92 piglit_draw_rect_z(0.0, -1, -1, 2, 2); // discard
93 piglit_draw_rect_z(0.5, -1, -1, 2, 2); // green
95 assert(glGetError() == 0);
97 piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, green
);
102 enum piglit_result
piglit_display(void)
110 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
113 void piglit_init(int argc
, char **argv
)
115 if (!GLEW_VERSION_2_0
) {
116 printf("Requires OpenGL 2.0\n");
117 piglit_report_result(PIGLIT_SKIP
);