1 /* Copyright © 2013 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
26 * (0)-------(1) Set up indices for quad 1 and 3.
28 * (2)-------(3) Use a basevertex of 2 to shift
29 * | 2 | indices from quad 1 to 2 and
30 * (4)-------(5) from quad 3 to 4
32 * (6)-------(7) End result 1 and 3 should be
33 * | 4 | blue while 2 and 4 are green.
37 * MultiDrawElementsBaseVertex behaves identically to
38 * DrawElementsBaseVertex, except that primcount separate
39 * lists of elements are specified instead. It has the
42 * for (int i = 0; i < primcount ; i++)
44 * DrawElementsBaseVertex(mode, count[i], type,
45 * indices[i], basevertex[i]);
49 #include "piglit-util-gl.h"
51 PIGLIT_GL_TEST_CONFIG_BEGIN
53 config
.supports_gl_es_version
= 20;
55 config
.window_width
= 200;
56 config
.window_height
= 200;
57 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
59 PIGLIT_GL_TEST_CONFIG_END
61 const char *vs_source
= {
63 "attribute vec2 vertex;\n"
65 " gl_Position = vec4(vertex.xy, 0, 1);\n"
69 const char *fs_source
= {
72 " gl_FragColor = vec4(0, 1, 0, 1);\n"
76 static GLuint vertexBuffer
;
77 static GLuint indexBuffer
;
82 static GLfloat vertices
[] = {
94 static GLsizei vertices_size
= sizeof(vertices
);
96 static GLushort indices
[] = {
97 0, 1, 2, 1, 2, 3, /* top square */
98 4, 5, 6, 5, 6, 7, /* bot square */
100 static GLsizei indices_size
= sizeof(indices
);
102 static const GLvoid
* const indices_offset
[] = {
103 (GLvoid
*) 0, (GLvoid
*)(6 * sizeof(GLushort
))
105 static GLsizei indices_count
[] = {
109 static GLint basevertex
[] = { 2, 2 };
112 piglit_init(int argc
, char **argv
)
117 piglit_require_extension("GL_OES_draw_elements_base_vertex");
118 piglit_require_extension("GL_EXT_multi_draw_arrays");
121 program
= piglit_build_simple_program(vs_source
, fs_source
);
122 glUseProgram(program
);
124 /* Gen vertex array buffer */
125 glGenBuffers(1, &vertexBuffer
);
126 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuffer
);
127 glBufferData(GL_ARRAY_BUFFER
, vertices_size
, vertices
, GL_STATIC_DRAW
);
129 /* Gen indices array buffer */
130 glGenBuffers(1, &indexBuffer
);
131 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuffer
);
132 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, indices_size
,
133 indices
, GL_STATIC_DRAW
);
136 glGenVertexArrays(1, &vao
);
137 glBindVertexArray(vao
);
139 /* Retrieve indices from vs */
140 vertex_index
= glGetAttribLocation(program
, "vertex");
142 /* Enable vertex attrib array */
143 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuffer
);
144 glEnableVertexAttribArray(vertex_index
);
145 glVertexAttribPointer(vertex_index
, 2, GL_FLOAT
, GL_FALSE
, 0, 0);
153 float green
[] = {0, 1, 0, 1};
154 float blue
[] = {0, 0, 1, 1};
156 glClearColor(blue
[0], blue
[1], blue
[2], 1.0);
157 glClear(GL_COLOR_BUFFER_BIT
);
159 glBindVertexArray(vao
);
160 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuffer
);
162 glMultiDrawElementsBaseVertexEXT(GL_TRIANGLES
, indices_count
,
163 GL_UNSIGNED_SHORT
, (GLvoid
*)indices_offset
,
166 /* Check for test pass */
167 pass
= piglit_probe_pixel_rgba(100, 175, blue
) && pass
;
168 pass
= piglit_probe_pixel_rgba(100, 125, green
) && pass
;
169 pass
= piglit_probe_pixel_rgba(100, 75, blue
) && pass
;
170 pass
= piglit_probe_pixel_rgba(100, 25, green
) && pass
;
172 piglit_present_results();
174 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;