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
25 * Test rendering into one window with multiple contexts.
33 #include "piglit-util-gl.h"
34 #include "piglit-wgl-util.h"
38 #define MAX_CONTEXTS 8
40 static HGLRC ctx
[MAX_CONTEXTS
];
41 static int num_contexts
= MAX_CONTEXTS
;
44 static const float colors
[MAX_CONTEXTS
][4] = {
56 static int rect_size
= 40;
62 return i
* rect_size
/ 2;
72 /* draw a series of colored quads, one per context, at increasing
75 for (i
= 0; i
< num_contexts
; i
++) {
76 if (!wglMakeCurrent(GetDC(win
), ctx
[i
])) {
77 fprintf(stderr
, "wglMakeCurrent failed\n");
82 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
85 glEnable(GL_DEPTH_TEST
);
86 glMatrixMode(GL_PROJECTION
);
88 glOrtho(0, piglit_width
, 0, piglit_height
, 0, 1);
90 glMatrixMode(GL_MODELVIEW
);
94 float p
= rect_pos(i
);
96 glTranslatef(p
, p
, z
);
98 glColor4fv(colors
[i
]);
99 piglit_draw_rect(0, 0, rect_size
, rect_size
);
104 /* probe rendering */
105 wglMakeCurrent(GetDC(win
), ctx
[0]);
106 for (i
= 0; i
< num_contexts
; i
++) {
107 int x
= rect_pos(i
) + rect_size
* 3 / 4;
108 int p
= piglit_probe_pixel_rgb(x
, x
, colors
[i
]);
111 printf("Failed probe for rect/context %d\n", i
);
116 SwapBuffers(GetDC(win
));
118 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
123 main(int argc
, char **argv
)
130 for (i
= 1; i
< argc
; i
++) {
131 if (strcmp(argv
[i
], "-auto") == 0) {
132 piglit_automatic
= 1;
137 win
= piglit_get_wgl_window();
140 for (i
= 0; i
< num_contexts
; i
++) {
141 ctx
[i
] = piglit_get_wgl_context(win
);
145 if (!wglMakeCurrent(GetDC(win
), ctx
[0])) {
146 fprintf(stderr
, "wglMakeCurrent failed\n");
150 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
152 piglit_wgl_event_loop(draw
);