1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.1 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Negative Vertex Array API tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es31fNegativeVertexArrayApiTests.hpp"
25 #include "gluCallLogWrapper.hpp"
26 #include "gluContextInfo.hpp"
27 #include "gluShaderProgram.hpp"
28 #include "glwDefs.hpp"
29 #include "glwEnums.hpp"
30 #include "tcuStringTemplate.hpp"
31 
32 namespace deqp
33 {
34 
35 using std::string;
36 using std::map;
37 
38 namespace gles31
39 {
40 namespace Functional
41 {
42 namespace NegativeTestShared
43 {
44 
45 using tcu::TestLog;
46 using glu::CallLogWrapper;
47 using namespace glw;
48 
49 static const char* vertexShaderSource		=	"${GLSL_VERSION_STRING}\n"
50 												"void main (void)\n"
51 												"{\n"
52 												"	gl_Position = vec4(0.0);\n"
53 												"}\n\0";
54 
55 static const char* fragmentShaderSource		=	"${GLSL_VERSION_STRING}\n"
56 												"layout(location = 0) out mediump vec4 fragColor;"
57 												"void main (void)\n"
58 												"{\n"
59 												"	fragColor = vec4(0.0);\n"
60 												"}\n\0";
61 
vertex_attribf(NegativeTestContext & ctx)62 void vertex_attribf (NegativeTestContext& ctx)
63 {
64 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
65 	int maxVertexAttribs = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
66 	ctx.glVertexAttrib1f(maxVertexAttribs, 0.0f);
67 	ctx.expectError(GL_INVALID_VALUE);
68 	ctx.glVertexAttrib2f(maxVertexAttribs, 0.0f, 0.0f);
69 	ctx.expectError(GL_INVALID_VALUE);
70 	ctx.glVertexAttrib3f(maxVertexAttribs, 0.0f, 0.0f, 0.0f);
71 	ctx.expectError(GL_INVALID_VALUE);
72 	ctx.glVertexAttrib4f(maxVertexAttribs, 0.0f, 0.0f, 0.0f, 0.0f);
73 	ctx.expectError(GL_INVALID_VALUE);
74 	ctx.endSection();
75 }
76 
vertex_attribfv(NegativeTestContext & ctx)77 void vertex_attribfv (NegativeTestContext& ctx)
78 {
79 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
80 	int maxVertexAttribs = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
81 	float v[4] = {0.0f};
82 	ctx.glVertexAttrib1fv(maxVertexAttribs, &v[0]);
83 	ctx.expectError(GL_INVALID_VALUE);
84 	ctx.glVertexAttrib2fv(maxVertexAttribs, &v[0]);
85 	ctx.expectError(GL_INVALID_VALUE);
86 	ctx.glVertexAttrib3fv(maxVertexAttribs, &v[0]);
87 	ctx.expectError(GL_INVALID_VALUE);
88 	ctx.glVertexAttrib4fv(maxVertexAttribs, &v[0]);
89 	ctx.expectError(GL_INVALID_VALUE);
90 	ctx.endSection();
91 }
92 
vertex_attribi4(NegativeTestContext & ctx)93 void vertex_attribi4 (NegativeTestContext& ctx)
94 {
95 	int maxVertexAttribs	= ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
96 	GLint valInt			= 0;
97 	GLuint valUint			= 0;
98 
99 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
100 	ctx.glVertexAttribI4i(maxVertexAttribs, valInt, valInt, valInt, valInt);
101 	ctx.expectError(GL_INVALID_VALUE);
102 	ctx.glVertexAttribI4ui(maxVertexAttribs, valUint, valUint, valUint, valUint);
103 	ctx.expectError(GL_INVALID_VALUE);
104 	ctx.endSection();
105 }
106 
vertex_attribi4v(NegativeTestContext & ctx)107 void vertex_attribi4v (NegativeTestContext& ctx)
108 {
109 	int maxVertexAttribs	= ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
110 	GLint valInt[4]			= { 0 };
111 	GLuint valUint[4]		= { 0 };
112 
113 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
114 	ctx.glVertexAttribI4iv(maxVertexAttribs, &valInt[0]);
115 	ctx.expectError(GL_INVALID_VALUE);
116 	ctx.glVertexAttribI4uiv(maxVertexAttribs, &valUint[0]);
117 	ctx.expectError(GL_INVALID_VALUE);
118 	ctx.endSection();
119 }
120 
vertex_attrib_pointer(NegativeTestContext & ctx)121 void vertex_attrib_pointer (NegativeTestContext& ctx)
122 {
123 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not an accepted value.");
124 	ctx.glVertexAttribPointer(0, 1, 0, GL_TRUE, 0, 0);
125 	ctx.expectError(GL_INVALID_ENUM);
126 	ctx.endSection();
127 
128 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
129 	int maxVertexAttribs = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
130 	ctx.glVertexAttribPointer(maxVertexAttribs, 1, GL_BYTE, GL_TRUE, 0, 0);
131 	ctx.expectError(GL_INVALID_VALUE);
132 	ctx.endSection();
133 
134 	ctx.beginSection("GL_INVALID_VALUE is generated if size is not 1, 2, 3, or 4.");
135 	ctx.glVertexAttribPointer(0, 0, GL_BYTE, GL_TRUE, 0, 0);
136 	ctx.expectError(GL_INVALID_VALUE);
137 	ctx.endSection();
138 
139 	ctx.beginSection("GL_INVALID_VALUE is generated if stride is negative.");
140 	ctx.glVertexAttribPointer(0, 1, GL_BYTE, GL_TRUE, -1, 0);
141 	ctx.expectError(GL_INVALID_VALUE);
142 	ctx.endSection();
143 
144 	ctx.beginSection("GL_INVALID_OPERATION is generated if type is GL_INT_2_10_10_10_REV or GL_UNSIGNED_INT_2_10_10_10_REV and size is not 4.");
145 	ctx.glVertexAttribPointer(0, 2, GL_INT_2_10_10_10_REV, GL_TRUE, 0, 0);
146 	ctx.expectError(GL_INVALID_OPERATION);
147 	ctx.glVertexAttribPointer(0, 2, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 0, 0);
148 	ctx.expectError(GL_INVALID_OPERATION);
149 	ctx.glVertexAttribPointer(0, 4, GL_INT_2_10_10_10_REV, GL_TRUE, 0, 0);
150 	ctx.expectError(GL_NO_ERROR);
151 	ctx.glVertexAttribPointer(0, 4, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 0, 0);
152 	ctx.expectError(GL_NO_ERROR);
153 	ctx.endSection();
154 
155 	ctx.beginSection("GL_INVALID_OPERATION is generated a non-zero vertex array object is bound, zero is bound to the GL_ARRAY_BUFFER buffer object binding point and the pointer argument is not NULL.");
156 	GLuint vao = 0;
157 	GLbyte offset = 1;
158 	ctx.glGenVertexArrays(1, &vao);
159 	ctx.glBindVertexArray(vao);
160 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
161 	ctx.expectError(GL_NO_ERROR);
162 
163 	ctx.glVertexAttribPointer(0, 1, GL_BYTE, GL_TRUE, 0, &offset);
164 	ctx.expectError(GL_INVALID_OPERATION);
165 
166 	ctx.glBindVertexArray(0);
167 	ctx.glDeleteVertexArrays(1, &vao);
168 	ctx.expectError(GL_NO_ERROR);
169 	ctx.endSection();
170 }
171 
vertex_attrib_i_pointer(NegativeTestContext & ctx)172 void vertex_attrib_i_pointer (NegativeTestContext& ctx)
173 {
174 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not an accepted value.");
175 	ctx.glVertexAttribIPointer(0, 1, 0, 0, 0);
176 	ctx.expectError(GL_INVALID_ENUM);
177 	ctx.glVertexAttribIPointer(0, 4, GL_INT_2_10_10_10_REV, 0, 0);
178 	ctx.expectError(GL_INVALID_ENUM);
179 	ctx.glVertexAttribIPointer(0, 4, GL_UNSIGNED_INT_2_10_10_10_REV, 0, 0);
180 	ctx.expectError(GL_INVALID_ENUM);
181 	ctx.endSection();
182 
183 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
184 	int maxVertexAttribs = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
185 	ctx.glVertexAttribIPointer(maxVertexAttribs, 1, GL_BYTE, 0, 0);
186 	ctx.expectError(GL_INVALID_VALUE);
187 	ctx.endSection();
188 
189 	ctx.beginSection("GL_INVALID_VALUE is generated if size is not 1, 2, 3, or 4.");
190 	ctx.glVertexAttribIPointer(0, 0, GL_BYTE, 0, 0);
191 	ctx.expectError(GL_INVALID_VALUE);
192 	ctx.endSection();
193 
194 	ctx.beginSection("GL_INVALID_VALUE is generated if stride is negative.");
195 	ctx.glVertexAttribIPointer(0, 1, GL_BYTE, -1, 0);
196 	ctx.expectError(GL_INVALID_VALUE);
197 	ctx.endSection();
198 
199 	ctx.beginSection("GL_INVALID_OPERATION is generated a non-zero vertex array object is bound, zero is bound to the GL_ARRAY_BUFFER buffer object binding point and the pointer argument is not NULL.");
200 	GLuint vao = 0;
201 	GLbyte offset = 1;
202 	ctx.glGenVertexArrays(1, &vao);
203 	ctx.glBindVertexArray(vao);
204 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
205 	ctx.expectError(GL_NO_ERROR);
206 
207 	ctx.glVertexAttribIPointer(0, 1, GL_BYTE, 0, &offset);
208 	ctx.expectError(GL_INVALID_OPERATION);
209 
210 	ctx.glBindVertexArray(0);
211 	ctx.glDeleteVertexArrays(1, &vao);
212 	ctx.expectError(GL_NO_ERROR);
213 	ctx.endSection();
214 }
215 
vertex_attrib_format(NegativeTestContext & ctx)216 void vertex_attrib_format (NegativeTestContext& ctx)
217 {
218 	int		maxVertexAttribs				= ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
219 	int		maxVertexAttribRelativeOffset	= ctx.getInteger(GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET);
220 	GLuint	vao								= 0;
221 
222 	ctx.beginSection("GL_INVALID_VALUE is generated if attribindex is greater than or equal to the value of MAX_VERTEX_ATTRIBS.");
223 	ctx.glGenVertexArrays(1, &vao);
224 	ctx.glBindVertexArray(vao);
225 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
226 	ctx.glVertexAttribFormat(maxVertexAttribs, 4, GL_FLOAT, GL_FALSE, maxVertexAttribRelativeOffset);
227 	ctx.expectError(GL_INVALID_VALUE);
228 	ctx.endSection();
229 
230 	ctx.beginSection("GL_INVALID_VALUE is generated if size is not one of 1, 2, 3, 4.");
231 	ctx.glGenVertexArrays(1, &vao);
232 	ctx.glBindVertexArray(vao);
233 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
234 	ctx.glVertexAttribFormat(1, 0, GL_FLOAT, GL_FALSE, maxVertexAttribRelativeOffset);
235 	ctx.expectError(GL_INVALID_VALUE);
236 	ctx.endSection();
237 
238 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the parameter token names allowed.");
239 	ctx.glGenVertexArrays(1, &vao);
240 	ctx.glBindVertexArray(vao);
241 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
242 	ctx.glVertexAttribFormat(1, 4, 1, GL_FALSE, 0);
243 	ctx.expectError(GL_INVALID_ENUM);
244 	ctx.endSection();
245 
246 	ctx.beginSection("GL_INVALID_OPERATION is generated if type is not a token name allowed.");
247 	ctx.glGenVertexArrays(1, &vao);
248 	ctx.glBindVertexArray(0);
249 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
250 	ctx.glVertexAttribFormat(1, 4, GL_FLOAT, GL_FALSE, 0);
251 	ctx.expectError(GL_INVALID_OPERATION);
252 	ctx.endSection();
253 
254 	ctx.beginSection("GL_INVALID_OPERATION is generated if type is GL_INT_2_10_10_10_REV and size is not 4.");
255 	ctx.glGenVertexArrays(1, &vao);
256 	ctx.glBindVertexArray(vao);
257 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
258 	ctx.glVertexAttribFormat(1, 3, GL_INT_2_10_10_10_REV, GL_FALSE, 0);
259 	ctx.expectError(GL_INVALID_OPERATION);
260 	ctx.endSection();
261 
262 	ctx.beginSection("GL_INVALID_OPERATION is generated if type is GL_UNSIGNED_INT_2_10_10_10_REV and size is not 4.");
263 	ctx.glGenVertexArrays(1, &vao);
264 	ctx.glBindVertexArray(vao);
265 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
266 	ctx.glVertexAttribFormat(1, 3, GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 0);
267 	ctx.expectError(GL_INVALID_OPERATION);
268 	ctx.endSection();
269 
270 	ctx.beginSection("GL_INVALID_VALUE is generated if relativeoffset is larger than the value of GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.");
271 	ctx.glGenVertexArrays(1, &vao);
272 	ctx.glBindVertexArray(vao);
273 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
274 	ctx.glVertexAttribFormat(1, 4, GL_FLOAT, GL_FALSE, maxVertexAttribRelativeOffset + 1);
275 	ctx.expectError(GL_INVALID_VALUE);
276 	ctx.endSection();
277 }
278 
vertex_attrib_i_format(NegativeTestContext & ctx)279 void vertex_attrib_i_format (NegativeTestContext& ctx)
280 {
281 	int		maxVertexAttribs				= ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
282 	int		maxVertexAttribRelativeOffset	= ctx.getInteger(GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET);
283 	GLuint	vao								= 0;
284 
285 	ctx.beginSection("GL_INVALID_VALUE is generated if attribindex is greater than or equal to the value of GL_MAX_VERTEX_ATTRIBS.");
286 	ctx.glGenVertexArrays(1, &vao);
287 	ctx.glBindVertexArray(vao);
288 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
289 	ctx.glVertexAttribIFormat(maxVertexAttribs, 4, GL_INT, 0);
290 	ctx.expectError(GL_INVALID_VALUE);
291 	ctx.endSection();
292 
293 	ctx.beginSection("GL_INVALID_VALUE is generated if size is not one the values 1, 2, 3, 4.");
294 	ctx.glGenVertexArrays(1, &vao);
295 	ctx.glBindVertexArray(vao);
296 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
297 	ctx.glVertexAttribIFormat(1, 0, GL_INT, 0);
298 	ctx.expectError(GL_INVALID_VALUE);
299 	ctx.endSection();
300 
301 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the parameter token names allowed.");
302 	ctx.glGenVertexArrays(1, &vao);
303 	ctx.glBindVertexArray(vao);
304 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
305 	ctx.glVertexAttribIFormat(1, 4, GL_FLOAT, 0);
306 	ctx.expectError(GL_INVALID_ENUM);
307 	ctx.endSection();
308 
309 	ctx.beginSection("GL_INVALID_OPERATION is generated if type is not a token name allowed.");
310 	ctx.glGenVertexArrays(1, &vao);
311 	ctx.glBindVertexArray(0);
312 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
313 	ctx.glVertexAttribIFormat(1, 4, GL_INT, 0);
314 	ctx.expectError(GL_INVALID_OPERATION);
315 	ctx.endSection();
316 
317 	ctx.beginSection("GL_INVALID_VALUE is generated if relativeoffset is larger than the value of GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET.");
318 	ctx.glGenVertexArrays(1, &vao);
319 	ctx.glBindVertexArray(vao);
320 	ctx.glBindBuffer(GL_ARRAY_BUFFER, 0);
321 	ctx.glVertexAttribIFormat(1, 4, GL_INT, maxVertexAttribRelativeOffset + 1);
322 	ctx.expectError(GL_INVALID_VALUE);
323 	ctx.endSection();
324 }
325 
enable_vertex_attrib_array(NegativeTestContext & ctx)326 void enable_vertex_attrib_array (NegativeTestContext& ctx)
327 {
328 	int maxVertexAttribs = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
329 
330 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
331 	ctx.glEnableVertexAttribArray(maxVertexAttribs);
332 	ctx.expectError(GL_INVALID_VALUE);
333 	ctx.endSection();
334 }
335 
disable_vertex_attrib_array(NegativeTestContext & ctx)336 void disable_vertex_attrib_array (NegativeTestContext& ctx)
337 {
338 	int maxVertexAttribs = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
339 
340 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
341 	ctx.glDisableVertexAttribArray(maxVertexAttribs);
342 	ctx.expectError(GL_INVALID_VALUE);
343 	ctx.endSection();
344 }
345 
gen_vertex_arrays(NegativeTestContext & ctx)346 void gen_vertex_arrays (NegativeTestContext& ctx)
347 {
348 	GLuint arrays = 0;
349 
350 	ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
351 	ctx.glGenVertexArrays(-1, &arrays);
352 	ctx.expectError(GL_INVALID_VALUE);
353 	ctx.endSection();
354 }
355 
bind_vertex_array(NegativeTestContext & ctx)356 void bind_vertex_array (NegativeTestContext& ctx)
357 {
358 	ctx.beginSection("GL_INVALID_OPERATION is generated if array is not zero or the name of an existing vertex array object.");
359 	ctx.glBindVertexArray(-1);
360 	ctx.expectError(GL_INVALID_OPERATION);
361 	ctx.endSection();
362 }
363 
delete_vertex_arrays(NegativeTestContext & ctx)364 void delete_vertex_arrays (NegativeTestContext& ctx)
365 {
366 	ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
367 	ctx.glDeleteVertexArrays(-1, 0);
368 	ctx.expectError(GL_INVALID_VALUE);
369 	ctx.endSection();
370 }
371 
vertex_attrib_divisor(NegativeTestContext & ctx)372 void vertex_attrib_divisor (NegativeTestContext& ctx)
373 {
374 	int maxVertexAttribs = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
375 
376 	ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
377 	ctx.glVertexAttribDivisor(maxVertexAttribs, 0);
378 	ctx.expectError(GL_INVALID_VALUE);
379 	ctx.endSection();
380 }
381 
draw_arrays(NegativeTestContext & ctx)382 void draw_arrays (NegativeTestContext& ctx)
383 {
384 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
385 	GLuint						fbo		= 0;
386 	map<string, string> 		args;
387 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
388 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
389 
390 	ctx.glUseProgram(program.getProgram());
391 	ctx.expectError(GL_NO_ERROR);
392 
393 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
394 	ctx.glDrawArrays(-1, 0, 1);
395 	ctx.expectError(GL_INVALID_ENUM);
396 	ctx.endSection();
397 
398 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
399 	ctx.glDrawArrays(GL_POINTS, 0, -1);
400 	ctx.expectError(GL_INVALID_VALUE);
401 	ctx.endSection();
402 
403 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
404 	ctx.glGenFramebuffers(1, &fbo);
405 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
406 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
407 	ctx.glDrawArrays(GL_POINTS, 0, 1);
408 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
409 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
410 	ctx.glDeleteFramebuffers(1, &fbo);
411 	ctx.endSection();
412 
413 	ctx.glUseProgram(0);
414 }
415 
draw_arrays_invalid_program(NegativeTestContext & ctx)416 void draw_arrays_invalid_program (NegativeTestContext& ctx)
417 {
418 	GLuint fbo = 0;
419 	ctx.glUseProgram(0);
420 
421 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
422 	ctx.glDrawArrays(-1, 0, 1);
423 	ctx.expectError(GL_INVALID_ENUM);
424 	ctx.endSection();
425 
426 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
427 	ctx.glDrawArrays(GL_POINTS, 0, -1);
428 	ctx.expectError(GL_INVALID_VALUE);
429 	ctx.endSection();
430 
431 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
432 	ctx.glGenFramebuffers(1, &fbo);
433 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
434 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
435 	ctx.glDrawArrays(GL_POINTS, 0, 1);
436 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
437 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
438 	ctx.glDeleteFramebuffers(1, &fbo);
439 	ctx.endSection();
440 }
441 
draw_arrays_incomplete_primitive(NegativeTestContext & ctx)442 void draw_arrays_incomplete_primitive (NegativeTestContext& ctx)
443 {
444 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
445 	GLuint						fbo		= 0;
446 	map<string, string> 		args;
447 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
448 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
449 
450 	ctx.glUseProgram(program.getProgram());
451 	ctx.expectError(GL_NO_ERROR);
452 
453 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
454 	ctx.glDrawArrays(-1, 0, 1);
455 	ctx.expectError(GL_INVALID_ENUM);
456 	ctx.endSection();
457 
458 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
459 	ctx.glDrawArrays(GL_TRIANGLES, 0, -1);
460 	ctx.expectError(GL_INVALID_VALUE);
461 	ctx.endSection();
462 
463 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
464 	ctx.glGenFramebuffers(1, &fbo);
465 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
466 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
467 	ctx.glDrawArrays(GL_TRIANGLES, 0, 1);
468 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
469 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
470 	ctx.glDeleteFramebuffers(1, &fbo);
471 	ctx.endSection();
472 
473 	ctx.glUseProgram(0);
474 }
475 
draw_elements(NegativeTestContext & ctx)476 void draw_elements (NegativeTestContext& ctx)
477 {
478 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
479 	GLuint						fbo		= 0;
480 	GLuint						buf		= 0;
481 	GLuint						tfID	= 0;
482 	GLfloat						vertices[1];
483 	map<string, string> 		args;
484 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
485 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
486 
487 	ctx.glUseProgram(program.getProgram());
488 	ctx.expectError(GL_NO_ERROR);
489 
490 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
491 	ctx.glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
492 	ctx.expectError(GL_INVALID_ENUM);
493 	ctx.endSection();
494 
495 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
496 	ctx.glDrawElements(GL_POINTS, 1, -1, vertices);
497 	ctx.expectError(GL_INVALID_ENUM);
498 	ctx.glDrawElements(GL_POINTS, 1, GL_FLOAT, vertices);
499 	ctx.expectError(GL_INVALID_ENUM);
500 	ctx.endSection();
501 
502 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
503 	ctx.glDrawElements(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices);
504 	ctx.expectError(GL_INVALID_VALUE);
505 	ctx.endSection();
506 
507 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
508 	ctx.glGenFramebuffers(1, &fbo);
509 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
510 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
511 	ctx.glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
512 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
513 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
514 	ctx.glDeleteFramebuffers(1, &fbo);
515 	ctx.endSection();
516 
517 	if (!ctx.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader")) // GL_EXT_geometry_shader removes error
518 	{
519 		ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is active and not paused.");
520 		const char* tfVarying = "gl_Position";
521 
522 		ctx.glGenBuffers(1, &buf);
523 		ctx.glGenTransformFeedbacks(1, &tfID);
524 
525 		ctx.glUseProgram(program.getProgram());
526 		ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
527 		ctx.glLinkProgram(program.getProgram());
528 		ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
529 		ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
530 		ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
531 		ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
532 		ctx.glBeginTransformFeedback(GL_POINTS);
533 		ctx.expectError(GL_NO_ERROR);
534 
535 		ctx.glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
536 		ctx.expectError(GL_INVALID_OPERATION);
537 
538 		ctx.glPauseTransformFeedback();
539 		ctx.glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
540 		ctx.expectError(GL_NO_ERROR);
541 
542 		ctx.glEndTransformFeedback();
543 		ctx.glDeleteBuffers(1, &buf);
544 		ctx.glDeleteTransformFeedbacks(1, &tfID);
545 		ctx.expectError(GL_NO_ERROR);
546 		ctx.endSection();
547 	}
548 
549 	ctx.glUseProgram(0);
550 }
551 
draw_elements_invalid_program(NegativeTestContext & ctx)552 void draw_elements_invalid_program (NegativeTestContext& ctx)
553 {
554 	ctx.glUseProgram(0);
555 	GLuint	fbo = 0;
556 	GLfloat	vertices[1];
557 
558 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
559 	ctx.glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
560 	ctx.expectError(GL_INVALID_ENUM);
561 	ctx.endSection();
562 
563 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
564 	ctx.glDrawElements(GL_POINTS, 1, -1, vertices);
565 	ctx.expectError(GL_INVALID_ENUM);
566 	ctx.glDrawElements(GL_POINTS, 1, GL_FLOAT, vertices);
567 	ctx.expectError(GL_INVALID_ENUM);
568 	ctx.endSection();
569 
570 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
571 	ctx.glDrawElements(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices);
572 	ctx.expectError(GL_INVALID_VALUE);
573 	ctx.endSection();
574 
575 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
576 	ctx.glGenFramebuffers(1, &fbo);
577 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
578 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
579 	ctx.glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices);
580 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
581 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
582 	ctx.glDeleteFramebuffers(1, &fbo);
583 	ctx.endSection();
584 }
585 
draw_elements_incomplete_primitive(NegativeTestContext & ctx)586 void draw_elements_incomplete_primitive (NegativeTestContext& ctx)
587 {
588 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
589 	GLuint						fbo		= 0;
590 	GLuint						buf		= 0;
591 	GLuint						tfID	= 0;
592 	GLfloat						vertices[1];
593 	map<string, string> 		args;
594 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
595 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
596 
597 	ctx.glUseProgram(program.getProgram());
598 	ctx.expectError(GL_NO_ERROR);
599 
600 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
601 	ctx.glDrawElements(-1, 1, GL_UNSIGNED_BYTE, vertices);
602 	ctx.expectError(GL_INVALID_ENUM);
603 	ctx.endSection();
604 
605 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
606 	ctx.glDrawElements(GL_TRIANGLES, 1, -1, vertices);
607 	ctx.expectError(GL_INVALID_ENUM);
608 	ctx.glDrawElements(GL_TRIANGLES, 1, GL_FLOAT, vertices);
609 	ctx.expectError(GL_INVALID_ENUM);
610 	ctx.endSection();
611 
612 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
613 	ctx.glDrawElements(GL_TRIANGLES, -1, GL_UNSIGNED_BYTE, vertices);
614 	ctx.expectError(GL_INVALID_VALUE);
615 	ctx.endSection();
616 
617 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
618 	ctx.glGenFramebuffers(1, &fbo);
619 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
620 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
621 	ctx.glDrawElements(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices);
622 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
623 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
624 	ctx.glDeleteFramebuffers(1, &fbo);
625 	ctx.endSection();
626 
627 	if (!ctx.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader")) // GL_EXT_geometry_shader removes error
628 	{
629 		ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is active and not paused.");
630 		const char* tfVarying= "gl_Position";
631 
632 		ctx.glGenBuffers(1, &buf);
633 		ctx.glGenTransformFeedbacks(1, &tfID);
634 
635 		ctx.glUseProgram(program.getProgram());
636 		ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
637 		ctx.glLinkProgram(program.getProgram());
638 		ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
639 		ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
640 		ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
641 		ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
642 		ctx.glBeginTransformFeedback(GL_TRIANGLES);
643 		ctx.expectError(GL_NO_ERROR);
644 
645 		ctx.glDrawElements(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices);
646 		ctx.expectError(GL_INVALID_OPERATION);
647 
648 		ctx.glPauseTransformFeedback();
649 		ctx.glDrawElements(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices);
650 		ctx.expectError(GL_NO_ERROR);
651 
652 		ctx.glEndTransformFeedback();
653 		ctx.glDeleteBuffers(1, &buf);
654 		ctx.glDeleteTransformFeedbacks(1, &tfID);
655 		ctx.expectError(GL_NO_ERROR);
656 		ctx.endSection();
657 	}
658 
659 	ctx.glUseProgram(0);
660 }
661 
draw_elements_base_vertex(NegativeTestContext & ctx)662 void draw_elements_base_vertex (NegativeTestContext& ctx)
663 {
664 	TCU_CHECK_AND_THROW(NotSupportedError, contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)), "This test requires a 3.2 context or higher context version.");
665 
666 	GLuint	fbo = 0;
667 	GLfloat	vertices[1];
668 
669 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
670 	ctx.glDrawElementsBaseVertex(-1, 1, GL_UNSIGNED_INT, vertices, 1);
671 	ctx.expectError(GL_INVALID_ENUM);
672 	ctx.endSection();
673 
674 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
675 	ctx.glDrawElementsBaseVertex(GL_POINTS, 1, -1, vertices, 1);
676 	ctx.expectError(GL_INVALID_ENUM);
677 	ctx.glDrawElementsBaseVertex(GL_POINTS, 1, GL_FLOAT, vertices, 1);
678 	ctx.expectError(GL_INVALID_ENUM);
679 	ctx.endSection();
680 
681 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
682 	ctx.glDrawElementsBaseVertex(GL_POINTS, -1, GL_UNSIGNED_INT, vertices, 1);
683 	ctx.expectError(GL_INVALID_VALUE);
684 	ctx.endSection();
685 
686 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
687 	ctx.glGenFramebuffers(1, &fbo);
688 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
689 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
690 	ctx.glDrawElementsBaseVertex(GL_POINTS, 1, GL_UNSIGNED_INT, vertices, 1);
691 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
692 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
693 	ctx.glDeleteFramebuffers(1, &fbo);
694 	ctx.endSection();
695 }
696 
draw_arrays_instanced(NegativeTestContext & ctx)697 void draw_arrays_instanced (NegativeTestContext& ctx)
698 {
699 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
700 	GLuint						fbo		= 0;
701 	map<string, string> 		args;
702 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
703 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
704 
705 	ctx.glUseProgram(program.getProgram());
706 	ctx.expectError(GL_NO_ERROR);
707 	ctx.glVertexAttribDivisor(0, 1);
708 	ctx.expectError(GL_NO_ERROR);
709 
710 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
711 	ctx.glDrawArraysInstanced(-1, 0, 1, 1);
712 	ctx.expectError(GL_INVALID_ENUM);
713 	ctx.endSection();
714 
715 	ctx.beginSection("GL_INVALID_VALUE is generated if count or primcount are negative.");
716 	ctx.glDrawArraysInstanced(GL_POINTS, 0, -1, 1);
717 	ctx.expectError(GL_INVALID_VALUE);
718 	ctx.glDrawArraysInstanced(GL_POINTS, 0, 1, -1);
719 	ctx.expectError(GL_INVALID_VALUE);
720 	ctx.endSection();
721 
722 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
723 	ctx.glGenFramebuffers(1, &fbo);
724 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
725 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
726 	ctx.glDrawArraysInstanced(GL_POINTS, 0, 1, 1);
727 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
728 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
729 	ctx.glDeleteFramebuffers(1, &fbo);
730 	ctx.endSection();
731 
732 	ctx.glUseProgram(0);
733 }
734 
draw_arrays_instanced_invalid_program(NegativeTestContext & ctx)735 void draw_arrays_instanced_invalid_program (NegativeTestContext& ctx)
736 {
737 	ctx.glUseProgram(0);
738 	GLuint fbo = 0;
739 	ctx.glVertexAttribDivisor(0, 1);
740 	ctx.expectError(GL_NO_ERROR);
741 
742 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
743 	ctx.glDrawArraysInstanced(-1, 0, 1, 1);
744 	ctx.expectError(GL_INVALID_ENUM);
745 	ctx.endSection();
746 
747 	ctx.beginSection("GL_INVALID_VALUE is generated if count or primcount are negative.");
748 	ctx.glDrawArraysInstanced(GL_POINTS, 0, -1, 1);
749 	ctx.expectError(GL_INVALID_VALUE);
750 	ctx.glDrawArraysInstanced(GL_POINTS, 0, 1, -1);
751 	ctx.expectError(GL_INVALID_VALUE);
752 	ctx.endSection();
753 
754 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
755 	ctx.glGenFramebuffers(1, &fbo);
756 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
757 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
758 	ctx.glDrawArraysInstanced(GL_POINTS, 0, 1, 1);
759 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
760 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
761 	ctx.glDeleteFramebuffers(1, &fbo);
762 	ctx.endSection();
763 }
764 
draw_arrays_instanced_incomplete_primitive(NegativeTestContext & ctx)765 void draw_arrays_instanced_incomplete_primitive (NegativeTestContext& ctx)
766 {
767 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
768 	GLuint						fbo		= 0;
769 	map<string, string> 		args;
770 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
771 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
772 
773 	ctx.glVertexAttribDivisor(0, 1);
774 	ctx.expectError(GL_NO_ERROR);
775 
776 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
777 	ctx.glDrawArraysInstanced(-1, 0, 1, 1);
778 	ctx.expectError(GL_INVALID_ENUM);
779 	ctx.endSection();
780 
781 	ctx.beginSection("GL_INVALID_VALUE is generated if count or primcount are negative.");
782 	ctx.glDrawArraysInstanced(GL_TRIANGLES, 0, -1, 1);
783 	ctx.expectError(GL_INVALID_VALUE);
784 	ctx.glDrawArraysInstanced(GL_TRIANGLES, 0, 1, -1);
785 	ctx.expectError(GL_INVALID_VALUE);
786 	ctx.endSection();
787 
788 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
789 	ctx.glGenFramebuffers(1, &fbo);
790 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
791 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
792 	ctx.glDrawArraysInstanced(GL_TRIANGLES, 0, 1, 1);
793 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
794 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
795 	ctx.glDeleteFramebuffers(1, &fbo);
796 	ctx.endSection();
797 
798 	ctx.glUseProgram(0);
799 }
800 
draw_elements_instanced(NegativeTestContext & ctx)801 void draw_elements_instanced (NegativeTestContext& ctx)
802 {
803 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
804 	GLuint						fbo		= 0;
805 	GLuint						buf		= 0;
806 	GLuint						tfID	= 0;
807 	GLfloat						vertices[1];
808 	map<string, string> 		args;
809 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
810 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
811 
812 	ctx.glUseProgram(program.getProgram());
813 	ctx.glVertexAttribDivisor(0, 1);
814 	ctx.expectError(GL_NO_ERROR);
815 
816 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
817 	ctx.glDrawElementsInstanced(-1, 1, GL_UNSIGNED_BYTE, vertices, 1);
818 	ctx.expectError(GL_INVALID_ENUM);
819 	ctx.endSection();
820 
821 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
822 	ctx.glDrawElementsInstanced(GL_POINTS, 1, -1, vertices, 1);
823 	ctx.expectError(GL_INVALID_ENUM);
824 	ctx.glDrawElementsInstanced(GL_POINTS, 1, GL_FLOAT, vertices, 1);
825 	ctx.expectError(GL_INVALID_ENUM);
826 	ctx.endSection();
827 
828 	ctx.beginSection("GL_INVALID_VALUE is generated if count or primcount are negative.");
829 	ctx.glDrawElementsInstanced(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices, 1);
830 	ctx.expectError(GL_INVALID_VALUE);
831 	ctx.glDrawElementsInstanced(GL_POINTS, 11, GL_UNSIGNED_BYTE, vertices, -1);
832 	ctx.expectError(GL_INVALID_VALUE);
833 	ctx.endSection();
834 
835 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
836 	ctx.glGenFramebuffers(1, &fbo);
837 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
838 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
839 	ctx.glDrawElementsInstanced(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices, 1);
840 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
841 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
842 	ctx.glDeleteFramebuffers(1, &fbo);
843 	ctx.endSection();
844 
845 	if (!ctx.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader")) // GL_EXT_geometry_shader removes error
846 	{
847 		ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is active and not paused.");
848 		const char* tfVarying = "gl_Position";
849 
850 		ctx.glGenBuffers(1, &buf);
851 		ctx.glGenTransformFeedbacks(1, &tfID);
852 
853 		ctx.glUseProgram(program.getProgram());
854 		ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
855 		ctx.glLinkProgram(program.getProgram());
856 		ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
857 		ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
858 		ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
859 		ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
860 		ctx.glBeginTransformFeedback(GL_POINTS);
861 		ctx.expectError(GL_NO_ERROR);
862 
863 		ctx.glDrawElementsInstanced(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices, 1);
864 		ctx.expectError(GL_INVALID_OPERATION);
865 
866 		ctx.glPauseTransformFeedback();
867 		ctx.glDrawElementsInstanced(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices, 1);
868 		ctx.expectError(GL_NO_ERROR);
869 
870 		ctx.glEndTransformFeedback();
871 		ctx.glDeleteBuffers(1, &buf);
872 		ctx.glDeleteTransformFeedbacks(1, &tfID);
873 		ctx.expectError(GL_NO_ERROR);
874 		ctx.endSection();
875 	}
876 
877 	ctx.glUseProgram(0);
878 }
879 
draw_elements_instanced_invalid_program(NegativeTestContext & ctx)880 void draw_elements_instanced_invalid_program (NegativeTestContext& ctx)
881 {
882 	ctx.glUseProgram(0);
883 	GLuint fbo = 0;
884 	GLfloat vertices[1];
885 	ctx.glVertexAttribDivisor(0, 1);
886 	ctx.expectError(GL_NO_ERROR);
887 
888 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
889 	ctx.glDrawElementsInstanced(-1, 1, GL_UNSIGNED_BYTE, vertices, 1);
890 	ctx.expectError(GL_INVALID_ENUM);
891 	ctx.endSection();
892 
893 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
894 	ctx.glDrawElementsInstanced(GL_POINTS, 1, -1, vertices, 1);
895 	ctx.expectError(GL_INVALID_ENUM);
896 	ctx.glDrawElementsInstanced(GL_POINTS, 1, GL_FLOAT, vertices, 1);
897 	ctx.expectError(GL_INVALID_ENUM);
898 	ctx.endSection();
899 
900 	ctx.beginSection("GL_INVALID_VALUE is generated if count or primcount are negative.");
901 	ctx.glDrawElementsInstanced(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices, 1);
902 	ctx.expectError(GL_INVALID_VALUE);
903 	ctx.glDrawElementsInstanced(GL_POINTS, 11, GL_UNSIGNED_BYTE, vertices, -1);
904 	ctx.expectError(GL_INVALID_VALUE);
905 	ctx.endSection();
906 
907 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
908 	ctx.glGenFramebuffers(1, &fbo);
909 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
910 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
911 	ctx.glDrawElementsInstanced(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices, 1);
912 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
913 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
914 	ctx.glDeleteFramebuffers(1, &fbo);
915 	ctx.endSection();
916 }
917 
draw_elements_instanced_incomplete_primitive(NegativeTestContext & ctx)918 void draw_elements_instanced_incomplete_primitive (NegativeTestContext& ctx)
919 {
920 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
921 	GLuint						fbo		= 0;
922 	GLuint						buf		= 0;
923 	GLuint						tfID	= 0;
924 	GLfloat						vertices[1];
925 	map<string, string> 		args;
926 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
927 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
928 
929 	ctx.glUseProgram(program.getProgram());
930 	ctx.glVertexAttribDivisor(0, 1);
931 	ctx.expectError(GL_NO_ERROR);
932 
933 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
934 	ctx.glDrawElementsInstanced(-1, 1, GL_UNSIGNED_BYTE, vertices, 1);
935 	ctx.expectError(GL_INVALID_ENUM);
936 	ctx.endSection();
937 
938 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
939 	ctx.glDrawElementsInstanced(GL_TRIANGLES, 1, -1, vertices, 1);
940 	ctx.expectError(GL_INVALID_ENUM);
941 	ctx.glDrawElementsInstanced(GL_TRIANGLES, 1, GL_FLOAT, vertices, 1);
942 	ctx.expectError(GL_INVALID_ENUM);
943 	ctx.endSection();
944 
945 	ctx.beginSection("GL_INVALID_VALUE is generated if count or primcount are negative.");
946 	ctx.glDrawElementsInstanced(GL_TRIANGLES, -1, GL_UNSIGNED_BYTE, vertices, 1);
947 	ctx.expectError(GL_INVALID_VALUE);
948 	ctx.glDrawElementsInstanced(GL_TRIANGLES, 11, GL_UNSIGNED_BYTE, vertices, -1);
949 	ctx.expectError(GL_INVALID_VALUE);
950 	ctx.endSection();
951 
952 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
953 	ctx.glGenFramebuffers(1, &fbo);
954 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
955 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
956 	ctx.glDrawElementsInstanced(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices, 1);
957 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
958 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
959 	ctx.glDeleteFramebuffers(1, &fbo);
960 	ctx.endSection();
961 
962 	if (!ctx.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader")) // GL_EXT_geometry_shader removes error
963 	{
964 		ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is active and not paused.");
965 		const char* tfVarying= "gl_Position";
966 
967 		ctx.glGenBuffers(1, &buf);
968 		ctx.glGenTransformFeedbacks(1, &tfID);
969 
970 		ctx.glUseProgram(program.getProgram());
971 		ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
972 		ctx.glLinkProgram(program.getProgram());
973 		ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
974 		ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
975 		ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
976 		ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
977 		ctx.glBeginTransformFeedback(GL_TRIANGLES);
978 		ctx.expectError(GL_NO_ERROR);
979 
980 		ctx.glDrawElementsInstanced(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices, 1);
981 		ctx.expectError(GL_INVALID_OPERATION);
982 
983 		ctx.glPauseTransformFeedback();
984 		ctx.glDrawElementsInstanced	(GL_TRIANGLES, 1, GL_UNSIGNED_BYTE, vertices, 1);
985 		ctx.expectError(GL_NO_ERROR);
986 
987 		ctx.glEndTransformFeedback();
988 		ctx.glDeleteBuffers(1, &buf);
989 		ctx.glDeleteTransformFeedbacks(1, &tfID);
990 		ctx.expectError(GL_NO_ERROR);
991 		ctx.endSection();
992 	}
993 
994 	ctx.glUseProgram(0);
995 }
996 
draw_elements_instanced_base_vertex(NegativeTestContext & ctx)997 void draw_elements_instanced_base_vertex (NegativeTestContext& ctx)
998 {
999 	TCU_CHECK_AND_THROW(NotSupportedError, contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)), "This test requires a 3.2 context or higher context version.");
1000 
1001 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
1002 	GLuint						fbo		= 0;
1003 	GLfloat						vertices[1];
1004 	map<string, string> 		args;
1005 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
1006 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
1007 
1008 	ctx.glUseProgram(program.getProgram());
1009 	ctx.glVertexAttribDivisor(0, 1);
1010 	ctx.expectError(GL_NO_ERROR);
1011 
1012 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
1013 	ctx.glDrawElementsInstancedBaseVertex(-1, 1, GL_UNSIGNED_BYTE, vertices, 1, 1);
1014 	ctx.expectError(GL_INVALID_ENUM);
1015 	ctx.endSection();
1016 
1017 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
1018 	ctx.glDrawElementsInstancedBaseVertex(GL_POINTS, 1, -1, vertices, 1, 1);
1019 	ctx.expectError(GL_INVALID_ENUM);
1020 	ctx.glDrawElementsInstancedBaseVertex(GL_POINTS, 1, GL_FLOAT, vertices, 1, 1);
1021 	ctx.expectError(GL_INVALID_ENUM);
1022 	ctx.endSection();
1023 
1024 	ctx.beginSection("GL_INVALID_VALUE is generated if count or primcount are negative.");
1025 	ctx.glDrawElementsInstancedBaseVertex(GL_POINTS, -1, GL_UNSIGNED_BYTE, vertices, 1, 1);
1026 	ctx.expectError(GL_INVALID_VALUE);
1027 	ctx.glDrawElementsInstancedBaseVertex(GL_POINTS, 11, GL_UNSIGNED_BYTE, vertices, -1, 1);
1028 	ctx.expectError(GL_INVALID_VALUE);
1029 	ctx.endSection();
1030 
1031 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
1032 	ctx.glGenFramebuffers(1, &fbo);
1033 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1034 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1035 	ctx.glDrawElementsInstancedBaseVertex(GL_POINTS, 1, GL_UNSIGNED_BYTE, vertices, 1, 1);
1036 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
1037 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
1038 	ctx.glDeleteFramebuffers(1, &fbo);
1039 	ctx.endSection();
1040 
1041 	ctx.glUseProgram(0);
1042 }
1043 
draw_range_elements(NegativeTestContext & ctx)1044 void draw_range_elements (NegativeTestContext& ctx)
1045 {
1046 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
1047 	GLuint						fbo		= 0;
1048 	GLuint						buf		= 0;
1049 	GLuint						tfID	= 0;
1050 	GLfloat						vertices[1];
1051 	map<string, string> 		args;
1052 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
1053 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
1054 
1055 	ctx.glUseProgram(program.getProgram());
1056 	ctx.expectError(GL_NO_ERROR);
1057 
1058 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
1059 	ctx.glDrawRangeElements(-1, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1060 	ctx.expectError(GL_INVALID_ENUM);
1061 	ctx.endSection();
1062 
1063 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
1064 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, -1, vertices);
1065 	ctx.expectError(GL_INVALID_ENUM);
1066 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, GL_FLOAT, vertices);
1067 	ctx.expectError(GL_INVALID_ENUM);
1068 	ctx.endSection();
1069 
1070 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
1071 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, -1, GL_UNSIGNED_BYTE, vertices);
1072 	ctx.expectError(GL_INVALID_VALUE);
1073 	ctx.endSection();
1074 
1075 	ctx.beginSection("GL_INVALID_VALUE is generated if end < start.");
1076 	ctx.glDrawRangeElements(GL_POINTS, 1, 0, 1, GL_UNSIGNED_BYTE, vertices);
1077 	ctx.expectError(GL_INVALID_VALUE);
1078 	ctx.endSection();
1079 
1080 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
1081 	ctx.glGenFramebuffers(1, &fbo);
1082 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1083 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1084 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1085 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
1086 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
1087 	ctx.glDeleteFramebuffers(1, &fbo);
1088 	ctx.endSection();
1089 
1090 	if (!ctx.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader")) // GL_EXT_geometry_shader removes error
1091 	{
1092 		ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is active and not paused.");
1093 		const char* tfVarying= "gl_Position";
1094 
1095 		ctx.glGenBuffers(1, &buf);
1096 		ctx.glGenTransformFeedbacks(1, &tfID);
1097 
1098 		ctx.glUseProgram(program.getProgram());
1099 		ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1100 		ctx.glLinkProgram(program.getProgram());
1101 		ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
1102 		ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
1103 		ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
1104 		ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1105 		ctx.glBeginTransformFeedback(GL_POINTS);
1106 		ctx.expectError(GL_NO_ERROR);
1107 
1108 		ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1109 		ctx.expectError(GL_INVALID_OPERATION);
1110 
1111 		ctx.glPauseTransformFeedback();
1112 		ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1113 		ctx.expectError(GL_NO_ERROR);
1114 
1115 		ctx.glEndTransformFeedback();
1116 		ctx.glDeleteBuffers(1, &buf);
1117 		ctx.glDeleteTransformFeedbacks(1, &tfID);
1118 		ctx.expectError(GL_NO_ERROR);
1119 		ctx.endSection();
1120 	}
1121 
1122 	ctx.glUseProgram(0);
1123 }
1124 
draw_range_elements_invalid_program(NegativeTestContext & ctx)1125 void draw_range_elements_invalid_program (NegativeTestContext& ctx)
1126 {
1127 	ctx.glUseProgram(0);
1128 	GLuint fbo = 0;
1129 	GLfloat vertices[1];
1130 
1131 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
1132 	ctx.glDrawRangeElements(-1, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1133 	ctx.expectError(GL_INVALID_ENUM);
1134 	ctx.endSection();
1135 
1136 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
1137 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, -1, vertices);
1138 	ctx.expectError(GL_INVALID_ENUM);
1139 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, GL_FLOAT, vertices);
1140 	ctx.expectError(GL_INVALID_ENUM);
1141 	ctx.endSection();
1142 
1143 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
1144 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, -1, GL_UNSIGNED_BYTE, vertices);
1145 	ctx.expectError(GL_INVALID_VALUE);
1146 	ctx.endSection();
1147 
1148 	ctx.beginSection("GL_INVALID_VALUE is generated if end < start.");
1149 	ctx.glDrawRangeElements(GL_POINTS, 1, 0, 1, GL_UNSIGNED_BYTE, vertices);
1150 	ctx.expectError(GL_INVALID_VALUE);
1151 	ctx.endSection();
1152 
1153 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
1154 	ctx.glGenFramebuffers(1, &fbo);
1155 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1156 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1157 	ctx.glDrawRangeElements(GL_POINTS, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1158 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
1159 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
1160 	ctx.glDeleteFramebuffers(1, &fbo);
1161 	ctx.endSection();
1162 }
1163 
draw_range_elements_incomplete_primitive(NegativeTestContext & ctx)1164 void draw_range_elements_incomplete_primitive (NegativeTestContext& ctx)
1165 {
1166 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
1167 	GLuint						fbo		= 0;
1168 	GLuint						buf		= 0;
1169 	GLuint						tfID	= 0;
1170 	GLfloat						vertices[1];
1171 	map<string, string> 		args;
1172 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
1173 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
1174 
1175 	ctx.glUseProgram(program.getProgram());
1176 	ctx.expectError(GL_NO_ERROR);
1177 
1178 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
1179 	ctx.glDrawRangeElements(-1, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1180 	ctx.expectError(GL_INVALID_ENUM);
1181 	ctx.endSection();
1182 
1183 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
1184 	ctx.glDrawRangeElements(GL_TRIANGLES, 0, 1, 1, -1, vertices);
1185 	ctx.expectError(GL_INVALID_ENUM);
1186 	ctx.glDrawRangeElements(GL_TRIANGLES, 0, 1, 1, GL_FLOAT, vertices);
1187 	ctx.expectError(GL_INVALID_ENUM);
1188 	ctx.endSection();
1189 
1190 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
1191 	ctx.glDrawRangeElements(GL_TRIANGLES, 0, 1, -1, GL_UNSIGNED_BYTE, vertices);
1192 	ctx.expectError(GL_INVALID_VALUE);
1193 	ctx.endSection();
1194 
1195 	ctx.beginSection("GL_INVALID_VALUE is generated if end < start.");
1196 	ctx.glDrawRangeElements(GL_TRIANGLES, 1, 0, 1, GL_UNSIGNED_BYTE, vertices);
1197 	ctx.expectError(GL_INVALID_VALUE);
1198 	ctx.endSection();
1199 
1200 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
1201 	ctx.glGenFramebuffers(1, &fbo);
1202 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1203 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1204 	ctx.glDrawRangeElements(GL_TRIANGLES, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1205 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
1206 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
1207 	ctx.glDeleteFramebuffers(1, &fbo);
1208 	ctx.endSection();
1209 
1210 	if (!ctx.getContextInfo().isExtensionSupported("GL_EXT_geometry_shader")) // GL_EXT_geometry_shader removes error
1211 	{
1212 		ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is active and not paused.");
1213 		const char* tfVarying = "gl_Position";
1214 
1215 		ctx.glGenBuffers(1, &buf);
1216 		ctx.glGenTransformFeedbacks(1, &tfID);
1217 
1218 		ctx.glUseProgram(program.getProgram());
1219 		ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1220 		ctx.glLinkProgram(program.getProgram());
1221 		ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
1222 		ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
1223 		ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
1224 		ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1225 		ctx.glBeginTransformFeedback(GL_TRIANGLES);
1226 		ctx.expectError(GL_NO_ERROR);
1227 
1228 		ctx.glDrawRangeElements(GL_TRIANGLES, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1229 		ctx.expectError(GL_INVALID_OPERATION);
1230 
1231 		ctx.glPauseTransformFeedback();
1232 		ctx.glDrawRangeElements(GL_TRIANGLES, 0, 1, 1, GL_UNSIGNED_BYTE, vertices);
1233 		ctx.expectError(GL_NO_ERROR);
1234 
1235 		ctx.glEndTransformFeedback();
1236 		ctx.glDeleteBuffers(1, &buf);
1237 		ctx.glDeleteTransformFeedbacks(1, &tfID);
1238 		ctx.expectError(GL_NO_ERROR);
1239 		ctx.endSection();
1240 	}
1241 
1242 	ctx.glUseProgram(0);
1243 }
1244 
draw_range_elements_base_vertex(NegativeTestContext & ctx)1245 void draw_range_elements_base_vertex (NegativeTestContext& ctx)
1246 {
1247 	TCU_CHECK_AND_THROW(NotSupportedError, contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)), "This test requires a 3.2 context or higher context version.");
1248 
1249 	const bool					isES32	= glu::contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2));
1250 	GLuint						fbo		= 0;
1251 	GLfloat						vertices[1];
1252 	map<string, string> 		args;
1253 	args["GLSL_VERSION_STRING"]			= isES32 ? getGLSLVersionDeclaration(glu::GLSL_VERSION_320_ES) : getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES);
1254 	glu::ShaderProgram			program	(ctx.getRenderContext(), glu::makeVtxFragSources(tcu::StringTemplate(vertexShaderSource).specialize(args), tcu::StringTemplate(fragmentShaderSource).specialize(args)));
1255 
1256 	ctx.glUseProgram(program.getProgram());
1257 	ctx.expectError(GL_NO_ERROR);
1258 
1259 	ctx.beginSection("GL_INVALID_ENUM is generated if mode is not an accepted value.");
1260 	ctx.glDrawRangeElementsBaseVertex(-1, 0, 1, 1, GL_UNSIGNED_BYTE, vertices, 1);
1261 	ctx.expectError(GL_INVALID_ENUM);
1262 	ctx.endSection();
1263 
1264 	ctx.beginSection("GL_INVALID_ENUM is generated if type is not one of the accepted values.");
1265 	ctx.glDrawRangeElementsBaseVertex(GL_POINTS, 0, 1, 1, -1, vertices, 1);
1266 	ctx.expectError(GL_INVALID_ENUM);
1267 	ctx.glDrawRangeElementsBaseVertex(GL_POINTS, 0, 1, 1, GL_FLOAT, vertices, 1);
1268 	ctx.expectError(GL_INVALID_ENUM);
1269 	ctx.endSection();
1270 
1271 	ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
1272 	ctx.glDrawRangeElementsBaseVertex(GL_POINTS, 0, 1, -1, GL_UNSIGNED_BYTE, vertices, 1);
1273 	ctx.expectError(GL_INVALID_VALUE);
1274 	ctx.endSection();
1275 
1276 	ctx.beginSection("GL_INVALID_VALUE is generated if end < start.");
1277 	ctx.glDrawRangeElementsBaseVertex(GL_POINTS, 1, 0, 1, GL_UNSIGNED_BYTE, vertices, 1);
1278 	ctx.expectError(GL_INVALID_VALUE);
1279 	ctx.endSection();
1280 
1281 	ctx.beginSection("GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
1282 	ctx.glGenFramebuffers(1, &fbo);
1283 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1284 	ctx.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1285 	ctx.glDrawRangeElementsBaseVertex(GL_POINTS, 0, 1, 1, GL_UNSIGNED_BYTE, vertices, 1);
1286 	ctx.expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
1287 	ctx.glBindFramebuffer(GL_FRAMEBUFFER, 0);
1288 	ctx.glDeleteFramebuffers(1, &fbo);
1289 	ctx.endSection();
1290 
1291 	ctx.glUseProgram(0);
1292 }
1293 
getNegativeVertexArrayApiTestFunctions()1294 std::vector<FunctionContainer> getNegativeVertexArrayApiTestFunctions ()
1295 {
1296 	FunctionContainer funcs[] =
1297 	{
1298 		{vertex_attribf,								"vertex_attribf",								"Invalid glVertexAttrib{1234}f() usage"				},
1299 		{vertex_attribfv,								"vertex_attribfv",								"Invalid glVertexAttrib{1234}fv() usage"			},
1300 		{vertex_attribi4,								"vertex_attribi4",								"Invalid glVertexAttribI4{i|ui}f() usage"			},
1301 		{vertex_attribi4v,								"vertex_attribi4v",								"Invalid glVertexAttribI4{i|ui}fv() usage"			},
1302 		{vertex_attrib_pointer,							"vertex_attrib_pointer",						"Invalid glVertexAttribPointer() usage"				},
1303 		{vertex_attrib_i_pointer,						"vertex_attrib_i_pointer",						"Invalid glVertexAttribPointer() usage"				},
1304 		{vertex_attrib_format,							"vertex_attrib_format",							"Invalid glVertexAttribFormat() usage"				},
1305 		{vertex_attrib_i_format,						"vertex_attrib_i_format",						"Invalid glVertexAttribIFormat() usage"				},
1306 		{enable_vertex_attrib_array,					"enable_vertex_attrib_array",					"Invalid glEnableVertexAttribArray() usage"			},
1307 		{disable_vertex_attrib_array,					"disable_vertex_attrib_array",					"Invalid glDisableVertexAttribArray() usage"		},
1308 		{gen_vertex_arrays,								"gen_vertex_arrays",							"Invalid glGenVertexArrays() usage"					},
1309 		{bind_vertex_array,								"bind_vertex_array",							"Invalid glBindVertexArray() usage"					},
1310 		{delete_vertex_arrays,							"delete_vertex_arrays",							"Invalid glDeleteVertexArrays() usage"				},
1311 		{vertex_attrib_divisor,							"vertex_attrib_divisor",						"Invalid glVertexAttribDivisor() usage"				},
1312 		{draw_arrays,									"draw_arrays",									"Invalid glDrawArrays() usage"						},
1313 		{draw_arrays_invalid_program,					"draw_arrays_invalid_program",					"Invalid glDrawArrays() usage"						},
1314 		{draw_arrays_incomplete_primitive,				"draw_arrays_incomplete_primitive",				"Invalid glDrawArrays() usage"						},
1315 		{draw_elements,									"draw_elements",								"Invalid glDrawElements() usage"					},
1316 		{draw_elements_base_vertex,						"draw_elements_base_vertex",					"Invalid glDrawElementsBaseVertex() usage"			},
1317 		{draw_elements_invalid_program,					"draw_elements_invalid_program",				"Invalid glDrawElements() usage"					},
1318 		{draw_elements_incomplete_primitive,			"draw_elements_incomplete_primitive",			"Invalid glDrawElements() usage"					},
1319 		{draw_arrays_instanced,							"draw_arrays_instanced",						"Invalid glDrawArraysInstanced() usage"				},
1320 		{draw_arrays_instanced_invalid_program,			"draw_arrays_instanced_invalid_program",		"Invalid glDrawArraysInstanced() usage"				},
1321 		{draw_arrays_instanced_incomplete_primitive,	"draw_arrays_instanced_incomplete_primitive",	"Invalid glDrawArraysInstanced() usage"				},
1322 		{draw_elements_instanced,						"draw_elements_instanced",						"Invalid glDrawElementsInstanced() usage"			},
1323 		{draw_elements_instanced_invalid_program,		"draw_elements_instanced_invalid_program",		"Invalid glDrawElementsInstanced() usage"			},
1324 		{draw_elements_instanced_incomplete_primitive,	"draw_elements_instanced_incomplete_primitive",	"Invalid glDrawElementsInstanced() usage"			},
1325 		{draw_elements_instanced_base_vertex,			"draw_elements_instanced_base_vertex",			"Invalid glDrawElementsInstancedBaseVertex() usage"	},
1326 		{draw_range_elements,							"draw_range_elements",							"Invalid glDrawRangeElements() usage"				},
1327 		{draw_range_elements_invalid_program,			"draw_range_elements_invalid_program",			"Invalid glDrawRangeElements() usage"				},
1328 		{draw_range_elements_incomplete_primitive,		"draw_range_elements_incomplete_primitive",		"Invalid glDrawRangeElements() usage"				},
1329 		{draw_range_elements_base_vertex,				"draw_range_elements_base_vertex",				"Invalid glDrawRangeElementsBaseVertex() usage"		},
1330 	};
1331 
1332 	return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
1333 }
1334 
1335 } // NegativeTestShared
1336 } // Functional
1337 } // gles31
1338 } // deqp
1339