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
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
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 };
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
,
64 pass
= piglit_probe_rect_rgba(0, 0,
65 piglit_width
/ 2, piglit_height
/2,
68 pass
= piglit_probe_rect_rgba(piglit_width
/ 2, 0,
69 piglit_width
/ 2, piglit_height
/ 2,
72 pass
= piglit_probe_rect_rgba(0, piglit_height
/2,
73 piglit_width
/ 2, piglit_height
/ 2,
76 pass
= piglit_probe_rect_rgba(piglit_width
/ 2, piglit_height
/2,
77 piglit_width
/ 2, piglit_height
/ 2,
81 piglit_present_results();
83 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
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.
120 GLuint prog
= piglit_build_simple_program(
123 "in vec4 piglit_vertex;\n"
126 "const vec3 colors[] = vec3[](\n"
153 " c = colors[gl_VertexID];\n"
154 " gl_Position = piglit_vertex;\n"
159 "out vec4 fragcolor;\n"
162 " fragcolor = vec4(c, 1);\n"
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
,
178 glBindBuffer(GL_ARRAY_BUFFER
, buf
[1]);
179 glBufferData(GL_ARRAY_BUFFER
, sizeof(verts
), verts
,
182 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, 0, (void *) 0);
183 glEnableVertexAttribArray(0);