Add more structure constructor tests.
[piglit/hramrach.git] / tests / general / depthrange-clear.c
blob6a2a510c00e15981e37ba5f6c4165b3219146d63
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /** @file depthrange-clear.c
30 * Tests that clears are appropriately unaffected by glDepthRange().
31 * Caught a regression in the intel driver with the metaops clear code.
34 #include "piglit-util.h"
36 int piglit_width = 100, piglit_height = 100;
37 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
39 /**
40 * Convenience function to draw an axis-aligned rectangle.
42 static void
43 draw_rect(float x, float y, float w, float h, float d)
45 float verts[4][4];
47 verts[0][0] = x;
48 verts[0][1] = y;
49 verts[0][2] = d;
50 verts[0][3] = 1.0;
51 verts[1][0] = x + w;
52 verts[1][1] = y;
53 verts[1][2] = d;
54 verts[1][3] = 1.0;
55 verts[2][0] = x + w;
56 verts[2][1] = y + h;
57 verts[2][2] = d;
58 verts[2][3] = 1.0;
59 verts[3][0] = x;
60 verts[3][1] = y + h;
61 verts[3][2] = d;
62 verts[3][3] = 1.0;
64 glVertexPointer(4, GL_FLOAT, 0, verts);
65 glEnableClientState(GL_VERTEX_ARRAY);
67 glDrawArrays(GL_QUADS, 0, 4);
69 glDisableClientState(GL_VERTEX_ARRAY);
72 static void
73 draw_rect_set(int y)
75 draw_rect(10, y, 10, 10, -.75);
76 draw_rect(30, y, 10, 10, -.25);
77 draw_rect(50, y, 10, 10, .25);
78 draw_rect(70, y, 10, 10, .75);
81 enum piglit_result
82 piglit_display(void)
84 GLboolean pass = GL_TRUE;
85 int x, y;
86 static float red[] = {1.0, 0.0, 0.0, 0.0};
87 static float green[] = {0.0, 1.0, 0.0, 0.0};
89 glEnable(GL_DEPTH_TEST);
91 glClearColor(0.0, 1.0, 0.0, 0.0);
92 glClear(GL_COLOR_BUFFER_BIT);
94 glColor4fv(red);
96 glClearDepth(0.5);
97 glClear(GL_DEPTH_BUFFER_BIT);
98 draw_rect_set(10);
100 glDepthRange(0.5, 1.0);
101 glClearDepth(0.5);
102 glClear(GL_DEPTH_BUFFER_BIT);
103 glDepthRange(0.0, 1.0);
104 draw_rect_set(30);
106 glDepthRange(0.0, 0.5);
107 glClearDepth(0.5);
108 glClear(GL_DEPTH_BUFFER_BIT);
109 glDepthRange(0.0, 1.0);
110 draw_rect_set(50);
112 for (y = 0; y < 3; y++) {
113 for (x = 0; x < 4; x++) {
114 float *expected;
116 if (x < 2)
117 expected = green;
118 else
119 expected = red;
121 pass &= piglit_probe_pixel_rgb(15 + x * 20, 15 + y * 20,
122 expected);
126 glutSwapBuffers();
128 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
132 static void reshape(int width, int height)
134 piglit_width = width;
135 piglit_height = height;
137 glViewport(0, 0, width, height);
138 piglit_ortho_projection(width, height, GL_FALSE);
141 void
142 piglit_init(int argc, char **argv)
144 reshape(piglit_width, piglit_height);