2 * Copyright © Christopher James Halse Rogers <christopher.halse.rogers@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@canonical.com>
28 /** @file glx-make-glxdrawable-current.c
30 * Test that MakeCurrent can successfully switch a single context between
31 * different GLXDrawables and back.
33 * https://bugs.freedesktop.org/show_bug.cgi?id=30457
36 #include "piglit-util-gl.h"
37 #include "piglit-glx-util.h"
39 int piglit_width
= 50, piglit_height
= 50;
41 static Window win_one
, win_two
;
42 static XVisualInfo
*visinfo
;
48 float green
[] = {0.0, 1.0, 0.0, 0.0};
49 GLboolean pass
= GL_TRUE
;
50 GLXWindow glxwin_one
, glxwin_two
;
53 config
= piglit_glx_get_fbconfig_for_visinfo(dpy
, visinfo
);
55 glxwin_one
= glXCreateWindow(dpy
, config
, win_one
, NULL
);
56 glxwin_two
= glXCreateWindow(dpy
, config
, win_two
, NULL
);
58 ctx
= piglit_get_glx_context(dpy
, visinfo
);
60 glXMakeCurrent(dpy
, glxwin_one
, ctx
);
61 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
63 glClearColor(0.0, 1.0, 0.0, 1.0);
64 glClear(GL_COLOR_BUFFER_BIT
);
66 glXMakeCurrent(dpy
, glxwin_two
, ctx
);
68 glClear(GL_COLOR_BUFFER_BIT
);
70 glXMakeCurrent(dpy
, glxwin_one
, ctx
);
71 pass
&= piglit_probe_pixel_rgb(1, 1, green
);
73 glXMakeCurrent(dpy
, glxwin_two
, ctx
);
74 pass
&= piglit_probe_pixel_rgb(1, 1, green
);
76 /* Free our resources when we're done. */
77 glXDestroyWindow(dpy
, glxwin_one
);
78 glXDestroyWindow(dpy
, glxwin_two
);
80 glXMakeCurrent(dpy
, None
, NULL
);
81 glXDestroyContext(dpy
, ctx
);
83 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
87 main(int argc
, char **argv
)
91 for(i
= 1; i
< argc
; ++i
) {
92 if (!strcmp(argv
[i
], "-auto"))
95 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
98 dpy
= XOpenDisplay(NULL
);
100 fprintf(stderr
, "couldn't open display\n");
101 piglit_report_result(PIGLIT_FAIL
);
103 visinfo
= piglit_get_glx_visual(dpy
);
104 win_one
= piglit_get_glx_window(dpy
, visinfo
);
105 win_two
= piglit_get_glx_window(dpy
, visinfo
);
107 piglit_glx_event_loop(dpy
, draw
);