2 * Copyright © 2010 Intel Corporation
3 * Copyright © 2017 VMWare Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * Eric Anholt <eric@anholt.net>
26 * Thomas Hellstrom <thellstrom@vmware.com>
30 /** @file glx-swap-exchange.c
32 * Test that GLX_SWAP_EXCHANGE_OML does in fact cause the back buffer to get
36 #include "piglit-util-gl.h"
37 #include "piglit-glx-util.h"
39 int piglit_width
= 50, piglit_height
= 50;
41 static GLXFBConfig
*config
;
42 static GLXContext ctx
;
43 static GLXWindow gwin
;
48 GLboolean pass
= GL_TRUE
;
49 static const float green
[] = {0.0, 1.0, 0.0, 0.3};
50 static const float red
[] = {1.0, 0.0, 0.0, 0.5};
52 glXMakeContextCurrent(dpy
, gwin
, gwin
, ctx
);
53 glClearColor(0.0, 1.0, 0.0, 0.3);
54 glClear(GL_COLOR_BUFFER_BIT
);
55 glXSwapBuffers(dpy
, gwin
);
56 glClearColor(1.0, 0.0, 0.0, 0.5);
57 glClear(GL_COLOR_BUFFER_BIT
);
58 glXSwapBuffers(dpy
, gwin
);
59 glReadBuffer(GL_BACK
);
60 pass
= piglit_probe_pixel_rgba(0, 0, green
);
62 glReadBuffer(GL_FRONT
);
63 pass
= piglit_probe_pixel_rgba(0, 0, red
);
66 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
71 piglit_get_swap_exchange_config(Display
*dpy
)
76 GLX_RENDER_TYPE
, GLX_RGBA_BIT
,
81 GLX_SWAP_METHOD_OML
, GLX_SWAP_EXCHANGE_OML
,
82 GLX_DOUBLEBUFFER
, True
,
85 int screen
= DefaultScreen(dpy
);
87 fbc
= glXChooseFBConfig(dpy
, screen
, attrib
, &nele
);
90 "Couldn't get a GLX_SWAP_EXCHANGE_OML, RGBA, "
91 "double-buffered fbconfig\n");
92 piglit_report_result(PIGLIT_SKIP
);
100 main(int argc
, char **argv
)
103 const char *glx_extension_list
;
105 XVisualInfo
*visinfo
;
107 for (i
= 1; i
< argc
; ++i
) {
108 if (!strcmp(argv
[i
], "-auto"))
109 piglit_automatic
= 1;
111 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
114 dpy
= XOpenDisplay(NULL
);
116 fprintf(stderr
, "couldn't open display\n");
117 piglit_report_result(PIGLIT_FAIL
);
120 glx_extension_list
= glXQueryExtensionsString(dpy
, DefaultScreen(dpy
));
121 if (strstr(glx_extension_list
, "GLX_OML_swap_method") == NULL
) {
122 printf("Requires GLX_OML_swap_method\n");
123 piglit_report_result(PIGLIT_SKIP
);
126 config
= piglit_get_swap_exchange_config(dpy
);
127 visinfo
= glXGetVisualFromFBConfig(dpy
, config
[0]);
130 printf("Error: couldn't create a visual from fbconfig.\n");
131 piglit_report_result(PIGLIT_FAIL
);
134 win
= piglit_get_glx_window(dpy
, visinfo
);
137 gwin
= glXCreateWindow(dpy
, config
[0], win
, NULL
);
138 ctx
= glXCreateNewContext(dpy
, config
[0], GLX_RGBA_TYPE
, 0, GL_TRUE
);
139 glXMakeContextCurrent(dpy
, gwin
, gwin
, ctx
);
140 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
142 piglit_glx_event_loop(dpy
, draw
);