ovr_multiview: add some basic glsl tests
[piglit.git] / tests / spec / nv_primitive_restart / dlist.c
blob5e19c5fc92b4ca05066581f101423efe0f47e676
1 /*
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
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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file dlist.c
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] = {
39 -1.0, -1.0, /* 0 */
40 -0.5, -1.0,
41 +0.0, -1.0,
42 -1.0, -0.5, /* 3 */
43 -0.5, -0.5,
44 +0.0, -0.5,
45 -1.0, +0.0, /* 6 */
46 -0.5, +0.0,
47 +0.0, +0.0,
48 -1.0, -0.5, /* 9 */
51 static const float colors[10 * 3] = {
52 0.0, 1.0, 0.0,
53 0.0, 1.0, 0.0,
54 0.0, 1.0, 0.0,
55 0.0, 1.0, 0.0,
56 0.0, 1.0, 0.0,
57 0.0, 1.0, 0.0,
58 0.0, 1.0, 0.0,
59 0.0, 1.0, 0.0,
60 0.0, 1.0, 0.0,
61 1.0, 0.0, 1.0,
64 static const int elts[] = {
65 3, 0, 4,
70 9, /* restart index */
72 6, 3, 7,
78 static void
79 lower_left(void)
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);
91 glLoadIdentity();
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,
105 elts);
106 glEndList();
108 /* Since the restart index is client state, it should not have any
109 * effect on glCallList.
111 glPrimitiveRestartIndexNV(0);
112 glCallList(dlist);
114 glDeleteLists(dlist, 1);
116 glPopClientAttrib();
117 glPopAttrib();
120 static void
121 lower_right(void)
123 glPushAttrib(GL_ALL_ATTRIB_BITS);
124 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
125 glLoadIdentity();
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
141 * restart.
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];
154 if (idx == 9) {
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)
158 * instead of 9.
160 glEnableClientState(GL_PRIMITIVE_RESTART_NV);
161 idx = 0;
164 glArrayElement(idx);
167 glEnd();
169 glEndList();
171 glTranslatef(1.0f, 0.0f, 0.0f);
172 glCallList(dlist);
174 glDeleteLists(dlist, 1);
176 glPopClientAttrib();
177 glPopAttrib();
180 static void
181 upper_left(void)
183 glPushAttrib(GL_ALL_ATTRIB_BITS);
184 glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
185 glLoadIdentity();
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++) {
209 if (elts[i] == 9) {
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
220 * is encountered.
222 glPrimitiveRestartNV();
223 } else
224 glArrayElement(elts[i]);
227 glEnd();
229 glEndList();
231 glTranslatef(0.0f, 1.0f, 0.0f);
232 glCallList(dlist);
234 glDeleteLists(dlist, 1);
236 glPopClientAttrib();
237 glPopAttrib();
240 static void
241 upper_right(void)
243 static const int elts[] = {
244 3, 0, 4,
249 0x12345678, /* restart index */
251 6, 3, 7,
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);
267 glLoadIdentity();
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,
284 elts);
285 glEndList();
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);
292 glCallList(dlist);
294 glDeleteLists(dlist, 1);
296 glPopClientAttrib();
297 glPopAttrib();
301 void
302 piglit_init(int argc, char **argv)
304 piglit_require_extension("GL_NV_primitive_restart");
307 enum piglit_result
308 piglit_display()
310 glClearColor(0.5, 0.5, 0.5, 1.0);
311 glClear(GL_COLOR_BUFFER_BIT);
313 lower_left();
314 lower_right();
315 upper_left();
316 upper_right();
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;