2 * Copyright © 2015 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.
27 * Basic test for gl_DrawIDARB.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config
.supports_gl_core_version
= 31;
35 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
37 PIGLIT_GL_TEST_CONFIG_END
39 static const char vs_template
[] =
41 "#extension GL_ARB_shader_draw_parameters: require\n"
43 "in vec4 piglit_vertex;\n"
49 " gl_Position = piglit_vertex;\n"
51 " color = vec4(0, 1, 0, 1);\n"
53 " color = vec4(1, 0, 0, 1);\n"
56 static const char fs_text
[] =
63 " gl_FragColor = color;\n"
67 piglit_init(int argc
, char **argv
)
72 if (strcmp(argv
[1], "drawid") == 0) {
73 (void)!asprintf(&vs_text
, vs_template
,
74 "ref.x == gl_DrawIDARB");
75 } else if (strcmp(argv
[1], "vertexid") == 0) {
76 (void)!asprintf(&vs_text
, vs_template
,
77 "ref.x == gl_DrawIDARB && ref.y == gl_VertexID");
79 printf("Unknown subtest: %s\n", argv
[1]);
80 piglit_report_result(PIGLIT_FAIL
);
83 piglit_require_extension("GL_ARB_shader_draw_parameters");
84 piglit_require_extension("GL_ARB_base_instance");
86 prog
= piglit_build_simple_program(vs_text
, fs_text
);
88 glBindAttribLocation(prog
, 1, (const GLchar
*) "ref");
99 float vertex_array
[16];
100 int reference_array
[16];
127 const int indices
[12] = {
135 float green
[] = {0, 1, 0, 1};
138 glGenVertexArrays(1, &vao
);
139 glBindVertexArray(vao
);
141 glGenBuffers(1, &vbo
);
142 glBindBuffer(GL_ARRAY_BUFFER
, vbo
);
143 glBufferData(GL_ARRAY_BUFFER
, sizeof(geometry
), &geometry
, GL_STATIC_DRAW
);
145 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
,
147 (void *) ((char *) &geometry
.vertex_array
- (char *) &geometry
));
149 glVertexAttribIPointer(1, 2, GL_UNSIGNED_INT
,
151 (void *) ((char *) &geometry
.reference_array
- (char *) &geometry
));
153 /* Enable the attributes */
154 glEnableVertexAttribArray(0);
155 glEnableVertexAttribArray(1);
157 static const GLsizei counts
[4] = { 6, 0, 6, 0 };
158 const int *indices_array
[4] = { &indices
[0], &indices
[0], &indices
[6], &indices
[6] };
160 glMultiDrawElements(GL_TRIANGLES
,
163 (const void **) indices_array
,
166 pass
= piglit_probe_rect_rgba(0, 0, piglit_width
, piglit_height
,
169 piglit_present_results();
171 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;