1 /* Copyright © 2014 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Test indirect renderinger with gl_VertexID
26 * When rendering with glDrawArraysIndirect, the value of gl_VertexID observed
27 * in the shader should start with the value of 'first' and increment from
30 * When rendering with glDrawElementsIndirect, the value of gl_VertexID
31 * observed in the shader should be the value retrieved from the index buffer
32 * plus the value of basevertex.
34 * Run the program with no parameters to use glDrawArraysIndirect, or run the
35 * program with "elements" parameter to use glDrawElementsIndirect.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config
.supports_gl_core_version
= 31;
43 config
.supports_gl_compat_version
= 31;
45 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
46 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
48 PIGLIT_GL_TEST_CONFIG_END
50 static const float green
[] = { 0, 1, 0, 1 };
51 static const float blue
[] = { 0, 0, 1, 1 };
52 static const float gold
[] = { 1, 1, 0, 1 };
53 static const float magenta
[] = { 1, 0, 1, 1 };
59 GLuint reservedMustBeZero
;
60 } DrawArraysIndirectCommand
;
67 GLuint reservedMustBeZero
;
68 } DrawElementsIndirectCommand
;
70 static const DrawArraysIndirectCommand arrays_commands
[] = {
77 static const DrawElementsIndirectCommand elements_commands
[ARRAY_SIZE(arrays_commands
)] = {
84 static bool use_arrays
= true;
92 glViewport(0, 0, piglit_width
, piglit_height
);
93 glClearColor(0.2, 0.2, 0.2, 0.2);
94 glClear(GL_COLOR_BUFFER_BIT
);
96 for (i
= 0; i
< ARRAY_SIZE(arrays_commands
); i
++) {
98 glDrawArraysIndirect(GL_TRIANGLE_FAN
,
99 (void *)(sizeof(arrays_commands
[0]) * i
));
101 glDrawElementsIndirect(GL_TRIANGLE_FAN
,
103 (void *)(sizeof(elements_commands
[0]) * i
));
107 pass
= piglit_probe_rect_rgba(0, 0,
108 piglit_width
/ 2, piglit_height
/2,
111 pass
= piglit_probe_rect_rgba(piglit_width
/ 2, 0,
112 piglit_width
/ 2, piglit_height
/ 2,
115 pass
= piglit_probe_rect_rgba(0, piglit_height
/2,
116 piglit_width
/ 2, piglit_height
/ 2,
119 pass
= piglit_probe_rect_rgba(piglit_width
/ 2, piglit_height
/2,
120 piglit_width
/ 2, piglit_height
/ 2,
124 piglit_present_results();
126 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
130 piglit_init(int argc
, char **argv
)
132 static const GLuint indices
[] = { 0, 1, 2, 3 };
133 static const GLfloat verts
[] = {
134 /* These vertices should never be accessed due to the way
135 * glDrawArraysIndirect and glDrawElementsIndirect are called.
163 GLuint prog
= piglit_build_simple_program(
166 "in vec4 piglit_vertex;\n"
169 "const vec3 colors[] = vec3[](\n"
196 " c = colors[gl_VertexID];\n"
197 " gl_Position = piglit_vertex;\n"
202 "out vec4 fragcolor;\n"
205 " fragcolor = vec4(c, 1);\n"
211 piglit_require_extension("GL_ARB_draw_indirect");
213 use_arrays
= (argc
< 2 || strcmp(argv
[1], "elements") != 0);
214 printf("Using glDraw%sIndirect...\n",
215 use_arrays
? "Arrays" : "Elements");
219 glGenVertexArrays(1, &vao
);
220 glBindVertexArray(vao
);
222 glGenBuffers(ARRAY_SIZE(buf
), buf
);
223 glBindBuffer(GL_ARRAY_BUFFER
, buf
[0]);
224 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
,
227 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, buf
[1]);
228 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, sizeof(indices
), indices
,
231 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, 0, (void *) 0);
232 glEnableVertexAttribArray(0);
235 glBindBuffer(GL_DRAW_INDIRECT_BUFFER
, buf
[2]);
236 glBufferData(GL_DRAW_INDIRECT_BUFFER
,
237 sizeof(arrays_commands
),
241 glBindBuffer(GL_DRAW_INDIRECT_BUFFER
, buf
[2]);
242 glBufferData(GL_DRAW_INDIRECT_BUFFER
,
243 sizeof(elements_commands
),