2 * Copyright © 2013 The Piglit project
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
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
21 * DEALINGS IN THE SOFTWARE.
25 * \file ignore-adjacent-vertices.c
27 * Test that adjacent vertices are ignored when no geometry shader is active.
28 * Draw the adjacency primitive in red and blend the non adjacency version in
29 * green on top of it. Then test that the entire framebuffer is either yellow
32 * From the ARB_geometry_shader4 spec section 2.6.1:
33 * "If a geometry shader is not active, the "adjacent" vertices are ignored."
36 #include "piglit-util-gl.h"
41 unsigned short indices
[12];
44 static const struct primitives
{
45 struct primitive adjacency
, base
;
48 {GL_LINES_ADJACENCY
, 8,
49 {4, 5, 6, 7, 8, 9, 10, 11} },
54 {GL_LINE_STRIP_ADJACENCY
, 6,
55 {4, 5, 6, 10, 9, 8} },
60 {GL_TRIANGLES_ADJACENCY
, 12,
61 {9, 4, 5, 6, 10, 14, 6, 11, 10, 9, 5, 1} },
63 {9, 5, 10, 6, 10, 5} }
66 {GL_TRIANGLE_STRIP_ADJACENCY
, 8,
67 {9, 4, 5, 14, 10, 1, 6, 11} },
68 {GL_TRIANGLE_STRIP
, 4,
73 static const float vertex_data
[] = {
74 -1, 1, -1/3., 1, 1/3., 1, 1, 1,
75 0, 1/3., -1/3., 1/3., 1/3., 1/3., 1, 1/3.,
76 0, -1/3., -1/3., -1/3., 1/3., -1/3., 1, -1/3.,
77 0, 0, -1/3., 0, 1/3., 0, 1, 0,
80 static const char vs_text
[] =
81 "attribute vec4 vertex;\n"
84 " gl_Position = vertex;\n"
87 static const char fs_text
[] =
88 "uniform vec4 color;\n"
91 " gl_FragColor = color;\n"
94 static const struct primitives
*test
;
95 static bool indexed
= false;
96 static bool use_core
= false;
99 parse_cmd_line(int argc
, char **argv
);
101 PIGLIT_GL_TEST_CONFIG_BEGIN
102 parse_cmd_line(argc
, argv
);
104 config
.supports_gl_compat_version
= 20;
105 config
.supports_gl_core_version
= 31;
107 config
.supports_gl_compat_version
= 32;
108 config
.supports_gl_core_version
= 32;
110 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
111 PIGLIT_GL_TEST_CONFIG_END
113 GLuint color_uniform
;
115 /* Parse command line arguments.
117 * Recognized command line arguments are:
118 * * The primitive type with adjacency to test (one of GL_LINES_ADJACENCY,
119 * GL_LINE_STRIP_ADJACENCY, GL_TRIANGLES_ADJACENCY or
120 * GL_TRIANGLE_STRIP_ADJACENCY).
121 * * The optional argument "indexed" to use indexed drawing.
122 * * The optional argument "core" to use GLSL 1.50
125 parse_cmd_line(int argc
, char **argv
)
129 for (i
= 1; i
< argc
; i
++) {
130 for (j
= 0; j
< ARRAY_SIZE(tests
); j
++) {
132 piglit_get_prim_name(tests
[j
].adjacency
.type
)) == 0)
135 if (strcmp(argv
[i
], "indexed") == 0)
137 else if (strcmp(argv
[i
], "core") == 0)
142 fprintf(stderr
, "Please specify the adjacent primitive type "
143 "to test on the command line\n");
144 piglit_report_result(PIGLIT_FAIL
);
149 piglit_init(int argc
, char **argv
)
151 GLuint array_bufs
[2];
156 piglit_require_extension("GL_ARB_geometry_shader4");
158 /* Bind Vertex Data */
159 glGenVertexArrays(1, &array
);
160 glBindVertexArray(array
);
161 glGenBuffers(2, array_bufs
);
162 glBindBuffer(GL_ARRAY_BUFFER
, array_bufs
[0]);
164 glBufferData(GL_ARRAY_BUFFER
, sizeof(vertex_data
),
165 vertex_data
, GL_STREAM_DRAW
);
166 glVertexAttribPointer(0, 2, GL_FLOAT
, GL_FALSE
, 0, NULL
);
167 glEnableVertexAttribArray(0);
169 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER
, array_bufs
[1]);
172 prog
= piglit_build_simple_program(vs_text
, fs_text
);
173 glBindAttribLocation(prog
, 0, "vertex");
175 color_uniform
= glGetUniformLocation(prog
, "color");
178 /* Enable blending. */
180 glBlendEquation(GL_FUNC_ADD
);
181 glBlendFunc(GL_ONE
, GL_ONE
);
185 draw(const struct primitive prim
)
188 /* Upload index data and draw. */
189 glBufferData(GL_ELEMENT_ARRAY_BUFFER
, prim
.count
* 2,
190 prim
.indices
, GL_STREAM_DRAW
);
191 glDrawElements(prim
.type
, prim
.count
, GL_UNSIGNED_SHORT
, NULL
);
196 /* Build vertex data, upload it and draw. */
197 for (i
= 0; i
< prim
.count
; ++i
) {
198 data
[2 * i
+ 0] = vertex_data
[2 * prim
.indices
[i
] + 0];
199 data
[2 * i
+ 1] = vertex_data
[2 * prim
.indices
[i
] + 1];
201 glBufferData(GL_ARRAY_BUFFER
, prim
.count
* 2 * 4, data
,
203 glDrawArrays(prim
.type
, 0, prim
.count
);
211 const float black
[] = {0, 0, 0, 1};
212 const float red
[] = {1, 0, 0, 1};
213 const float green
[] = {0, 1, 0, 1};
214 const float yellow
[] = {1, 1, 0, 1};
216 glClear(GL_COLOR_BUFFER_BIT
);
218 /* Draw adjacency primitive red. */
219 glUniform4fv(color_uniform
, 1, red
);
220 draw(test
->adjacency
);
222 /* Draw normal primitive green. */
223 glUniform4fv(color_uniform
, 1, green
);
226 pass
= piglit_probe_rect_two_rgb(0, 0, piglit_width
, piglit_height
,
227 black
, yellow
) && pass
;
228 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
230 if (!piglit_automatic
)
231 piglit_present_results();
233 return (pass
? PIGLIT_PASS
: PIGLIT_FAIL
);