cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / wgl / wgl-multi-context-single-window.c
bloba28a3244da337832dd7c7f2b3994092205a980d5
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
25 * Test rendering into one window with multiple contexts.
27 * Authors:
28 * Brian Paul
31 #include <assert.h>
32 #include <stdio.h>
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;
42 static HWND win;
44 static const float colors[MAX_CONTEXTS][4] = {
45 {1, 0, 0, 1},
46 {0, 1, 0, 1},
47 {0, 0, 1, 1},
48 {0, 1, 1, 1},
49 {1, 0, 1, 1},
50 {1, 1, 0, 1},
51 {1, 1, 1, 1},
52 {.5, .5, .5, 1},
56 static int rect_size = 40;
59 static int
60 rect_pos(int i)
62 return i * rect_size / 2;
66 enum piglit_result
67 draw(void)
69 int i;
70 bool pass = true;
72 /* draw a series of colored quads, one per context, at increasing
73 * Z distance.
75 for (i = 0; i < num_contexts; i++) {
76 if (!wglMakeCurrent(GetDC(win), ctx[i])) {
77 fprintf(stderr, "wglMakeCurrent failed\n");
78 return PIGLIT_FAIL;
81 if (i == 0) {
82 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
85 glEnable(GL_DEPTH_TEST);
86 glMatrixMode(GL_PROJECTION);
87 glLoadIdentity();
88 glOrtho(0, piglit_width, 0, piglit_height, 0, 1);
90 glMatrixMode(GL_MODELVIEW);
91 glLoadIdentity();
93 glPushMatrix();
94 float p = rect_pos(i);
95 float z = -i / 10.0;
96 glTranslatef(p, p, z);
98 glColor4fv(colors[i]);
99 piglit_draw_rect(0, 0, rect_size, rect_size);
101 glPopMatrix();
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]);
110 if (!p) {
111 printf("Failed probe for rect/context %d\n", i);
112 pass = false;
116 SwapBuffers(GetDC(win));
118 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
123 main(int argc, char **argv)
125 int i;
127 piglit_width = 500;
128 piglit_height = 500;
130 for (i = 1; i < argc; i++) {
131 if (strcmp(argv[i], "-auto") == 0) {
132 piglit_automatic = 1;
133 break;
137 win = piglit_get_wgl_window();
138 assert(win);
140 for (i = 0; i < num_contexts; i++) {
141 ctx[i] = piglit_get_wgl_context(win);
142 assert(ctx[i]);
145 if (!wglMakeCurrent(GetDC(win), ctx[0])) {
146 fprintf(stderr, "wglMakeCurrent failed\n");
147 return 0;
150 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
152 piglit_wgl_event_loop(draw);
154 return 0;