2 * Copyright 2017 VMware, Inc.
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 /** @file glx-multi-context-single-window.c
26 * Exercise rendering to a single window with multiple contexts.
30 #include "piglit-util-gl.h"
31 #include "piglit-glx-util.h"
33 #define MAX_CONTEXTS 8
35 static GLXContext ctx
[MAX_CONTEXTS
];
36 static int num_contexts
= MAX_CONTEXTS
;
40 static const float colors
[MAX_CONTEXTS
][4] = {
51 int piglit_width
= 500, piglit_height
= 500;
53 static int rect_size
= 40;
59 return i
* rect_size
/ 2;
69 /* draw a series of colored quads, one per context, at increasing
72 for (i
= 0; i
< num_contexts
; i
++) {
73 glXMakeCurrent(dpy
, win
, ctx
[i
]);
76 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
79 glEnable(GL_DEPTH_TEST
);
80 glMatrixMode(GL_PROJECTION
);
82 glOrtho(0, piglit_width
, 0, piglit_height
, 0, 1);
84 glMatrixMode(GL_MODELVIEW
);
88 float p
= rect_pos(i
);
90 glTranslatef(p
, p
, z
);
92 glColor4fv(colors
[i
]);
93 piglit_draw_rect(0, 0, rect_size
, rect_size
);
99 glXMakeCurrent(dpy
, win
, ctx
[0]);
100 for (i
= 0; i
< num_contexts
; i
++) {
101 int x
= rect_pos(i
) + rect_size
* 3 / 4;
102 int p
= piglit_probe_pixel_rgb(x
, x
, colors
[i
]);
105 printf("Failed probe for rect/context %d\n", i
);
110 glXSwapBuffers(dpy
, win
);
112 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
117 main(int argc
, char **argv
)
119 XVisualInfo
*visinfo
;
122 for (i
= 1; i
< argc
; ++i
) {
123 if (!strcmp(argv
[i
], "-auto"))
124 piglit_automatic
= 1;
126 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
129 dpy
= XOpenDisplay(NULL
);
131 fprintf(stderr
, "couldn't open display\n");
132 piglit_report_result(PIGLIT_FAIL
);
134 visinfo
= piglit_get_glx_visual(dpy
);
136 win
= piglit_get_glx_window(dpy
, visinfo
);
138 for (i
= 0; i
< num_contexts
; i
++) {
139 ctx
[i
] = piglit_get_glx_context(dpy
, visinfo
);
142 glXMakeCurrent(dpy
, win
, ctx
[0]);
143 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
145 piglit_glx_event_loop(dpy
, draw
);
148 glXDestroyWindow(dpy
, win
);
149 for (i
= 0; i
< num_contexts
; i
++) {
150 glXDestroyContext(dpy
, ctx
[i
]);