2 * Copyright © 2009 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
24 * Eric Anholt <eric@anholt.net>
30 * Tests that glDepthFunc()'s various modes all work correctly.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 10;
39 config
.window_height
= 200;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DEPTH
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
46 * Convenience function to draw an axis-aligned rectangle.
49 draw_rect_depth(float x
, float y
, float w
, float h
, float d
)
70 glVertexPointer(4, GL_FLOAT
, 0, verts
);
71 glEnableClientState(GL_VERTEX_ARRAY
);
73 glDrawArrays(GL_QUADS
, 0, 4);
75 glDisableClientState(GL_VERTEX_ARRAY
);
81 GLboolean pass
= GL_TRUE
;
93 const float green
[4] = {0, 1, 0, 0};
94 const float blue
[4] = {0, 0, 1, 0};
96 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
98 glClearColor(0.5, 0.5, 0.5, 0.0);
99 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
101 glColor4f(0.0, 1.0, 0.0, 0.0);
102 glEnable(GL_DEPTH_TEST
);
103 glDepthFunc(GL_ALWAYS
);
104 for (i
= 0; i
< ARRAY_SIZE(funcs
); i
++) {
105 draw_rect_depth(10, 10 + 20 * i
, 10, 10, 0.0);
106 draw_rect_depth(30, 10 + 20 * i
, 10, 10, 0.0);
107 draw_rect_depth(50, 10 + 20 * i
, 10, 10, 0.0);
110 glColor4f(0.0, 0.0, 1.0, 0.0);
111 for (i
= 0; i
< ARRAY_SIZE(funcs
); i
++) {
112 glDepthFunc(funcs
[i
]);
113 draw_rect_depth(10, 10 + 20 * i
, 10, 10, 0.5);
114 draw_rect_depth(30, 10 + 20 * i
, 10, 10, 0.0);
115 draw_rect_depth(50, 10 + 20 * i
, 10, 10, -0.5);
118 for (i
= 0; i
< ARRAY_SIZE(funcs
); i
++) {
119 glDepthFunc(funcs
[i
]);
120 pass
= pass
&& piglit_probe_pixel_rgb(15, 15 + 20 * i
,
121 i
& 1 ? blue
: green
);
122 pass
= pass
&& piglit_probe_pixel_rgb(35, 15 + 20 * i
,
123 i
& 2 ? blue
: green
);
124 pass
= pass
&& piglit_probe_pixel_rgb(55, 15 + 20 * i
,
125 i
& 4 ? blue
: green
);
128 piglit_present_results();
130 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
133 void piglit_init(int argc
, char**argv
)