fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / spec / oes_draw_elements_base_vertex / drawrangeelements.c
blob4c7573b2ca3f6105c955bd43c5acb5089238b6a7
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.
23 #include "piglit-util-gl.h"
25 PIGLIT_GL_TEST_CONFIG_BEGIN
27 config.supports_gl_es_version = 30;
29 config.window_width = 200;
30 config.window_height = 200;
31 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
33 PIGLIT_GL_TEST_CONFIG_END
35 const char *vs_source = {
36 "#version 300 es\n"
37 "in vec2 vertex;\n"
38 "void main() {\n"
39 " gl_Position = vec4(vertex.xy, 0, 1);\n"
40 "}\n"
43 const char *fs_source = {
44 "#version 300 es\n"
45 "out highp vec4 ocol;\n"
46 "void main() {\n"
47 " ocol = vec4(0, 1, 0, 1);\n"
48 "}\n"
51 static GLuint vao;
52 static GLuint vertexBuffer;
53 static GLuint indexBuffer;
55 /* sets of two (x,y) */
56 static GLfloat vertices[] = {
57 -1.0, 1.0,
58 1.0, 1.0,
59 -1.0, 0.5,
60 1.0, 0.5,
61 -1.0, 0.0,
62 1.0, 0.0,
63 -1.0,-0.5,
64 1.0,-0.5,
65 -1.0,-1.0,
66 1.0,-1.0
68 static GLsizei vertices_size = sizeof(vertices);
70 static GLushort indices[] = {
71 0, 1, 2, 1, 2, 3, /* Top Quad */
72 4, 5, 6, 5, 6, 7, /* Bot Quad */
74 static GLsizei indices_size = sizeof(indices);
76 void
77 piglit_init(int argc, char **argv)
79 GLuint program;
80 GLuint vertex_index;
82 piglit_require_extension("GL_OES_draw_elements_base_vertex");
84 /* Create program */
85 program = piglit_build_simple_program(vs_source, fs_source);
86 glUseProgram(program);
88 /* Gen vertex array buffer */
89 glGenBuffers(1, &vertexBuffer);
90 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
91 glBufferData(GL_ARRAY_BUFFER, vertices_size, vertices, GL_STATIC_DRAW);
93 /* Gen indices array buffer */
94 glGenBuffers(1, &indexBuffer);
95 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
96 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_size,
97 indices, GL_STATIC_DRAW);
99 /* Gen VAO */
100 glGenVertexArrays(1, &vao);
101 glBindVertexArray(vao);
103 /* Retrieve indices from vs */
104 vertex_index = glGetAttribLocation(program, "vertex");
106 /* Enable vertex attrib array */
107 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
108 glEnableVertexAttribArray(vertex_index);
109 glVertexAttribPointer(vertex_index, 2, GL_FLOAT, GL_FALSE, 0, 0);
112 enum piglit_result
113 piglit_display(void)
115 bool pass = true;
117 float green[] = {0, 1, 0, 1};
118 float blue[] = {0, 0, 1, 1};
120 glClearColor(blue[0], blue[1], blue[2], 1.0);
121 glClear(GL_COLOR_BUFFER_BIT);
123 glBindVertexArray(vao);
124 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
126 /* Top Quad */
127 glDrawRangeElementsBaseVertexOES(GL_TRIANGLES, 0, 3, 6, GL_UNSIGNED_SHORT,
128 NULL, 0);
130 /* Bot Quad */
131 glDrawRangeElementsBaseVertexOES(GL_TRIANGLES, 4, 7, 6, GL_UNSIGNED_SHORT,
132 (GLvoid *)(sizeof(GLushort)*6), 2);
134 /* Check for test pass */
135 pass = piglit_probe_pixel_rgba(100, 175, green) && pass;
136 pass = piglit_probe_pixel_rgba(100, 125, blue) && pass;
137 pass = piglit_probe_pixel_rgba(100, 75, blue) && pass;
138 pass = piglit_probe_pixel_rgba(100, 25, green) && pass;
140 piglit_present_results();
142 return pass ? PIGLIT_PASS : PIGLIT_FAIL;