ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / gl-3.2 / basevertex-vertexid.c
blob9094800f12a3da1ef9956b3025401398c2b9aa6f
1 /* Copyright © 2014 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 /** @file basevertex-vertexid.c
24 * Test using gl_VertexID in conjunction with glMultiDrawElementsBaseVertex.
26 * The value of gl_VertexID observed in the shader should be the value
27 * retrieved from the index buffer plus the value of basevertex.
30 #include "piglit-util-gl.h"
32 PIGLIT_GL_TEST_CONFIG_BEGIN
34 config.supports_gl_core_version = 32;
35 config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
36 config.khr_no_error_support = PIGLIT_NO_ERRORS;
38 PIGLIT_GL_TEST_CONFIG_END
40 static const float green[] = { 0, 1, 0, 1 };
41 static const float blue[] = { 0, 0, 1, 1 };
42 static const float gold[] = { 1, 1, 0, 1 };
43 static const float magenta[] = { 1, 0, 1, 1 };
45 enum piglit_result
46 piglit_display(void)
48 bool pass = true;
49 static const GLsizei count[] = { 4, 4, 4, 4 };
50 static const void *indices[ARRAY_SIZE(count)] = { 0, 0, 0, 0 };
51 static const GLint base[ARRAY_SIZE(count)] = { 4, 8, 12, 16 };
53 glViewport(0, 0, piglit_width, piglit_height);
54 glClearColor(0.2, 0.2, 0.2, 0.2);
55 glClear(GL_COLOR_BUFFER_BIT);
57 glMultiDrawElementsBaseVertex(GL_TRIANGLE_FAN,
58 count,
59 GL_UNSIGNED_INT,
60 indices,
61 ARRAY_SIZE(indices),
62 base);
64 pass = piglit_probe_rect_rgba(0, 0,
65 piglit_width / 2, piglit_height /2,
66 green)
67 && pass;
68 pass = piglit_probe_rect_rgba(piglit_width / 2, 0,
69 piglit_width / 2, piglit_height / 2,
70 blue)
71 && pass;
72 pass = piglit_probe_rect_rgba(0, piglit_height /2,
73 piglit_width / 2, piglit_height / 2,
74 gold)
75 && pass;
76 pass = piglit_probe_rect_rgba(piglit_width / 2, piglit_height /2,
77 piglit_width / 2, piglit_height / 2,
78 magenta)
79 && pass;
81 piglit_present_results();
83 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
86 void
87 piglit_init(int argc, char **argv)
89 static const GLuint indices[] = { 0, 1, 2, 3 };
90 static const GLfloat verts[] = {
91 /* These vertices should never be accessed due to the way
92 * glDrawElementsBaseVertex is called.
94 -1.0, -1.0,
95 1.0, -1.0,
96 1.0, 1.0,
97 -1.0, 1.0,
99 -1.0, -1.0,
100 0.0, -1.0,
101 0.0, 0.0,
102 -1.0, 0.0,
104 0.0, -1.0,
105 1.0, -1.0,
106 1.0, 0.0,
107 0.0, 0.0,
109 -1.0, 0.0,
110 0.0, 0.0,
111 0.0, 1.0,
112 -1.0, 1.0,
114 0.0, 0.0,
115 1.0, 0.0,
116 1.0, 1.0,
117 0.0, 1.0,
120 GLuint prog = piglit_build_simple_program(
121 "#version 140\n"
122 "\n"
123 "in vec4 piglit_vertex;\n"
124 "out vec3 c;\n"
125 "\n"
126 "const vec3 colors[] = vec3[](\n"
127 " vec3(1, 0, 0),\n"
128 " vec3(1, 0, 0),\n"
129 " vec3(1, 0, 0),\n"
130 " vec3(1, 0, 0),\n"
131 "\n"
132 " vec3(0, 1, 0),\n"
133 " vec3(0, 1, 0),\n"
134 " vec3(0, 1, 0),\n"
135 " vec3(0, 1, 0),\n"
136 "\n"
137 " vec3(0, 0, 1),\n"
138 " vec3(0, 0, 1),\n"
139 " vec3(0, 0, 1),\n"
140 " vec3(0, 0, 1),\n"
141 "\n"
142 " vec3(1, 1, 0),\n"
143 " vec3(1, 1, 0),\n"
144 " vec3(1, 1, 0),\n"
145 " vec3(1, 1, 0),\n"
146 "\n"
147 " vec3(1, 0, 1),\n"
148 " vec3(1, 0, 1),\n"
149 " vec3(1, 0, 1),\n"
150 " vec3(1, 0, 1)\n"
151 ");\n"
152 "void main() {\n"
153 " c = colors[gl_VertexID];\n"
154 " gl_Position = piglit_vertex;\n"
155 "}\n",
157 "#version 140\n"
158 "in vec3 c;\n"
159 "out vec4 fragcolor;\n"
160 "\n"
161 "void main() {\n"
162 " fragcolor = vec4(c, 1);\n"
163 "}\n");
165 GLuint vao;
166 GLuint buf[2];
168 glUseProgram(prog);
170 glGenVertexArrays(1, &vao);
171 glBindVertexArray(vao);
173 glGenBuffers(2, buf);
174 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf[0]);
175 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices,
176 GL_STATIC_DRAW);
178 glBindBuffer(GL_ARRAY_BUFFER, buf[1]);
179 glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts,
180 GL_STATIC_DRAW);
182 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void *) 0);
183 glEnableVertexAttribArray(0);