2 * Copyright © 2012 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
25 * \file cannot-bind-when-active.c
27 * The ARB_transform_feedback2 spec says:
29 * "The error INVALID_OPERATION is generated by BindTransformFeedback if
30 * the transform feedback operation is active on the currently bound
31 * transform feedback object, and that operation is not paused (as
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
51 static const char vstext
[] =
52 "varying vec4 x; void main() { gl_Position = vec4(0); x = vec4(0); }";
54 void piglit_init(int argc
, char **argv
)
61 static const char *varyings
[] = {"x"};
63 piglit_require_vertex_shader();
64 piglit_require_transform_feedback();
65 piglit_require_extension("GL_ARB_transform_feedback2");
67 /* This is all just the boot-strap work for the test.
69 glGenBuffers(1, &buf
);
70 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, buf
);
71 glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER
, 1024, NULL
, GL_STREAM_READ
);
73 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vstext
);
74 prog
= glCreateProgram();
75 glAttachShader(prog
, vs
);
77 glTransformFeedbackVaryings(prog
, 1, varyings
,
78 GL_INTERLEAVED_ATTRIBS
);
80 if (!piglit_link_check_status(prog
)) {
87 glGenTransformFeedbacks(2, ids
);
89 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[0]);
90 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER
, 0, buf
);
92 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[1]);
93 glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER
, 0, buf
);
95 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, 0);
97 /* Bind the first object and make it active. Try to bind the other
98 * object. This should fail.
100 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[0]);
101 glBeginTransformFeedback(GL_TRIANGLES
);
103 pass
= piglit_check_gl_error(0) && pass
;
105 if (!piglit_khr_no_error
) {
106 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[1]);
107 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
110 /* Make the transform feedback object inactive by calling
111 * EndTransformFeedback. Then try (again) to bind the other object.
112 * This should just work.
114 glEndTransformFeedback();
115 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[1]);
116 pass
= piglit_check_gl_error(0) && pass
;
118 /* Make the second object active, and pause it. Try rebinding the
119 * first object. This should also just work.
121 glBeginTransformFeedback(GL_TRIANGLES
);
122 glPauseTransformFeedback();
124 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[0]);
125 pass
= piglit_check_gl_error(0) && pass
;
127 /* Rebind the second object, and resume it. This will make it active.
128 * Re-rebind the first object. This should fail.
130 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[1]);
131 pass
= piglit_check_gl_error(0) && pass
;
133 glResumeTransformFeedback();
134 pass
= piglit_check_gl_error(0) && pass
;
136 if (!piglit_khr_no_error
) {
137 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, ids
[0]);
138 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
141 /* Make the second object non-active, and restore the default object.
144 glEndTransformFeedback();
145 glBindTransformFeedback(GL_TRANSFORM_FEEDBACK
, 0);
146 pass
= piglit_check_gl_error(0) && pass
;
149 glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER
, 0);
150 glDeleteBuffers(1, &buf
);
152 glDeleteTransformFeedbacks(2, ids
);
156 glDeleteProgram(prog
);
158 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);