conversion-explicit: use a different value for normalized +/- min
[piglit.git] / tests / glx / glx-swap-exchange.c
blob039604adc551ab4a6c53ed82e31bb31068a35a25
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-exchange.c
32 * Test that GLX_SWAP_EXCHANGE_OML does in fact cause the back buffer to get
33 * exchanged 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 GLXFBConfig *config;
42 static GLXContext ctx;
43 static GLXWindow gwin;
45 enum piglit_result
46 draw(Display *dpy)
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);
61 if (pass) {
62 glReadBuffer(GL_FRONT);
63 pass = piglit_probe_pixel_rgba(0, 0, red);
66 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
70 static GLXFBConfig *
71 piglit_get_swap_exchange_config(Display *dpy)
73 GLXFBConfig *fbc;
74 int nele;
75 int attrib[] = {
76 GLX_RENDER_TYPE, GLX_RGBA_BIT,
77 GLX_RED_SIZE, 8,
78 GLX_GREEN_SIZE, 8,
79 GLX_BLUE_SIZE, 8,
80 GLX_ALPHA_SIZE, 8,
81 GLX_SWAP_METHOD_OML, GLX_SWAP_EXCHANGE_OML,
82 GLX_DOUBLEBUFFER, True,
83 None
85 int screen = DefaultScreen(dpy);
87 fbc = glXChooseFBConfig(dpy, screen, attrib, &nele);
88 if (fbc == NULL) {
89 fprintf(stderr,
90 "Couldn't get a GLX_SWAP_EXCHANGE_OML, RGBA, "
91 "double-buffered fbconfig\n");
92 piglit_report_result(PIGLIT_SKIP);
93 exit(1);
96 return fbc;
99 int
100 main(int argc, char **argv)
102 int i;
103 const char *glx_extension_list;
104 Window win;
105 XVisualInfo *visinfo;
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_exchange_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 XFree(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);
144 XFree(config);
146 return 0;