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
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.
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
;
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];
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
) {
60 if (x
>= 32 && x
< 96 && y
>= 32 && y
< 96)
63 delta
= fabs(mainr
- mainf
[y
][x
][0]) + fabs(maing
- mainf
[y
][x
][1]) + fabs(mainb
- mainf
[y
][x
][2]);
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]);
73 for(x
= 0; x
< 64; ++x
) {
74 for(y
= 0; y
< 64; ++y
) {
77 delta
= fabs(subr
- sub
[y
][x
][0]) + fabs(subg
- sub
[y
][x
][1]) + fabs(subb
- sub
[y
][x
][2]);
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]);
90 static void test(void)
94 glutSetWindow(MainWindow
);
95 glClearColor(1, 0, 0, 0);
96 glClear(GL_COLOR_BUFFER_BIT
);
99 glutSetWindow(SubWindow
);
100 glClearColor(0, 1, 0, 0);
101 glClear(GL_COLOR_BUFFER_BIT
);
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
);
111 success
= success
&& verify(0, 0, 1, 0, 1, 0, "re-clear main window");
113 glutSetWindow(SubWindow
);
123 success
= success
&& verify(0, 0, 1, 1, 1, 0, "render in sub window");
125 glutSetWindow(MainWindow
);
135 success
= success
&& verify(0, 1, 1, 1, 1, 0, "render in main window");
138 piglit_report_result(success
? PIGLIT_PASS
: PIGLIT_FAIL
);
141 static void RedisplayMain(void)
146 static void RedisplaySub(void)
152 static void Reshape(int width
, int height
)
154 glViewport(0, 0, width
, height
);
155 glMatrixMode(GL_PROJECTION
);
157 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
158 glMatrixMode(GL_MODELVIEW
);
163 static void Key(unsigned char key
, int x
, int y
)
175 int main(int argc
, char *argv
[])
177 glutInit(&argc
, argv
);
178 if (argc
== 2 && !strcmp(argv
[1], "-auto"))
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
);
188 glutKeyboardFunc(Key
);
190 MainWindow
= glutGetWindow();
191 SubWindow
= glutCreateSubWindow(MainWindow
, SubX
, SubY
, SubWidth
, SubHeight
);
192 glutReshapeFunc(Reshape
);
193 glutDisplayFunc(RedisplaySub
);