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
21 * DEALINGS IN THE SOFTWARE.
24 * Eric Anholt <eric@anholt.net>
27 /** @file depth_clamp.c
28 * Tests ARB_depth_clamp functionality by drawing side-by-side triangles,
29 * lines, points, and raster images that go behind the near plane, and
30 * testing that when DEPTH_CLAMP is enabled they get rasterized as they should.
32 * An extension of this test would be to test that the depth values are
33 * correctly clamped to the near/far plane, not just unclipped, and to test
34 * the same operations against the far plane.
37 #include "piglit-util.h"
39 int piglit_width
= 100, piglit_height
= 150;
40 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
;
42 /* In case the headers have the old enum name but not the new */
43 #ifndef GL_DEPTH_CLAMP
44 #define GL_DEPTH_CLAMP GL_DEPTH_CLAMP_NV
48 piglit_init(int argc
, char **argv
)
50 piglit_require_extension("GL_ARB_depth_clamp");
52 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
58 GLboolean pass
= GL_TRUE
;
59 float white
[3] = {1.0, 1.0, 1.0};
60 float clear
[3] = {0.0, 0.0, 0.0};
61 float white_rect
[20 * 20 * 3];
64 for (i
= 0; i
< ARRAY_SIZE(white_rect
); i
++)
67 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
69 /* 1: unclamped quad */
70 glDisable(GL_DEPTH_CLAMP
);
73 glVertex3f(10, 10, 0);
74 glVertex3f(30, 10, 0);
75 glVertex3f(30, 30, -2);
76 glVertex3f(10, 30, -2);
80 glEnable(GL_DEPTH_CLAMP
);
82 glVertex3f(40, 10, 0);
83 glVertex3f(60, 10, 0);
84 glVertex3f(60, 30, -2);
85 glVertex3f(40, 30, -2);
88 /* 3: unclamped line */
89 glDisable(GL_DEPTH_CLAMP
);
91 glVertex3f(10.5, 40.5, 0);
92 glVertex3f(10.5, 60.5, -2);
96 glEnable(GL_DEPTH_CLAMP
);
98 glVertex3f(40.5, 40.5, 0);
99 glVertex3f(40.5, 60.5, -2);
102 /* 5: unclamped point */
103 glDisable(GL_DEPTH_CLAMP
);
105 glVertex3f(10.5, 70.5, -2);
108 /* 6: clamped point */
109 glEnable(GL_DEPTH_CLAMP
);
111 glVertex3f(40.5, 70.5, -2);
114 /* 7: unclamped raster */
115 glDisable(GL_DEPTH_CLAMP
);
116 glRasterPos3f(10, 80, -2);
117 glDrawPixels(20, 20, GL_RGB
, GL_FLOAT
, white_rect
);
119 /* 8: clamped raster */
120 glEnable(GL_DEPTH_CLAMP
);
121 glRasterPos3f(40, 80, -2);
122 glDrawPixels(20, 20, GL_RGB
, GL_FLOAT
, white_rect
);
124 /* 1: unclamped quad */
125 pass
= piglit_probe_pixel_rgb(20, 15, white
) && pass
;
126 pass
= piglit_probe_pixel_rgb(20, 25, clear
) && pass
;
128 /* 2: clamped quad */
129 pass
= piglit_probe_pixel_rgb(50, 15, white
) && pass
;
130 pass
= piglit_probe_pixel_rgb(50, 25, white
) && pass
;
132 /* 3: unclamped line */
133 pass
= piglit_probe_pixel_rgb(10, 45, white
) && pass
;
134 pass
= piglit_probe_pixel_rgb(10, 55, clear
) && pass
;
136 /* 4: unclamped line */
137 pass
= piglit_probe_pixel_rgb(40, 45, white
) && pass
;
138 pass
= piglit_probe_pixel_rgb(40, 55, white
) && pass
;
140 /* 5: unclamped point */
141 pass
= piglit_probe_pixel_rgb(10, 70, clear
) && pass
;
143 /* 6: clamped point */
144 pass
= piglit_probe_pixel_rgb(40, 70, white
) && pass
;
146 /* 7: unclamped raster */
147 pass
= piglit_probe_pixel_rgb(20, 90, clear
) && pass
;
149 /* 8: clamped raster */
150 pass
= piglit_probe_pixel_rgb(50, 90, white
) && pass
;
154 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;