glsl-1.30: add more loop unroll tests
[piglit.git] / tests / spec / arb_draw_elements_base_vertex / drawrangeelements.c
blob1df970175238bf7d09f061101877d3af99564361
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /** @file draw-range-elements-base-vertex.c
26 * Section 2.8.2(Vertex Arrays) From GL spec 3.2 core:
27 * glDrawRangeElementsBaseVertex was added.
29 * For DrawRangeElementsBaseVertex, the index values must lie between start
30 * and end inclusive, prior to adding the basevertex offset. Index values
31 * lying outside the range [start, end] are treated in the same way as
32 * DrawRangeElements.
34 * It is an error for index values other than the primitive restart index
35 * to lie outside the range [start, end], but implementations are not
36 * required to check for this. Such indices will cause implementation-
37 * dependent behavior.
39 * (0)-------(1) Set up indices for quad 1 and 3.
40 * | 1 |
41 * (2)-------(3) Use a basevertex of 2 on quad 3
42 * | 2 | draw call to shift quad 3 to quad 4
43 * (4)-------(5)
44 * | 3 | End result quad 1 will be green and quad 2 blue.
45 * (6)-------(7) If index values are compared to start and end values
46 * | 4 | prior to adding basevertex quad 3 will be blue,
47 * (8)-------(9) while 4 will be green.
50 #include "piglit-util-gl.h"
52 PIGLIT_GL_TEST_CONFIG_BEGIN
54 config.supports_gl_compat_version = 10;
55 config.supports_gl_core_version = 31;
57 config.window_width = 200;
58 config.window_height = 200;
59 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
61 PIGLIT_GL_TEST_CONFIG_END
63 const char *vs_source = {
64 "#version 130\n"
65 "in vec2 vertex;\n"
66 "void main() {\n"
67 " gl_Position = vec4(vertex.xy, 0, 1);\n"
68 "}\n"
71 const char *fs_source = {
72 "#version 130\n"
73 "void main() {\n"
74 " gl_FragColor = vec4(0, 1, 0, 1);\n"
75 "}\n"
78 static GLuint vao;
79 static GLuint vertexBuffer;
80 static GLuint indexBuffer;
82 /* sets of two (x,y) */
83 static GLfloat vertices[] = {
84 -1.0, 1.0,
85 1.0, 1.0,
86 -1.0, 0.5,
87 1.0, 0.5,
88 -1.0, 0.0,
89 1.0, 0.0,
90 -1.0,-0.5,
91 1.0,-0.5,
92 -1.0,-1.0,
93 1.0,-1.0
95 static GLsizei vertices_size = sizeof(vertices);
97 static GLuint indices[] = {
98 0, 1, 2, 1, 2, 3, /* Top Quad */
99 4, 5, 6, 5, 6, 7, /* Bot Quad */
101 static GLsizei indices_size = sizeof(indices);
103 void
104 piglit_init(int argc, char **argv)
106 GLuint program;
107 GLuint vertex_index;
109 if (piglit_get_gl_version() < 32) {
110 piglit_require_extension("GL_ARB_draw_elements_base_vertex");
111 piglit_require_GLSL_version(130);
114 /* Create program */
115 program = piglit_build_simple_program(vs_source, fs_source);
116 glUseProgram(program);
118 /* Gen vertex array buffer */
119 glGenBuffers(1, &vertexBuffer);
120 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
121 glBufferData(GL_ARRAY_BUFFER, vertices_size, vertices, GL_STATIC_DRAW);
123 /* Gen indices array buffer */
124 glGenBuffers(1, &indexBuffer);
125 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
126 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_size,
127 indices, GL_STATIC_DRAW);
129 /* Gen VAO */
130 glGenVertexArrays(1, &vao);
131 glBindVertexArray(vao);
133 /* Retrieve indices from vs */
134 vertex_index = glGetAttribLocation(program, "vertex");
136 /* Enable vertex attrib array */
137 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
138 glEnableVertexAttribArray(vertex_index);
139 glVertexAttribPointer(vertex_index, 2, GL_FLOAT, GL_FALSE, 0, 0);
142 enum piglit_result
143 piglit_display(void)
145 bool pass = true;
147 float green[] = {0, 1, 0};
148 float blue[] = {0, 0, 1};
150 glClearColor(blue[0], blue[1], blue[2], 1.0);
151 glClear(GL_COLOR_BUFFER_BIT);
153 glBindVertexArray(vao);
154 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
156 /* Top Quad */
157 glDrawRangeElementsBaseVertex(GL_TRIANGLES, 0, 3, 6, GL_UNSIGNED_INT,
158 NULL, 0);
160 /* Bot Quad */
161 glDrawRangeElementsBaseVertex(GL_TRIANGLES, 4, 7, 6, GL_UNSIGNED_INT,
162 (GLvoid *)(sizeof(GLuint)*6), 2);
164 /* Check for test pass */
165 pass = piglit_probe_pixel_rgb(100, 175, green) && pass;
166 pass = piglit_probe_pixel_rgb(100, 125, blue) && pass;
167 pass = piglit_probe_pixel_rgb(100, 75, blue) && pass;
168 pass = piglit_probe_pixel_rgb(100, 25, green) && pass;
170 piglit_present_results();
172 return pass ? PIGLIT_PASS : PIGLIT_FAIL;