2 * Copyright Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
3 * Copyright 2010 Red Hat, 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
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
25 * Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
26 * Adam Jackson <ajax@redhat.com>
28 * Derived from glx-make-current.c
31 /** @file glx-copy-sub-buffer.c
33 * Test that GLX_MESA_copy_sub_buffer works as advertised
36 #include "piglit-util-gl.h"
37 #include "piglit-glx-util.h"
39 int piglit_width
= 100, piglit_height
= 100;
41 static Window win_one
;
42 static XVisualInfo
*visinfo
;
43 static PFNGLXCOPYSUBBUFFERMESAPROC CopySubBuffer
;
49 GLboolean pass
= GL_TRUE
;
50 static float red
[] = {1.0, 0.0, 0.0, 0.0};
51 static float green
[] = {0.0, 1.0, 0.0, 0.0};
53 ctx
= piglit_get_glx_context(dpy
, visinfo
);
54 glXMakeCurrent(dpy
, win_one
, ctx
);
55 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
57 glClearColor(1.0, 0.0, 0.0, 0.0);
58 glClear(GL_COLOR_BUFFER_BIT
);
59 glXSwapBuffers(dpy
, win_one
);
61 glClearColor(0.0, 1.0, 0.0, 0.0);
62 glClear(GL_COLOR_BUFFER_BIT
);
63 CopySubBuffer(dpy
, win_one
,
69 glReadBuffer(GL_FRONT
);
71 pass
&= piglit_probe_rect_rgb(0, 0, piglit_width
/ 4, piglit_height
/ 4,
73 pass
&= piglit_probe_rect_rgb(piglit_width
/ 4, piglit_width
/ 4,
74 piglit_width
/ 2, piglit_height
/ 2,
77 glXMakeCurrent(dpy
, None
, NULL
);
78 glXDestroyContext(dpy
, ctx
);
80 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
84 get_glx_visual(Display
*dpy
, int samples
)
93 samples
<= 1 ? None
: GLX_SAMPLE_BUFFERS
, 1,
97 int screen
= DefaultScreen(dpy
);
99 visinfo
= glXChooseVisual(dpy
, screen
, attrib
);
100 if (visinfo
== NULL
) {
102 "Couldn't get an RGBA, double-buffered visual "
103 "with samples=%i\n", samples
);
104 piglit_report_result(PIGLIT_SKIP
);
112 main(int argc
, char **argv
)
116 for(i
= 1; i
< argc
; ++i
) {
117 if (!strcmp(argv
[i
], "-auto"))
118 piglit_automatic
= 1;
119 else if (!strncmp(argv
[i
], "-samples=", 9)) {
120 samples
= atoi(argv
[i
]+9);
123 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
126 dpy
= XOpenDisplay(NULL
);
128 fprintf(stderr
, "couldn't open display\n");
129 piglit_report_result(PIGLIT_FAIL
);
132 piglit_require_glx_extension(dpy
, "GLX_MESA_copy_sub_buffer");
133 CopySubBuffer
= (PFNGLXCOPYSUBBUFFERMESAPROC
)
134 glXGetProcAddressARB((GLubyte
*)"glXCopySubBufferMESA");
136 visinfo
= get_glx_visual(dpy
, samples
);
137 win_one
= piglit_get_glx_window(dpy
, visinfo
);
139 piglit_glx_event_loop(dpy
, draw
);