2 * Copyright 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Test GL_EXT_frag_depth support in GLSL ES 1.0
26 * We draw overlapping red and green quads. The red quad is at Z=0
27 * while the green quad's fragment depths vary from left to right.
28 * Should see intersecting quads.
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_es_version
= 20;
36 config
.window_visual
= (PIGLIT_GL_VISUAL_RGBA
|
37 PIGLIT_GL_VISUAL_DEPTH
|
38 PIGLIT_GL_VISUAL_DOUBLE
);
39 PIGLIT_GL_TEST_CONFIG_END
42 static const char *vs_source
=
44 "attribute vec4 piglit_vertex;\n"
47 " gl_Position = piglit_vertex; \n"
48 " // Convert z from [-1, 1] to [0, 1] \n"
49 " z = piglit_vertex.x * 0.5 + 0.5; \n"
51 static const char *fs_source
=
53 "#extension GL_EXT_frag_depth : enable \n"
54 "precision mediump float; \n"
56 "uniform vec4 color;\n"
58 " if (color.g == 1.0) \n"
59 " gl_FragDepthEXT = z; \n"
61 " gl_FragDepthEXT = 0.5; \n"
62 " gl_FragColor = color; \n"
65 static GLuint program
;
71 static const float red
[4] = {1.0, 0.0, 0.0, 1.0};
72 static const float green
[4] = {0.0, 1.0, 0.0, 1.0};
73 int x
= piglit_width
/ 2;
74 int y
= piglit_height
/ 2;
78 glViewport(0, 0, piglit_width
, piglit_height
);
79 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
80 glUseProgram(program
);
81 color_loc
= glGetUniformLocation(program
, "color");
83 glUniform4fv(color_loc
, 1, red
);
84 /* Draw a red rect at z = 0 (will be 0.5 in depth range [0,1]) */
85 piglit_draw_rect(-0.5, -0.5, 1.0, 1.0);
87 /* Draw green rect with variable z = piglit_vertex.x * 0.5 + 0.5 */
88 glUniform4fv(color_loc
, 1, green
);
89 piglit_draw_rect(-0.75, -0.25, 1.5, 0.5);
91 pass
= piglit_probe_pixel_rgba(x
-10, y
, green
) && pass
;
92 pass
= piglit_probe_pixel_rgba(x
+10, y
, red
) && pass
;
94 piglit_present_results();
95 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
100 piglit_init(int argc
, char **argv
)
102 piglit_require_extension("GL_EXT_frag_depth");
103 program
= piglit_build_simple_program(vs_source
, fs_source
);
104 glClearColor(0.25f
, 0.25f
, 0.25f
, 1.0f
);
105 glEnable(GL_DEPTH_TEST
);