2 * Copyright © 2011 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 DEALINGS
24 /** @file negative-prims.c
26 * Tests that glBeginTransformFeedback emits errors when attempting to
27 * draw primitives other than those allowed by the current transform
28 * feedback primitiveMode.
30 * From the EXT_transform_feedback spec:
32 * "The error INVALID_OPERATION is generated if Begin, or any
33 * command that performs an explicit Begin, is called when:
35 * * a geometry shader is not active and <mode> does not match
36 * the allowed begin modes for the current transform feedback
37 * state as given by table X.1."
39 * (the test also executes primitives that should pass, to ensure that
40 * the test is correctly generating GL errors just due to the bad
44 #include "piglit-util-gl.h"
46 PIGLIT_GL_TEST_CONFIG_BEGIN
48 config
.supports_gl_compat_version
= 10;
50 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
51 config
.khr_no_error_support
= PIGLIT_HAS_ERRORS
;
53 PIGLIT_GL_TEST_CONFIG_END
59 { GL_POINTS
, GL_POINTS
},
60 { GL_LINES
, GL_LINES
},
61 { GL_LINES
, GL_LINE_STRIP
},
62 { GL_LINES
, GL_LINE_LOOP
},
63 { GL_TRIANGLES
, GL_TRIANGLES
},
64 { GL_TRIANGLES
, GL_TRIANGLE_STRIP
},
65 { GL_TRIANGLES
, GL_TRIANGLE_FAN
},
66 { GL_TRIANGLES
, GL_QUADS
},
67 { GL_TRIANGLES
, GL_QUAD_STRIP
},
68 { GL_TRIANGLES
, GL_POLYGON
},
72 test_one_prim(GLenum tf_prim
, int i
)
75 const char *prim_name
= piglit_get_prim_name(prims
[i
].prim
);
76 const char *tf_name
= piglit_get_prim_name(tf_prim
);
78 glDrawArrays(prims
[i
].prim
, 0, 4);
81 if (prims
[i
].tf_prim
!= tf_prim
) {
82 if (error
!= GL_INVALID_OPERATION
) {
83 printf("Expected GL error 0x%x, got 0x%x, when "
84 "rendering %s during %s transform feedback\n",
85 GL_INVALID_OPERATION
, error
,
91 printf("Unexpected GL error 0x%x when "
92 "rendering %s during %s transform feedback\n",
102 test_transform_feedback_prim(GLenum tf_prim
)
107 glBeginTransformFeedbackEXT(tf_prim
);
108 for (i
= 0; i
< ARRAY_SIZE(prims
); i
++) {
109 pass
= pass
&& test_one_prim(tf_prim
, i
);
111 glEndTransformFeedbackEXT();
121 pass
= pass
&& test_transform_feedback_prim(GL_POINTS
);
122 pass
= pass
&& test_transform_feedback_prim(GL_LINES
);
123 pass
= pass
&& test_transform_feedback_prim(GL_TRIANGLES
);
125 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
131 static const char *vs_source
=
134 " gl_Position = gl_Vertex;\n"
137 static const char *fs_source
=
140 " gl_FragColor = vec4(0.0, 1.0, 0.0, 0.0);\n"
144 piglit_init(int argc
, char **argv
)
152 GLuint vbo
, xfb
, vs
, fs
, prog
;
153 const char *varying
= "gl_Position";
155 piglit_require_extension("GL_EXT_transform_feedback");
157 piglit_require_gl_version(30);
158 piglit_require_transform_feedback();
160 glGenBuffersARB(1, &vbo
);
161 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, vbo
);
162 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, 8 * sizeof(float),
163 verts
, GL_DYNAMIC_DRAW
);
165 glGenBuffersARB(1, &xfb
);
166 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, xfb
);
167 glBufferDataARB(GL_TRANSFORM_FEEDBACK_BUFFER
, 4096, NULL
,
170 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vs_source
);
171 fs
= piglit_compile_shader_text(GL_FRAGMENT_SHADER
, fs_source
);
172 prog
= glCreateProgram();
173 glAttachShader(prog
, vs
);
174 glAttachShader(prog
, fs
);
175 glTransformFeedbackVaryings(prog
, 1, &varying
, GL_INTERLEAVED_ATTRIBS
);
177 if (!fs
|| !vs
|| !prog
)
178 piglit_report_result(PIGLIT_FAIL
);
179 if (!piglit_link_check_status(prog
))
180 piglit_report_result(PIGLIT_FAIL
);
183 glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER
, 0, xfb
, 0, 4096);