2 * Copyright © 2013 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 multi-draw-elements-base-vertex.c
26 * Section 2.8.2(Vertex Arrays) From GL spec 3.2 core:
27 * glMultiDrawElementsBaseVertex was added.
30 * (0)-------(1) Set up indices for quad 1 and 3.
32 * (2)-------(3) Use a basevertex of 2 to shift
33 * | 2 | indices from quad 1 to 2 and
34 * (4)-------(5) from quad 3 to 4
36 * (6)-------(7) End result 1 and 3 should be
37 * | 4 | blue while 2 and 4 are green.
41 * MultiDrawElementsBaseVertex behaves identically to
42 * DrawElementsBaseVertex, except that primcount separate
43 * lists of elements are specified instead. It has the
46 * for (int i = 0; i < primcount ; i++)
48 * DrawElementsBaseVertex(mode, count[i], type,
49 * indices[i], basevertex[i]);
53 #include "piglit-util-gl.h"
55 PIGLIT_GL_TEST_CONFIG_BEGIN
57 config
.supports_gl_compat_version
= 10;
59 config
.window_width
= 200;
60 config
.window_height
= 200;
61 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
62 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
64 PIGLIT_GL_TEST_CONFIG_END
66 const char *vs_source
= {
70 " gl_Position = vec4(vertex.xy, 0, 1);\n"
74 const char *fs_source
= {
77 " gl_FragColor = vec4(0, 1, 0, 1);\n"
82 static GLuint vertexBuffer
;
83 static GLuint indexBuffer
;
88 static GLfloat vertices
[] = {
100 static GLsizei vertices_size
= sizeof(vertices
);
102 static GLuint indices
[] = {
103 0, 1, 2, 1, 2, 3, /* top square */
104 4, 5, 6, 5, 6, 7, /* bot square */
106 static GLsizei indices_size
= sizeof(indices
);
108 static const uintptr_t indices_offset
[] = {
109 0, 6 * sizeof(GLuint
)
111 static GLsizei indices_count
[] = {
115 static GLint basevertex
[] = { 2, 2 };
116 static bool indirect
;
119 piglit_init(int argc
, char **argv
)
121 for (int i
= 1; i
< argc
; i
++) {
122 if (strcmp(argv
[i
], "-indirect") == 0) {
123 piglit_require_extension("GL_ARB_multi_draw_indirect");
124 puts("Testing GL_ARB_multi_draw_indirect");
132 piglit_require_GLSL_version(130);
134 if (piglit_get_gl_version() < 32) {
135 piglit_require_extension("GL_ARB_draw_elements_base_vertex");
139 program
= piglit_build_simple_program(vs_source
, fs_source
);
140 glUseProgram(program
);
142 /* Retrieve index from vs */
143 vertex_index
= glGetAttribLocation(program
, "vertex");
144 glEnableVertexAttribArray(vertex_index
);
146 /* Gen vertex array buffer */
148 /* Use non-VBO attributes to test this codepath. */
149 glVertexAttribPointer(vertex_index
, 2, GL_FLOAT
, GL_FALSE
, 0, vertices
);
151 glGenBuffers(1, &vertexBuffer
);
152 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuffer
);
153 glBufferData(GL_ARRAY_BUFFER
, vertices_size
, vertices
, GL_STATIC_DRAW
);
155 glVertexAttribPointer(vertex_index
, 2, GL_FLOAT
, GL_FALSE
, 0, 0);
158 /* Gen indices array buffer */
159 glGenBuffers(1, &indexBuffer
);
160 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuffer
);
161 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, indices_size
,
162 indices
, GL_STATIC_DRAW
);
164 if(!piglit_check_gl_error(GL_NO_ERROR
))
165 piglit_report_result(PIGLIT_FAIL
);
172 float green
[] = {0, 1, 0};
173 float blue
[] = {0, 0, 1};
175 glClearColor(blue
[0], blue
[1], blue
[2], 1.0);
176 glClear(GL_COLOR_BUFFER_BIT
);
178 glBindVertexArray(vao
);
179 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuffer
);
182 unsigned data
[2 * 5];
184 for (unsigned i
= 0; i
< 2; i
++) {
185 data
[i
*5+0] = indices_count
[i
];
187 data
[i
*5+2] = indices_offset
[i
] / sizeof(GLuint
);
188 data
[i
*5+3] = basevertex
[i
];
193 glGenBuffers(1, &ib
);
194 glBindBuffer(GL_DRAW_INDIRECT_BUFFER
, ib
);
195 glBufferData(GL_DRAW_INDIRECT_BUFFER
, sizeof(data
), data
,
198 glMultiDrawElementsIndirect(GL_TRIANGLES
, GL_UNSIGNED_INT
, NULL
, 2, 0);
199 glDeleteBuffers(1, &ib
);
201 glMultiDrawElementsBaseVertex(GL_TRIANGLES
, indices_count
,
202 GL_UNSIGNED_INT
, (GLvoid
*)indices_offset
,
206 /* Check for test pass */
207 pass
= piglit_probe_pixel_rgb(100, 175, blue
) && pass
;
208 pass
= piglit_probe_pixel_rgb(100, 125, green
) && pass
;
209 pass
= piglit_probe_pixel_rgb(100, 75, blue
) && pass
;
210 pass
= piglit_probe_pixel_rgb(100, 25, green
) && pass
;
212 if(!piglit_check_gl_error(GL_NO_ERROR
))
215 piglit_present_results();
217 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;