ext_transform_feedback: document missing mode in usage
[piglit.git] / tests / glx / glx-swap-pbuffer.c
blob7597b5b356e4863d84f6248b7b5919a94ff9d9ce
1 /*
2 * Copyright 2011 Red Hat, Inc.
3 * Copyright 2011 Intel Corporation.
4 * Copyright 2021 Advanced Micro Devices, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * IN THE SOFTWARE.
26 /**
27 * Test swap buffer works for pbuffer.
30 #include "piglit-util-gl.h"
31 #include "piglit-glx-util.h"
33 int piglit_width = 50, piglit_height = 50;
35 static GLXFBConfig
36 get_fbconfig(Display *dpy)
38 int n;
39 int attrs[] = {
40 GLX_DOUBLEBUFFER, 1,
41 GLX_RENDER_TYPE, GLX_RGBA_BIT,
42 GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT | GLX_WINDOW_BIT,
43 GLX_RED_SIZE, 8,
44 GLX_GREEN_SIZE, 8,
45 GLX_BLUE_SIZE, 8,
46 GLX_ALPHA_SIZE, 8,
47 None
49 GLXFBConfig *configs = glXChooseFBConfig(dpy, DefaultScreen(dpy), attrs, &n);
50 if (!configs || n < 1) {
51 fprintf(stderr, "Can't find proper fbconfig.\n");
52 piglit_report_result(PIGLIT_FAIL);
55 return configs[0];
58 static GLXPbuffer
59 get_pbuffer(Display *dpy, GLXFBConfig config)
61 int attrs[] = {
62 GLX_PBUFFER_WIDTH, piglit_width,
63 GLX_PBUFFER_HEIGHT, piglit_height,
64 GLX_PRESERVED_CONTENTS, True,
65 GLX_LARGEST_PBUFFER, False,
66 None
68 GLXPbuffer pbuffer = glXCreatePbuffer(dpy, config, attrs);
69 if (!pbuffer) {
70 fprintf(stderr, "Fail to create pbuffer.\n");
71 piglit_report_result(PIGLIT_FAIL);
74 return pbuffer;
77 static GLXContext
78 get_context(Display *dpy, GLXFBConfig config)
80 GLXContext ctx = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, True);
81 if (!ctx) {
82 fprintf(stderr, "Fail to create context.\n");
83 piglit_report_result(PIGLIT_FAIL);
86 return ctx;
89 static void
90 clear_and_check_result(Display *dpy, GLXPbuffer pbuffer, const float *color)
92 bool pass;
94 glClearColor(color[0], color[1], color[2], color[3]);
95 glClear(GL_COLOR_BUFFER_BIT);
97 glXSwapBuffers(dpy, pbuffer);
99 pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, color);
100 if (!pass) {
101 fprintf(stderr, "Clear check fail for color (%f %f %f %f).\n",
102 color[0], color[1], color[2], color[3]);
103 piglit_report_result(PIGLIT_FAIL);
108 main(int argc, char **argv)
110 Display *dpy;
111 GLXFBConfig config;
112 GLXPbuffer pbuffer;
113 GLXContext ctx;
114 const float green[] = {0.0, 1.0, 0.0, 0.0};
115 const float red[] = {1.0, 0.0, 0.0, 0.0};
117 dpy = XOpenDisplay(NULL);
118 if (dpy == NULL) {
119 fprintf(stderr, "couldn't open display\n");
120 piglit_report_result(PIGLIT_FAIL);
123 piglit_glx_get_error(dpy, NULL);
124 piglit_require_glx_version(dpy, 1, 3);
126 config = get_fbconfig(dpy);
127 pbuffer = get_pbuffer(dpy, config);
128 ctx = get_context(dpy, config);
130 glXMakeCurrent(dpy, pbuffer, ctx);
131 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
133 /* Check front buffer has been updated after swap buffer. */
134 glReadBuffer(GL_FRONT);
136 clear_and_check_result(dpy, pbuffer, green);
137 clear_and_check_result(dpy, pbuffer, red);
139 glXDestroyPbuffer(dpy, pbuffer);
141 piglit_report_result(PIGLIT_PASS);
143 return 0;