2 * Copyright © 2009-2011 Intel Corporation
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
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
24 /** @file glx-multi-context-ib.c
26 * Tests that multiple contexts drawing using index buffers work correctly.
28 * Catches a bug in the i965 driver in which index buffer state was
29 * not reemitted across batchbuffer boundaries, if the first draw
30 * after the batch didn't use the IB.
34 #include "piglit-util-gl.h"
35 #include "piglit-glx-util.h"
37 int piglit_width
= 50, piglit_height
= 50;
40 static GLXContext ctx0
, ctx1
;
42 GLuint vb_c0
, vb_c1
, ib_c0
, ib_c1
;
43 static float green
[] = {0, 1, 0, 0};
44 static float red
[] = {1, 0, 0, 0};
46 /* c0 sets up an IB that will mess up c1's drawing, by only indexing
47 * outside of c0's VBO.
62 uint32_t ib_data
[] = {
66 glGenBuffersARB(1, &vb_c0
);
67 glGenBuffersARB(1, &ib_c0
);
68 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, vb_c0
);
69 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, ib_c0
);
71 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(vb_data
), vb_data
,
73 glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, sizeof(ib_data
), ib_data
,
86 uint32_t ib_data
[] = {
90 glGenBuffersARB(1, &vb_c1
);
91 glGenBuffersARB(1, &ib_c1
);
92 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, vb_c1
);
93 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, ib_c1
);
95 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(vb_data
), vb_data
,
97 glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, sizeof(ib_data
), ib_data
,
104 glXMakeCurrent(dpy
, win
, ctx0
);
108 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, vb_c0
);
109 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, ib_c0
);
110 glEnableClientState(GL_VERTEX_ARRAY
);
111 glVertexPointer(2, GL_FLOAT
, 0, (void *)0);
113 glDrawElements(GL_TRIANGLE_FAN
, 4, GL_UNSIGNED_INT
, (void *)0);
117 context1_frame(int iter
)
119 glXMakeCurrent(dpy
, win
, ctx1
);
121 /* This is the drawing without an IB that triggered the driver
122 * not reemitting IB state in the next draw call.
124 * The other context just exists to ensure that the race for
125 * the IB getting smashed is lost, and is also the thing that
126 * produces the glFlush()-based batchbuffer emits we rely on.
129 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
131 /* Failing draw call. */
137 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, vb_c0
);
138 glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB
, ib_c0
);
139 glEnableClientState(GL_VERTEX_ARRAY
);
140 glVertexPointer(2, GL_FLOAT
, 0, (void *)0);
142 glDrawElements(GL_TRIANGLE_FAN
, 4, GL_UNSIGNED_INT
, (void *)0);
152 /* The issue was that on the second frame, failure occurred. */
156 pass
= piglit_probe_rect_rgb(0, 0, piglit_width
, piglit_height
, green
);
158 glXSwapBuffers(dpy
, win
);
160 glXMakeCurrent(dpy
, None
, None
);
162 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
166 main(int argc
, char **argv
)
168 XVisualInfo
*visinfo
;
171 for(i
= 1; i
< argc
; ++i
) {
172 if (!strcmp(argv
[i
], "-auto"))
173 piglit_automatic
= 1;
175 fprintf(stderr
, "Unknown option: %s\n", argv
[i
]);
178 dpy
= XOpenDisplay(NULL
);
180 fprintf(stderr
, "couldn't open display\n");
181 piglit_report_result(PIGLIT_FAIL
);
183 visinfo
= piglit_get_glx_visual(dpy
);
184 win
= piglit_get_glx_window(dpy
, visinfo
);
186 ctx0
= piglit_get_glx_context(dpy
, visinfo
);
187 ctx1
= piglit_get_glx_context(dpy
, visinfo
);
189 glXMakeCurrent(dpy
, win
, ctx0
);
190 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL
);
191 piglit_require_extension("GL_ARB_vertex_buffer_object");
193 glXMakeCurrent(dpy
, win
, ctx1
);
196 piglit_glx_event_loop(dpy
, draw
);
199 glXDestroyContext(dpy
, ctx0
);
200 glXDestroyContext(dpy
, ctx1
);