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-copy.c
32 * Test that GLX_SWAP_COPY_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 XVisualInfo
*visinfo
;
42 static GLXFBConfig
*config
;
43 static GLXContext ctx
;
44 static GLXWindow gwin
;
49 GLboolean pass
= GL_TRUE
;
50 static const float red
[] = {1.0, 0.0, 0.0, 0.5};
52 glXMakeContextCurrent(dpy
, gwin
, gwin
, ctx
);
53 glClearColor(1.0, 0.0, 0.0, 0.5);
54 glClear(GL_COLOR_BUFFER_BIT
);
55 glXMakeContextCurrent(dpy
, None
, None
, NULL
);
56 glXSwapBuffers(dpy
, gwin
);
57 glXSwapBuffers(dpy
, gwin
);
58 glXSwapBuffers(dpy
, gwin
);
59 glXMakeContextCurrent(dpy
, gwin
, gwin
, ctx
);
60 glReadBuffer(GL_BACK
);
61 pass
= piglit_probe_pixel_rgba(0, 0, red
);
63 glReadBuffer(GL_FRONT
);
64 pass
= piglit_probe_pixel_rgb(0, 0, red
);
67 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
72 piglit_get_swap_copy_config(Display
*dpy
)
77 GLX_RENDER_TYPE
, GLX_RGBA_BIT
,
82 GLX_SWAP_METHOD_OML
, GLX_SWAP_COPY_OML
,
83 GLX_DOUBLEBUFFER
, True
,
86 int screen
= DefaultScreen(dpy
);
88 fbc
= glXChooseFBConfig(dpy
, screen
, attrib
, &nele
);
91 "Couldn't get a GLX_SWAP_COPY_OML, RGBA, "
92 "double-buffered fbconfig\n");
93 piglit_report_result(PIGLIT_SKIP
);
101 main(int argc
, char **argv
)
104 const char *glx_extension_list
;
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_copy_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
);
135 gwin
= glXCreateWindow(dpy
, config
[0], win
, NULL
);
136 ctx
= glXCreateNewContext(dpy
, config
[0], GLX_RGBA_TYPE
, 0, GL_TRUE
);
137 glXMakeContextCurrent(dpy
, gwin
, gwin
, ctx
);
138 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
140 piglit_glx_event_loop(dpy
, draw
);