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
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.
24 /** @file vertices-in.c
26 * Check that the built-in geometry shader constant gl_VerticesIn has
27 * the correct value for all input primitive types.
29 * The test uses transform feedback to extract the value of
30 * gl_VerticesIn out of the shader.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 30;
38 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGB
;
40 PIGLIT_GL_TEST_CONFIG_END
42 static const char *vs_text
=
46 " gl_Position = vec4(0.0);\n"
49 static const char *gs_text
=
51 "#extension GL_ARB_geometry_shader4: require\n"
52 "out int vertices_in;\n"
55 " vertices_in = gl_VerticesIn;\n"
59 static const char *varyings
[] = { "vertices_in" };
67 { GL_LINES_ADJACENCY
, 4},
69 { GL_TRIANGLES_ADJACENCY
, 6}
73 piglit_init(int argc
, char **argv
)
75 GLuint vs
, gs
, prog
, buf
;
81 piglit_require_GLSL_version(130);
82 piglit_require_extension("GL_ARB_geometry_shader4");
83 piglit_require_extension("GL_EXT_transform_feedback");
85 /* Compile shaders, and prepare for linking. We don't link
86 * yet because we're going to need to change the input
87 * primitive type inside the "for" loop below.
89 prog
= glCreateProgram();
90 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_text
);
91 glAttachShader(prog
, vs
);
92 gs
= piglit_compile_shader_text(GL_GEOMETRY_SHADER
, gs_text
);
93 glAttachShader(prog
, gs
);
94 glProgramParameteriARB(prog
, GL_GEOMETRY_OUTPUT_TYPE_ARB
, GL_POINTS
);
95 glProgramParameteriARB(prog
, GL_GEOMETRY_VERTICES_OUT_ARB
, 1);
96 glTransformFeedbackVaryings(prog
, 1, varyings
,
97 GL_INTERLEAVED_ATTRIBS_EXT
);
99 /* Set up the transform feedback buffer. */
100 glGenBuffers(1, &buf
);
101 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
, 0, buf
);
102 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
, sizeof(GLint
), NULL
,
105 /* Use GL_RASTERIZER_DISCARD, since we are going to use
106 * transform feedback for this test.
108 glEnable(GL_RASTERIZER_DISCARD
);
110 if (!piglit_check_gl_error(GL_NO_ERROR
))
111 piglit_report_result(PIGLIT_FAIL
);
113 for (i
= 0; i
< ARRAY_SIZE(test_vectors
); i
++) {
114 printf("Testing %s:\n",
115 piglit_get_prim_name(test_vectors
[i
].prim_type
));
116 glProgramParameteriARB(prog
, GL_GEOMETRY_INPUT_TYPE_ARB
,
117 test_vectors
[i
].prim_type
);
119 if (!piglit_link_check_status(prog
))
120 piglit_report_result(PIGLIT_FAIL
);
121 if (!piglit_check_gl_error(GL_NO_ERROR
))
122 piglit_report_result(PIGLIT_FAIL
);
124 glBeginTransformFeedback(GL_POINTS
);
125 glDrawArrays(test_vectors
[i
].prim_type
, 0,
126 test_vectors
[i
].vertices_in
);
127 glEndTransformFeedback();
128 if (!piglit_check_gl_error(GL_NO_ERROR
))
129 piglit_report_result(PIGLIT_FAIL
);
130 ptr
= glMapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
,
132 printf(" Expected gl_VerticesIn = %d, got %d\n",
133 test_vectors
[i
].vertices_in
, *ptr
);
134 if (test_vectors
[i
].vertices_in
!= *ptr
)
136 glUnmapBuffer(GL_TRANSFORM_FEEDBACK_BUFFER_EXT
);
137 if (!piglit_check_gl_error(GL_NO_ERROR
))
138 piglit_report_result(PIGLIT_FAIL
);
141 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
148 /* Should never be reached */