ext_transform_feedback: document missing mode in usage
[piglit.git] / tests / glx / glx-copy-sub-buffer.c
blob492dab1c62e38f724ba9bb71272ed4ff4175dff2
1 /*
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
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 * 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;
40 static Display *dpy;
41 static Window win_one;
42 static XVisualInfo *visinfo;
43 static PFNGLXCOPYSUBBUFFERMESAPROC CopySubBuffer;
45 enum piglit_result
46 draw(Display *dpy)
48 GLXContext ctx;
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,
64 piglit_width / 4,
65 piglit_height / 4,
66 piglit_width / 2,
67 piglit_height / 2);
69 glReadBuffer(GL_FRONT);
71 pass &= piglit_probe_rect_rgb(0, 0, piglit_width / 4, piglit_height / 4,
72 red);
73 pass &= piglit_probe_rect_rgb(piglit_width / 4, piglit_width / 4,
74 piglit_width / 2, piglit_height / 2,
75 green);
77 glXMakeCurrent(dpy, None, NULL);
78 glXDestroyContext(dpy, ctx);
80 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
83 static XVisualInfo *
84 get_glx_visual(Display *dpy, int samples)
86 XVisualInfo *visinfo;
87 int attrib[] = {
88 GLX_RGBA,
89 GLX_RED_SIZE, 1,
90 GLX_GREEN_SIZE, 1,
91 GLX_BLUE_SIZE, 1,
92 GLX_DOUBLEBUFFER,
93 samples <= 1 ? None : GLX_SAMPLE_BUFFERS, 1,
94 GLX_SAMPLES, samples,
95 None
97 int screen = DefaultScreen(dpy);
99 visinfo = glXChooseVisual(dpy, screen, attrib);
100 if (visinfo == NULL) {
101 fprintf(stderr,
102 "Couldn't get an RGBA, double-buffered visual "
103 "with samples=%i\n", samples);
104 piglit_report_result(PIGLIT_SKIP);
105 exit(1);
108 return visinfo;
112 main(int argc, char **argv)
114 int i, samples = 0;
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);
122 else
123 fprintf(stderr, "Unknown option: %s\n", argv[i]);
126 dpy = XOpenDisplay(NULL);
127 if (dpy == 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);
141 return 0;