2 * Copyright © 2020 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
21 * DEALINGS IN THE SOFTWARE.
26 * Exercise various interactions of primitive restart with display lists.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_compat_version
= 12;
34 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
36 PIGLIT_GL_TEST_CONFIG_END
38 static const float verts
[10 * 2] = {
51 static const float colors
[10 * 3] = {
64 static const int elts
[] = {
70 9, /* restart index */
81 glPushAttrib(GL_ALL_ATTRIB_BITS
);
82 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS
);
84 /* Disable backface culling. The position data and drawing indices
85 * are crafted such that the same pixels will be covered even if
86 * primitive restart state is ignored. However, that will result in
87 * an extra triangle being drawn with incorrect colors.
89 glDisable(GL_CULL_FACE
);
90 glDisable(GL_DEPTH_TEST
);
93 glVertexPointer(2, GL_FLOAT
, 0, verts
);
94 glColorPointer(3, GL_FLOAT
, 0, colors
);
95 glEnableClientState(GL_VERTEX_ARRAY
);
96 glEnableClientState(GL_COLOR_ARRAY
);
98 glEnableClientState(GL_PRIMITIVE_RESTART_NV
);
99 glPrimitiveRestartIndexNV(9);
101 const GLuint dlist
= glGenLists(1);
103 glNewList(dlist
, GL_COMPILE
);
104 glDrawElements(GL_TRIANGLE_STRIP
, ARRAY_SIZE(elts
), GL_UNSIGNED_INT
,
108 /* Since the restart index is client state, it should not have any
109 * effect on glCallList.
111 glPrimitiveRestartIndexNV(0);
114 glDeleteLists(dlist
, 1);
123 glPushAttrib(GL_ALL_ATTRIB_BITS
);
124 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS
);
127 /* Disable backface culling. The position data and drawing indices
128 * are crafted such that the same pixels will be covered even if
129 * primitive restart state is ignored. However, that will result in
130 * an extra triangle being drawn with incorrect colors.
132 glDisable(GL_CULL_FACE
);
133 glDisable(GL_DEPTH_TEST
);
135 glVertexPointer(2, GL_FLOAT
, 0, verts
);
136 glColorPointer(3, GL_FLOAT
, 0, colors
);
137 glEnableClientState(GL_VERTEX_ARRAY
);
138 glEnableClientState(GL_COLOR_ARRAY
);
140 /* The real reset index is 9, but set it to 0 and disable primitive
143 glPrimitiveRestartIndexNV(0);
144 glDisableClientState(GL_PRIMITIVE_RESTART_NV
);
146 const GLuint dlist
= glGenLists(1);
147 glNewList(dlist
, GL_COMPILE
);
149 glBegin(GL_TRIANGLE_STRIP
);
151 for (unsigned i
= 0; i
< ARRAY_SIZE(elts
); i
++) {
152 GLuint idx
= elts
[i
];
155 /* 0 only appears once in the elts list, and that is
156 * before 9. Once the 9 is encountered, enable
157 * primitive restart, and emit 0 (the restart index)
160 glEnableClientState(GL_PRIMITIVE_RESTART_NV
);
171 glTranslatef(1.0f
, 0.0f
, 0.0f
);
174 glDeleteLists(dlist
, 1);
183 glPushAttrib(GL_ALL_ATTRIB_BITS
);
184 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS
);
187 /* Disable backface culling. The position data and drawing indices
188 * are crafted such that the same pixels will be covered even if
189 * primitive restart state is ignored. However, that will result in
190 * an extra triangle being drawn with incorrect colors.
192 glDisable(GL_CULL_FACE
);
193 glDisable(GL_DEPTH_TEST
);
195 glVertexPointer(2, GL_FLOAT
, 0, verts
);
196 glColorPointer(3, GL_FLOAT
, 0, colors
);
197 glEnableClientState(GL_VERTEX_ARRAY
);
198 glEnableClientState(GL_COLOR_ARRAY
);
200 glPrimitiveRestartIndexNV(0);
201 glDisableClientState(GL_PRIMITIVE_RESTART_NV
);
203 const GLuint dlist
= glGenLists(1);
204 glNewList(dlist
, GL_COMPILE
);
206 glBegin(GL_TRIANGLE_STRIP
);
208 for (unsigned i
= 0; i
< ARRAY_SIZE(elts
); i
++) {
210 /* The GL_NV_primitive_restart spec doesn't explicitly
211 * say whether or not the GL_PRIMITIVE_RESTART_NV
212 * affects glPrimitiveRestartNV, but it _implies_ that
213 * it is not affected. GL_PRIMITIVE_RESTART_NV is
214 * client state, but GLX protocol is (partially)
215 * defined for glPrimitiveRestartNV. The idea is that
216 * when the GLX client library decomposes
217 * glDrawElements into immediate mode drawing
218 * commands, it will emit glPrimitiveRestartNV
219 * (instead of glVertex, etc.) when the restart index
222 glPrimitiveRestartNV();
224 glArrayElement(elts
[i
]);
231 glTranslatef(0.0f
, 1.0f
, 0.0f
);
234 glDeleteLists(dlist
, 1);
243 static const int elts
[] = {
249 0x12345678, /* restart index */
257 glPushAttrib(GL_ALL_ATTRIB_BITS
);
258 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS
);
260 /* Disable backface culling. The position data and drawing indices
261 * are crafted such that the same pixels will be covered even if
262 * primitive restart state is ignored. However, that will result in
263 * an extra triangle being drawn with incorrect colors.
265 glDisable(GL_CULL_FACE
);
266 glDisable(GL_DEPTH_TEST
);
269 glVertexPointer(2, GL_FLOAT
, 0, verts
);
270 glColorPointer(3, GL_FLOAT
, 0, colors
);
271 glEnableClientState(GL_VERTEX_ARRAY
);
272 glEnableClientState(GL_COLOR_ARRAY
);
274 const GLuint dlist
= glGenLists(1);
276 /* At least at the time of this writing, doing this same thing using
277 * glEnable(GL_PRIMITIVE_RESTART) and glPrimitiveRestartIndex(...)
278 * leads to a segfault during display list compilation on Mesa.
280 glNewList(dlist
, GL_COMPILE
);
281 glEnableClientState(GL_PRIMITIVE_RESTART_NV
);
282 glPrimitiveRestartIndexNV(0x12345678);
283 glDrawElements(GL_TRIANGLE_STRIP
, ARRAY_SIZE(elts
), GL_UNSIGNED_INT
,
287 /* Since the primitive restart enable is client state, it should not
288 * have any effect on glCallList.
290 glDisableClientState(GL_PRIMITIVE_RESTART_NV
);
291 glTranslatef(1.0f
, 1.0f
, 0.0f
);
294 glDeleteLists(dlist
, 1);
302 piglit_init(int argc
, char **argv
)
304 piglit_require_extension("GL_NV_primitive_restart");
310 glClearColor(0.5, 0.5, 0.5, 1.0);
311 glClear(GL_COLOR_BUFFER_BIT
);
318 static const float green
[] = { 0.0, 1.0, 0.0, 1.0 };
320 bool pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
, green
);
321 piglit_present_results();
323 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;