glsl-1.10: test mesa bug with forward declaration
[piglit.git] / tests / glx / glx-fbo-binding.c
blob5cb08622dc5ab7c5089d41d9a9d9f57148ebf4ac
1 /*
2 * Copyright (c) 2011, VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /**
25 * Test framebuffer binding state across glXMakeCurrent calls.
26 * Brian Paul
27 * June 15, 2011
30 #include "piglit-util-gl.h"
31 #include "piglit-glx-util.h"
33 int piglit_width = 50, piglit_height = 50;
34 static const char *TestName = "glx-fbo-binding";
36 static Window Windows[2];
37 static GLXContext ctx;
40 enum piglit_result
41 draw(Display *dpy)
43 GLuint fbo = 0;
44 GLint b = 0;
46 /* bind first window, create FBO, bind it */
47 glXMakeCurrent(dpy, Windows[0], ctx);
48 glGenFramebuffersEXT(1, &fbo);
49 if (fbo == 0) {
50 printf("%s: glGenFramebuffer() failed (%u)\n",
51 TestName, fbo);
52 return PIGLIT_FAIL;
54 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
55 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &b);
56 if (fbo != b) {
57 printf("%s: glBindFramebuffer() #1 failed (%u vs %d)\n",
58 TestName, fbo, b);
59 return PIGLIT_FAIL;
62 /* bind second window, test FBO binding (should be unchanged) */
63 glXMakeCurrent(dpy, Windows[1], ctx);
64 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &b);
65 if (fbo != b) {
66 printf("%s: glBindFramebuffer() #2 failed (%u vs %d)\n",
67 TestName, fbo, b);
68 return PIGLIT_FAIL;
71 /* bind second window again, test FBO binding */
72 glXMakeCurrent(dpy, Windows[1], ctx);
73 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &b);
74 if (fbo != b) {
75 printf("%s: glBindFramebuffer() #3 failed (%u vs %d)\n",
76 TestName, fbo, b);
77 return PIGLIT_FAIL;
80 return PIGLIT_PASS;
84 int
85 main(int argc, char **argv)
87 Display *dpy;
88 XVisualInfo *visinfo;
89 int i;
91 for (i = 1; i < argc; i++) {
92 if (strcmp(argv[i], "-auto") == 0) {
93 piglit_automatic = 1;
94 break;
98 dpy = XOpenDisplay(NULL);
99 if (!dpy) {
100 fprintf(stderr, "Failed to open display\n");
101 piglit_report_result(PIGLIT_FAIL);
104 visinfo = piglit_get_glx_visual(dpy);
105 Windows[0] = piglit_get_glx_window(dpy, visinfo);
106 Windows[1] = piglit_get_glx_window(dpy, visinfo);
108 ctx = piglit_get_glx_context(dpy, visinfo);
110 glXMakeCurrent(dpy, Windows[0], ctx);
111 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
113 piglit_glx_event_loop(dpy, draw);
115 return 0;