Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / glsl-fs-discard-02.c
blob0ef6282e75145353578a7c31a89c4c83535d4c37
1 /*
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
14 * Software.
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
22 * IN THE SOFTWARE.
24 * Authors:
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[] =
41 "varying vec4 color;"
42 "\n"
43 "void main()\n"
44 "{\n"
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"
50 " else\n"
51 " color = vec4(0.0, 0.0, 1.0, gl_Vertex.z);\n"
52 "}\n";
54 static char fs_code[] =
55 "varying vec4 color;\n"
56 "\n"
57 "void main()\n"
58 "{\n"
59 " if (color.w < 0.25)\n"
60 " discard;"
61 " gl_FragColor = vec4(color.xyz, 0.0);\n"
62 "}\n";
64 static GLuint setup_shaders()
66 GLuint vs, fs, prog;
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);
72 glUseProgram(prog);
73 return prog;
76 static GLboolean test()
78 GLint prog, location;
79 GLboolean pass = GL_TRUE;
80 int i;
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);
99 return pass;
102 enum piglit_result piglit_display(void)
104 GLboolean pass;
106 pass = test();
108 glutSwapBuffers();
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);