fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / general / windowoverlap.c
blob19d1aaa1b13ffc70473bc242631630b1794545ce
1 /*
2 * Copyright (c) The Piglit project 2008
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /**
25 * @file
26 * Test whether rendering does not bleed into areas outside the window.
27 * This is done by creating a subwindow and verifying that rendering in
28 * the main window vs. in the sub window is clipped correctly.
30 * This test was prompted by http://bugs.freedesktop.org/show_bug.cgi?id=16123
33 #include "piglit-util-gl.h"
35 static const int MainWidth = 128, MainHeight = 128;
36 static const int SubX = 32, SubY = 32;
37 static const int SubWidth = 64, SubHeight = 64;
39 static int Automatic = 0;
40 static int MainWindow;
41 static int SubWindow;
44 static int verify(float mainr, float maing, float mainb, float subr, float subg, float subb, const char* testname)
46 float mainf[128][128][3];
47 float sub[64][64][3];
48 int x, y;
50 glutSetWindow(MainWindow);
51 glReadPixels(0, 0, 128, 128, GL_RGB, GL_FLOAT, mainf);
53 glutSetWindow(SubWindow);
54 glReadPixels(0, 0, 64, 64, GL_RGB, GL_FLOAT, sub);
56 for(x = 0; x < 128; ++x) {
57 for(y = 0; y < 128; ++y) {
58 float delta;
60 if (x >= 32 && x < 96 && y >= 32 && y < 96)
61 continue;
63 delta = fabs(mainr - mainf[y][x][0]) + fabs(maing - mainf[y][x][1]) + fabs(mainb - mainf[y][x][2]);
64 if (delta > 0.01) {
65 printf("Test %s: Fail at main window pixel %i,%i\n", testname, x, y);
66 printf(" Expected: %5.3f %5.2f %5.3f\n", mainr, maing, mainb);
67 printf(" Actual: %5.3f %5.2f %5.3f\n", mainf[y][x][0], mainf[y][x][1], mainf[y][x][2]);
68 return 0;
73 for(x = 0; x < 64; ++x) {
74 for(y = 0; y < 64; ++y) {
75 float delta;
77 delta = fabs(subr - sub[y][x][0]) + fabs(subg - sub[y][x][1]) + fabs(subb - sub[y][x][2]);
78 if (delta > 0.01) {
79 printf("Test %s: Fail at sub window pixel %i,%i\n", testname, x, y);
80 printf(" Expected: %5.3f %5.2f %5.3f\n", subr, subg, subb);
81 printf(" Actual: %5.3f %5.2f %5.3f\n", sub[y][x][0], sub[y][x][1], sub[y][x][2]);
82 return 0;
87 return 1;
90 static void test(void)
92 int success = 1;
94 glutSetWindow(MainWindow);
95 glClearColor(1, 0, 0, 0);
96 glClear(GL_COLOR_BUFFER_BIT);
97 glFinish();
99 glutSetWindow(SubWindow);
100 glClearColor(0, 1, 0, 0);
101 glClear(GL_COLOR_BUFFER_BIT);
102 glFinish();
104 success = success && verify(1, 0, 0, 0, 1, 0, "initial clear");
106 glutSetWindow(MainWindow);
107 glClearColor(0, 0, 1, 0);
108 glClear(GL_COLOR_BUFFER_BIT);
109 glFinish();
111 success = success && verify(0, 0, 1, 0, 1, 0, "re-clear main window");
113 glutSetWindow(SubWindow);
114 glColor3f(1, 1, 0);
115 glBegin(GL_QUADS);
116 glVertex2f(-1, -1);
117 glVertex2f( 2, -1);
118 glVertex2f( 2, 2);
119 glVertex2f(-1, 2);
120 glEnd();
121 glFinish();
123 success = success && verify(0, 0, 1, 1, 1, 0, "render in sub window");
125 glutSetWindow(MainWindow);
126 glColor3f(0, 1, 1);
127 glBegin(GL_QUADS);
128 glVertex2f(-1, -1);
129 glVertex2f( 2, -1);
130 glVertex2f( 2, 2);
131 glVertex2f(-1, 2);
132 glEnd();
133 glFinish();
135 success = success && verify(0, 1, 1, 1, 1, 0, "render in main window");
137 if (Automatic)
138 piglit_report_result(success ? PIGLIT_PASS : PIGLIT_FAIL);
141 static void RedisplayMain(void)
143 test();
146 static void RedisplaySub(void)
148 test();
152 static void Reshape(int width, int height)
154 glViewport(0, 0, width, height);
155 glMatrixMode(GL_PROJECTION);
156 glLoadIdentity();
157 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
158 glMatrixMode(GL_MODELVIEW);
159 glLoadIdentity();
163 static void Key(unsigned char key, int x, int y)
165 (void) x;
166 (void) y;
167 switch (key) {
168 case 27:
169 exit(0);
170 break;
172 glutPostRedisplay();
175 int main(int argc, char *argv[])
177 glutInit(&argc, argv);
178 if (argc == 2 && !strcmp(argv[1], "-auto"))
179 Automatic = 1;
180 glutInitWindowPosition(0, 0);
181 glutInitWindowSize(MainWidth, MainHeight);
182 glutInitDisplayMode(PIGLIT_GL_VISUAL_RGB);
183 glutCreateWindow(argv[0]);
184 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
185 glutReshapeFunc(Reshape);
186 glutDisplayFunc(RedisplayMain);
187 if (!Automatic)
188 glutKeyboardFunc(Key);
190 MainWindow = glutGetWindow();
191 SubWindow = glutCreateSubWindow(MainWindow, SubX, SubY, SubWidth, SubHeight);
192 glutReshapeFunc(Reshape);
193 glutDisplayFunc(RedisplaySub);
194 glutMainLoop();
195 return 0;