glsl-1.10: test mesa bug with forward declaration
[piglit.git] / tests / glx / glx-swap-copy.c
bloba1841670882545ea610012d9bd796cc1ba308649
1 /*
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
14 * Software.
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
22 * IN THE SOFTWARE.
24 * Authors:
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
33 * preserved on swap.
36 #include "piglit-util-gl.h"
37 #include "piglit-glx-util.h"
39 int piglit_width = 50, piglit_height = 50;
40 static Display *dpy;
41 static XVisualInfo *visinfo;
42 static GLXFBConfig *config;
43 static GLXContext ctx;
44 static GLXWindow gwin;
46 enum piglit_result
47 draw(Display *dpy)
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);
62 if (pass) {
63 glReadBuffer(GL_FRONT);
64 pass = piglit_probe_pixel_rgb(0, 0, red);
67 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
71 static GLXFBConfig *
72 piglit_get_swap_copy_config(Display *dpy)
74 GLXFBConfig *fbc;
75 int nele;
76 int attrib[] = {
77 GLX_RENDER_TYPE, GLX_RGBA_BIT,
78 GLX_RED_SIZE, 8,
79 GLX_GREEN_SIZE, 8,
80 GLX_BLUE_SIZE, 8,
81 GLX_ALPHA_SIZE, 8,
82 GLX_SWAP_METHOD_OML, GLX_SWAP_COPY_OML,
83 GLX_DOUBLEBUFFER, True,
84 None
86 int screen = DefaultScreen(dpy);
88 fbc = glXChooseFBConfig(dpy, screen, attrib, &nele);
89 if (fbc == NULL) {
90 fprintf(stderr,
91 "Couldn't get a GLX_SWAP_COPY_OML, RGBA, "
92 "double-buffered fbconfig\n");
93 piglit_report_result(PIGLIT_SKIP);
94 exit(1);
97 return fbc;
101 main(int argc, char **argv)
103 int i;
104 const char *glx_extension_list;
105 Window win;
107 for (i = 1; i < argc; ++i) {
108 if (!strcmp(argv[i], "-auto"))
109 piglit_automatic = 1;
110 else
111 fprintf(stderr, "Unknown option: %s\n", argv[i]);
114 dpy = XOpenDisplay(NULL);
115 if (dpy == 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]);
128 if (!visinfo) {
129 XFree(config);
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);
142 XFree(config);
144 return 0;