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.h"
34 #include "piglit-framework.h"
36 int piglit_width
= 100;
37 int piglit_height
= 200;
38 int piglit_window_mode
= GLUT_RGB
| GLUT_ALPHA
| GLUT_DEPTH
;
41 * Convenience function to draw an axis-aligned rectangle.
44 draw_rect_depth(float x
, float y
, float w
, float h
, float d
)
65 glVertexPointer(4, GL_FLOAT
, 0, verts
);
66 glEnableClientState(GL_VERTEX_ARRAY
);
68 glDrawArrays(GL_QUADS
, 0, 4);
70 glDisableClientState(GL_VERTEX_ARRAY
);
76 GLboolean pass
= GL_TRUE
;
88 const float green
[4] = {0, 1, 0, 0};
89 const float blue
[4] = {0, 0, 1, 0};
91 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
93 glClearColor(0.5, 0.5, 0.5, 0.0);
94 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
96 glColor4f(0.0, 1.0, 0.0, 0.0);
97 glEnable(GL_DEPTH_TEST
);
98 glDepthFunc(GL_ALWAYS
);
99 for (i
= 0; i
< ARRAY_SIZE(funcs
); i
++) {
100 draw_rect_depth(10, 10 + 20 * i
, 10, 10, 0.0);
101 draw_rect_depth(30, 10 + 20 * i
, 10, 10, 0.0);
102 draw_rect_depth(50, 10 + 20 * i
, 10, 10, 0.0);
105 glColor4f(0.0, 0.0, 1.0, 0.0);
106 for (i
= 0; i
< ARRAY_SIZE(funcs
); i
++) {
107 glDepthFunc(funcs
[i
]);
108 draw_rect_depth(10, 10 + 20 * i
, 10, 10, 0.5);
109 draw_rect_depth(30, 10 + 20 * i
, 10, 10, 0.0);
110 draw_rect_depth(50, 10 + 20 * i
, 10, 10, -0.5);
113 for (i
= 0; i
< ARRAY_SIZE(funcs
); i
++) {
114 glDepthFunc(funcs
[i
]);
115 pass
= pass
&& piglit_probe_pixel_rgb(15, 15 + 20 * i
,
116 i
& 1 ? blue
: green
);
117 pass
= pass
&& piglit_probe_pixel_rgb(35, 15 + 20 * i
,
118 i
& 2 ? blue
: green
);
119 pass
= pass
&& piglit_probe_pixel_rgb(55, 15 + 20 * i
,
120 i
& 4 ? blue
: green
);
125 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
128 void piglit_init(int argc
, char**argv
)