2 * Copyright ?? Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
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 * Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
28 /** @file glx-make-current.c
30 * Test that MakeCurrent can successfully switch a single context between
31 * different drawables and back.
35 #include "piglit-util-gl.h"
36 #include "piglit-glx-util.h"
38 int piglit_width
= 50, piglit_height
= 50;
41 static Window wins
[NUM_WINDOWS
];
42 static XVisualInfo
*visinfo
;
49 (float)rand() / RAND_MAX
, (float)rand() / RAND_MAX
, (float)rand() / RAND_MAX
, 0.0
51 GLboolean pass
= GL_TRUE
;
53 ctx
= piglit_get_glx_context(dpy
, visinfo
);
54 glXMakeCurrent(dpy
, wins
[0], ctx
);
55 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
56 glClearColor(color
[0], color
[1], color
[2], 1.0);
57 glClear(GL_COLOR_BUFFER_BIT
);
59 for (int i
= 1; i
< NUM_WINDOWS
; i
++) {
60 glXMakeCurrent(dpy
, wins
[i
], ctx
);
61 glClear(GL_COLOR_BUFFER_BIT
);
64 for (int i
= 0; i
< NUM_WINDOWS
; i
++) {
65 glXMakeCurrent(dpy
, wins
[i
], ctx
);
66 if (!piglit_probe_pixel_rgb(1, 1, color
)) {
67 printf(" (test failed for window %d)\n", i
);
72 for (int i
= 0; i
< NUM_WINDOWS
; i
++) {
73 glXMakeCurrent(dpy
, wins
[i
], ctx
);
74 glXSwapBuffers(dpy
, wins
[i
]);
77 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
81 main(int argc
, char **argv
)
85 for(i
= 1; i
< argc
; ++i
) {
86 if (!strcmp(argv
[i
], "-auto"))
89 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
92 dpy
= XOpenDisplay(NULL
);
94 fprintf(stderr
, "couldn't open display\n");
95 piglit_report_result(PIGLIT_FAIL
);
97 visinfo
= piglit_get_glx_visual(dpy
);
98 for (int i
= 0; i
< NUM_WINDOWS
; i
++)
99 wins
[i
] = piglit_get_glx_window(dpy
, visinfo
);
101 piglit_glx_event_loop(dpy
, draw
);
103 /* Free our resources when we're done. */
104 glXMakeCurrent(dpy
, None
, NULL
);
105 glXDestroyContext(dpy
, piglit_get_glx_context(dpy
, visinfo
));