ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / oes_draw_elements_base_vertex / multidrawelements.c
blobf135cbb6104985a4357b8d1cfc8a405b6bc42065
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
12 * Software.
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
20 * IN THE SOFTWARE.
24 /**
26 * (0)-------(1) Set up indices for quad 1 and 3.
27 * | 1 |
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
31 * | 3 |
32 * (6)-------(7) End result 1 and 3 should be
33 * | 4 | blue while 2 and 4 are green.
34 * (8)-------(9)
37 * MultiDrawElementsBaseVertex behaves identically to
38 * DrawElementsBaseVertex, except that primcount separate
39 * lists of elements are specified instead. It has the
40 * same effect as:
42 * for (int i = 0; i < primcount ; i++)
43 * if (count[i] > 0)
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 = {
62 "#version 100\n"
63 "attribute vec2 vertex;\n"
64 "void main() {\n"
65 " gl_Position = vec4(vertex.xy, 0, 1);\n"
66 "}\n"
69 const char *fs_source = {
70 "#version 100\n"
71 "void main() {\n"
72 " gl_FragColor = vec4(0, 1, 0, 1);\n"
73 "}\n"
75 static GLuint vao;
76 static GLuint vertexBuffer;
77 static GLuint indexBuffer;
80 * sets of two (x,y)
82 static GLfloat vertices[] = {
83 -1.0, 1.0,
84 1.0, 1.0,
85 -1.0, 0.5,
86 1.0, 0.5,
87 -1.0, 0.0,
88 1.0, 0.0,
89 -1.0,-0.5,
90 1.0,-0.5,
91 -1.0,-1.0,
92 1.0,-1.0
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[] = {
106 6, 6
109 static GLint basevertex[] = { 2, 2 };
111 void
112 piglit_init(int argc, char **argv)
114 GLuint program;
115 GLuint vertex_index;
117 piglit_require_extension("GL_OES_draw_elements_base_vertex");
118 piglit_require_extension("GL_EXT_multi_draw_arrays");
120 /* Create program */
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);
135 /* Gen VAO */
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);
148 enum piglit_result
149 piglit_display(void)
151 bool pass = true;
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,
164 2, basevertex);
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;