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