1 /* Copyright © 2009 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 /* Tests OES_draw_elements_base_vertex functionality by drawing a checkerboard
25 * of quads using different base vertices using the same vertex and
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_es_version
= 20;
35 config
.window_width
= 300;
36 config
.window_height
= 300;
37 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
39 PIGLIT_GL_TEST_CONFIG_END
42 const GLfloat inc_amount
= 2.0 / NUM_QUADS
;
43 const int window_width
= 300;
44 const int window_height
= 300;
46 const char *vs_source
= {
48 "attribute vec2 vertex;\n"
50 " gl_Position = vec4(vertex.xy, 0, 1);\n"
54 const char *fs_source
= {
57 " gl_FragColor = vec4(1, 1, 1, 1);\n"
61 static GLushort indices
[] = {
64 static GLsizei indices_size
= sizeof(indices
);
67 static GLuint vertexBuffer
;
68 static GLuint indexBuffer
;
71 piglit_init(int argc
, char **argv
)
73 piglit_require_extension("GL_OES_draw_elements_base_vertex");
78 GLfloat
* vertices
= malloc(4 * 2 * NUM_QUADS
* sizeof(GLfloat
));
79 GLsizei vertices_size
= 4 * 2 * NUM_QUADS
* sizeof(GLfloat
);
81 // Generate a checkerboard pattern
85 for (i
= 0; i
< NUM_QUADS
; ++i
)
87 GLfloat xoffset
, yoffset
;
90 xoffset
= inc_amount
* i
- 1.0;
91 yoffset
= i
% 2 ? 0.0 : 1.0;
98 x
[1] = xoffset
+ inc_amount
;
103 y
[2] = yoffset
- 1.0;
106 x
[3] = xoffset
+ inc_amount
;
107 y
[3] = yoffset
- 1.0;
109 vertices
[i
* 8 + 0] = x
[0];
110 vertices
[i
* 8 + 1] = y
[0];
112 vertices
[i
* 8 + 2] = x
[1];
113 vertices
[i
* 8 + 3] = y
[1];
115 vertices
[i
* 8 + 4] = x
[2];
116 vertices
[i
* 8 + 5] = y
[2];
118 vertices
[i
* 8 + 6] = x
[3];
119 vertices
[i
* 8 + 7] = y
[3];
123 program
= piglit_build_simple_program(vs_source
, fs_source
);
124 glUseProgram(program
);
126 /* Gen vertex array buffer */
127 glGenBuffers(1, &vertexBuffer
);
128 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuffer
);
129 glBufferData(GL_ARRAY_BUFFER
, vertices_size
, vertices
, GL_STATIC_DRAW
);
131 /* Gen indices array buffer */
132 glGenBuffers(1, &indexBuffer
);
133 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuffer
);
134 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, indices_size
,
135 indices
, GL_STATIC_DRAW
);
138 glGenVertexArrays(1, &vao
);
139 glBindVertexArray(vao
);
141 /* Retrieve indices from vs */
142 vertex_index
= glGetAttribLocation(program
, "vertex");
144 /* Enable vertex attrib array */
145 glBindBuffer(GL_ARRAY_BUFFER
, vertexBuffer
);
146 glEnableVertexAttribArray(vertex_index
);
147 glVertexAttribPointer(vertex_index
, 2, GL_FLOAT
, GL_FALSE
, 0, 0);
153 GLboolean pass
= GL_TRUE
;
154 float white
[] = {1.0, 1.0, 1.0, 1.0};
157 glClear(GL_COLOR_BUFFER_BIT
);
159 glBindVertexArray(vao
);
160 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, indexBuffer
);
162 for (i
= 0; i
< NUM_QUADS
; ++i
)
163 glDrawElementsBaseVertexOES(GL_TRIANGLES
, 6, GL_UNSIGNED_SHORT
, NULL
, i
* 4);
165 for (i
= 0; i
< NUM_QUADS
; ++i
)
167 GLfloat xoffset
[2], yoffset
[2];
169 xoffset
[0] = inc_amount
* i
/ 2.0 * window_width
;
170 xoffset
[1] = inc_amount
* (i
+ 1) / 2.0 * window_width
;
171 yoffset
[0] = (i
% 2 ? 0.0 : 0.5) * window_height
;
172 yoffset
[1] = yoffset
[0] + window_height
/ 2;
174 pass
= piglit_probe_rect_rgba(xoffset
[0], yoffset
[0],
175 xoffset
[1] - xoffset
[0], yoffset
[1] - yoffset
[0], white
) && pass
;
178 piglit_present_results();
180 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;