README: recommend Ninja by default and switch to cmake --build
[piglit.git] / tests / glx / glx-swap-pixmap.c
blobc557f3aea5dde0b75a339288b08139db8ff8a891
1 /*
2 * Copyright 2011 Red Hat, Inc.
3 * Copyright 2011 Intel Corporation.
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.
25 /** @file glx-swap-pixmap.c
27 * Test that glXSwapbuffer() on a pixmap is a noop.
29 * From the GLX 1.4 specification page 34 (page 40 of the PDF):
31 * This operation is a no-op if draw was created with a
32 * non-double-buffered GLXFBConfig, or if draw is a GLXPixmap.
35 #include "piglit-util-gl.h"
36 #include "piglit-glx-util.h"
38 int piglit_width = 50, piglit_height = 50;
39 static Display *dpy;
40 static XVisualInfo *visinfo;
42 int
43 main(int argc, char **argv)
45 Pixmap p;
46 GLXPixmap g;
47 static const float green_alpha_zero[4] = {0.0, 1.0, 0.0, 0.0};
48 static const float green_alpha_one[4] = {0.0, 1.0, 0.0, 1.0};
49 GLXContext ctx;
50 bool pass;
51 GLint alpha_bits;
53 dpy = XOpenDisplay(NULL);
54 if (dpy == NULL) {
55 fprintf(stderr, "couldn't open display\n");
56 piglit_report_result(PIGLIT_FAIL);
59 piglit_glx_get_error(dpy, NULL);
60 piglit_require_glx_version(dpy, 1, 3);
62 visinfo = piglit_get_glx_visual(dpy);
63 p = XCreatePixmap(dpy, DefaultRootWindow(dpy), piglit_width,
64 piglit_height, visinfo->depth);
66 g = glXCreateGLXPixmap(dpy, visinfo, p);
68 ctx = piglit_get_glx_context(dpy, visinfo);
69 glXMakeCurrent(dpy, g, ctx);
70 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
72 /* Clear to green */
73 glClearColor(0.0, 1.0, 0.0, 0.0);
74 glClear(GL_COLOR_BUFFER_BIT);
76 /* Noop */
77 glXSwapBuffers(dpy, g);
79 /* We want to actually catch any X error that leaks through as
80 * a result of glXSwapBuffers() before we go saying "pass" or
81 * "fail".
83 XSync(dpy, False);
85 /* If the visual has no alpha, then the GL spec requires that 1.0 be
86 * read back. Otherwise, we should read back the 0.0 that we wrote.
88 glGetIntegerv(GL_ALPHA_BITS, &alpha_bits);
89 if (alpha_bits == 0) {
90 pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
91 green_alpha_one);
92 } else {
93 pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height,
94 green_alpha_zero);
97 glXDestroyPixmap(dpy, g);
99 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
101 return 0;