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
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
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;
36 get_fbconfig(Display
*dpy
)
41 GLX_RENDER_TYPE
, GLX_RGBA_BIT
,
42 GLX_DRAWABLE_TYPE
, GLX_PBUFFER_BIT
| GLX_WINDOW_BIT
,
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
);
59 get_pbuffer(Display
*dpy
, GLXFBConfig config
)
62 GLX_PBUFFER_WIDTH
, piglit_width
,
63 GLX_PBUFFER_HEIGHT
, piglit_height
,
64 GLX_PRESERVED_CONTENTS
, True
,
65 GLX_LARGEST_PBUFFER
, False
,
68 GLXPbuffer pbuffer
= glXCreatePbuffer(dpy
, config
, attrs
);
70 fprintf(stderr
, "Fail to create pbuffer.\n");
71 piglit_report_result(PIGLIT_FAIL
);
78 get_context(Display
*dpy
, GLXFBConfig config
)
80 GLXContext ctx
= glXCreateNewContext(dpy
, config
, GLX_RGBA_TYPE
, NULL
, True
);
82 fprintf(stderr
, "Fail to create context.\n");
83 piglit_report_result(PIGLIT_FAIL
);
90 clear_and_check_result(Display
*dpy
, GLXPbuffer pbuffer
, const float *color
)
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
);
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
)
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
);
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
);