[automerger skipped] DO NOT MERGE: Make the tests permissive for Lollipop MR1
[platform/upstream/VK-GL-CTS.git] / modules / gles31 / functional / es31fNegativeShaderApiTests.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 Shader API tests.
22  *//*--------------------------------------------------------------------*/
23
24 #include "es31fNegativeShaderApiTests.hpp"
25
26 #include "deUniquePtr.hpp"
27
28 #include "glwDefs.hpp"
29 #include "glwEnums.hpp"
30
31 #include "gluShaderProgram.hpp"
32 #include "gluCallLogWrapper.hpp"
33
34
35
36 namespace deqp
37 {
38 namespace gles31
39 {
40 namespace Functional
41 {
42 namespace NegativeTestShared
43 {
44 using tcu::TestLog;
45 using glu::CallLogWrapper;
46 using namespace glw;
47
48 static const char* vertexShaderSource           =       "#version 300 es\n"
49                                                                                                 "void main (void)\n"
50                                                                                                 "{\n"
51                                                                                                 "       gl_Position = vec4(0.0);\n"
52                                                                                                 "}\n\0";
53
54 static const char* fragmentShaderSource         =       "#version 300 es\n"
55                                                                                                 "layout(location = 0) out mediump vec4 fragColor;"
56                                                                                                 "void main (void)\n"
57                                                                                                 "{\n"
58                                                                                                 "       fragColor = vec4(0.0);\n"
59                                                                                                 "}\n\0";
60
61 static const char* uniformTestVertSource        =       "#version 300 es\n"
62                                                                                                 "uniform mediump vec4 vec4_v;\n"
63                                                                                                 "uniform mediump mat4 mat4_v;\n"
64                                                                                                 "void main (void)\n"
65                                                                                                 "{\n"
66                                                                                                 "       gl_Position = mat4_v * vec4_v;\n"
67                                                                                                 "}\n\0";
68
69 static const char* uniformTestFragSource        =       "#version 300 es\n"
70                                                                                                 "uniform mediump ivec4 ivec4_f;\n"
71                                                                                                 "uniform mediump uvec4 uvec4_f;\n"
72                                                                                                 "uniform sampler2D sampler_f;\n"
73                                                                                                 "layout(location = 0) out mediump vec4 fragColor;"
74                                                                                                 "void main (void)\n"
75                                                                                                 "{\n"
76                                                                                                 "       fragColor.xy = (vec4(uvec4_f) + vec4(ivec4_f)).xy;\n"
77                                                                                                 "       fragColor.zw = texture(sampler_f, vec2(0.0, 0.0)).zw;\n"
78                                                                                                 "}\n\0";
79
80 static const char* uniformBlockVertSource       =       "#version 300 es\n"
81                                                                                                 "layout(shared) uniform Block { lowp float var; };\n"
82                                                                                                 "void main (void)\n"
83                                                                                                 "{\n"
84                                                                                                 "       gl_Position = vec4(var);\n"
85                                                                                                 "}\n\0";
86
87
88 // Shader control commands
89 void create_shader (NegativeTestContext& ctx)
90 {
91         ctx.beginSection("GL_INVALID_ENUM is generated if shaderType is not an accepted value.");
92         ctx.glCreateShader(-1);
93         ctx.expectError(GL_INVALID_ENUM);
94         ctx.endSection();
95 }
96
97 void shader_source (NegativeTestContext& ctx)
98 {
99         // make notAShader not a shader id
100         const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
101         ctx.glDeleteShader(notAShader);
102
103         ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
104         ctx.glShaderSource(notAShader, 0, 0, 0);
105         ctx.expectError(GL_INVALID_VALUE);
106         ctx.endSection();
107
108         ctx.beginSection("GL_INVALID_VALUE is generated if count is less than 0.");
109         GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
110         ctx.glShaderSource(shader, -1, 0, 0);
111         ctx.expectError(GL_INVALID_VALUE);
112         ctx.endSection();
113
114         ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
115         GLuint program = ctx.glCreateProgram();
116         ctx.glShaderSource(program, 0, 0, 0);
117         ctx.expectError(GL_INVALID_OPERATION);
118         ctx.endSection();
119
120         ctx.glDeleteProgram(program);
121         ctx.glDeleteShader(shader);
122 }
123
124 void compile_shader (NegativeTestContext& ctx)
125 {
126         // \note Shader compilation must be supported.
127
128         ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
129         ctx.glCompileShader(9);
130         ctx.expectError(GL_INVALID_VALUE);
131         ctx.endSection();
132
133         ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
134         GLuint program = ctx.glCreateProgram();
135         ctx.glCompileShader(program);
136         ctx.expectError(GL_INVALID_OPERATION);
137         ctx.endSection();
138
139         ctx.glDeleteProgram(program);
140 }
141
142 void delete_shader (NegativeTestContext& ctx)
143 {
144         ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
145         ctx.glDeleteShader(9);
146         ctx.expectError(GL_INVALID_VALUE);
147         ctx.endSection();
148 }
149
150 void shader_binary (NegativeTestContext& ctx)
151 {
152         std::vector<deInt32> binaryFormats;
153
154         {
155                 deInt32 numFormats = 0x1234;
156                 ctx.glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &numFormats);
157
158                 if (numFormats == 0)
159                         ctx.getLog() << TestLog::Message << "// No supported extensions available." << TestLog::EndMessage;
160                 else
161                 {
162                         binaryFormats.resize(numFormats);
163                         ctx.glGetIntegerv(GL_SHADER_BINARY_FORMATS, &binaryFormats[0]);
164                 }
165         }
166
167         deBool shaderBinarySupported = !binaryFormats.empty();
168         if (!shaderBinarySupported)
169                 ctx.getLog() << TestLog::Message << "// Shader binaries not supported." << TestLog::EndMessage;
170         else
171                 ctx.getLog() << TestLog::Message << "// Shader binaries supported" << TestLog::EndMessage;
172
173         GLuint shaders[2];
174         shaders[0]              = ctx.glCreateShader(GL_VERTEX_SHADER);
175         shaders[1]              = ctx.glCreateShader(GL_VERTEX_SHADER);
176
177         ctx.beginSection("GL_INVALID_ENUM is generated if binaryFormat is not an accepted value.");
178         ctx.glShaderBinary(1, &shaders[0], -1, 0, 0);
179         ctx.expectError(GL_INVALID_ENUM);
180         ctx.endSection();
181
182         if (shaderBinarySupported)
183         {
184                 ctx.beginSection("GL_INVALID_VALUE is generated if the data pointed to by binary does not match the format specified by binaryFormat.");
185                 const GLbyte data = 0x005F;
186                 ctx.glShaderBinary(1, &shaders[0], binaryFormats[0], &data, 1);
187                 ctx.expectError(GL_INVALID_VALUE);
188                 ctx.endSection();
189
190                 ctx.beginSection("GL_INVALID_OPERATION is generated if more than one of the handles in shaders refers to the same type of shader, or GL_INVALID_VALUE due to invalid data pointer.");
191                 ctx.glShaderBinary(2, &shaders[0], binaryFormats[0], 0, 0);
192                 ctx.expectError(GL_INVALID_OPERATION, GL_INVALID_VALUE);
193                 ctx.endSection();
194         }
195
196         ctx.glDeleteShader(shaders[0]);
197         ctx.glDeleteShader(shaders[1]);
198 }
199
200 void attach_shader (NegativeTestContext& ctx)
201 {
202         GLuint shader1 = ctx.glCreateShader(GL_VERTEX_SHADER);
203         GLuint shader2 = ctx.glCreateShader(GL_VERTEX_SHADER);
204         GLuint program = ctx.glCreateProgram();
205
206         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
207         ctx.glAttachShader(shader1, shader1);
208         ctx.expectError(GL_INVALID_OPERATION);
209         ctx.endSection();
210
211         ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
212         ctx.glAttachShader(program, program);
213         ctx.expectError(GL_INVALID_OPERATION);
214         ctx.glAttachShader(shader1, program);
215         ctx.expectError(GL_INVALID_OPERATION);
216         ctx.endSection();
217
218         ctx.beginSection("GL_INVALID_VALUE is generated if either program or shader is not a value generated by OpenGL.");
219         ctx.glAttachShader(program, -1);
220         ctx.expectError(GL_INVALID_VALUE);
221         ctx.glAttachShader(-1, shader1);
222         ctx.expectError(GL_INVALID_VALUE);
223         ctx.glAttachShader(-1, -1);
224         ctx.expectError(GL_INVALID_VALUE);
225         ctx.endSection();
226
227         ctx.beginSection("GL_INVALID_OPERATION is generated if shader is already attached to program.");
228         ctx.glAttachShader(program, shader1);
229         ctx.expectError(GL_NO_ERROR);
230         ctx.glAttachShader(program, shader1);
231         ctx.expectError(GL_INVALID_OPERATION);
232         ctx.endSection();
233
234         ctx.beginSection("GL_INVALID_OPERATION is generated if a shader of the same type as shader is already attached to program.");
235         ctx.glAttachShader(program, shader2);
236         ctx.expectError(GL_INVALID_OPERATION);
237         ctx.endSection();
238
239         ctx.glDeleteProgram(program);
240         ctx.glDeleteShader(shader1);
241         ctx.glDeleteShader(shader2);
242 }
243
244 void detach_shader (NegativeTestContext& ctx)
245 {
246         GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
247         GLuint program = ctx.glCreateProgram();
248
249         ctx.beginSection("GL_INVALID_VALUE is generated if either program or shader is not a value generated by OpenGL.");
250         ctx.glDetachShader(-1, shader);
251         ctx.expectError(GL_INVALID_VALUE);
252         ctx.glDetachShader(program, -1);
253         ctx.expectError(GL_INVALID_VALUE);
254         ctx.glDetachShader(-1, -1);
255         ctx.expectError(GL_INVALID_VALUE);
256         ctx.endSection();
257
258         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
259         ctx.glDetachShader(shader, shader);
260         ctx.expectError(GL_INVALID_OPERATION);
261         ctx.endSection();
262
263         ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
264         ctx.glDetachShader(program, program);
265         ctx.expectError(GL_INVALID_OPERATION);
266         ctx.glDetachShader(shader, program);
267         ctx.expectError(GL_INVALID_OPERATION);
268         ctx.endSection();
269
270         ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not attached to program.");
271         ctx.glDetachShader(program, shader);
272         ctx.expectError(GL_INVALID_OPERATION);
273         ctx.endSection();
274
275         ctx.glDeleteProgram(program);
276         ctx.glDeleteShader(shader);
277 }
278
279 void link_program (NegativeTestContext& ctx)
280 {
281         GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
282
283         ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
284         ctx.glLinkProgram(-1);
285         ctx.expectError(GL_INVALID_VALUE);
286         ctx.endSection();
287
288         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
289         ctx.glLinkProgram(shader);
290         ctx.expectError(GL_INVALID_OPERATION);
291         ctx.endSection();
292
293         ctx.glDeleteShader(shader);
294
295         ctx.beginSection("GL_INVALID_OPERATION is generated if program is the currently active program object and transform feedback mode is active.");
296         glu::ShaderProgram                      program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
297         deUint32                                        buf = 0x1234;
298         deUint32                                        tfID = 0x1234;
299         const char* tfVarying           = "gl_Position";
300
301         ctx.glGenTransformFeedbacks             (1, &tfID);
302         ctx.glGenBuffers                                (1, &buf);
303
304         ctx.glUseProgram                                (program.getProgram());
305         ctx.glTransformFeedbackVaryings (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
306         ctx.glLinkProgram                               (program.getProgram());
307         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID);
308         ctx.glBindBuffer                                (GL_TRANSFORM_FEEDBACK_BUFFER, buf);
309         ctx.glBufferData                                (GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
310         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
311         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
312         ctx.expectError                                 (GL_NO_ERROR);
313
314         ctx.glLinkProgram                               (program.getProgram());
315         ctx.expectError                         (GL_INVALID_OPERATION);
316
317         ctx.glEndTransformFeedback              ();
318         ctx.glDeleteTransformFeedbacks  (1, &tfID);
319         ctx.glDeleteBuffers                             (1, &buf);
320         ctx.expectError                         (GL_NO_ERROR);
321         ctx.endSection();
322 }
323
324 void use_program (NegativeTestContext& ctx)
325 {
326         GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
327
328         ctx.beginSection("GL_INVALID_VALUE is generated if program is neither 0 nor a value generated by OpenGL.");
329         ctx.glUseProgram(-1);
330         ctx.expectError(GL_INVALID_VALUE);
331         ctx.endSection();
332
333         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
334         ctx.glUseProgram(shader);
335         ctx.expectError(GL_INVALID_OPERATION);
336         ctx.endSection();
337
338         ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback mode is active and not paused.");
339         glu::ShaderProgram                      program1(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
340         glu::ShaderProgram                      program2(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
341         deUint32                                        buf = 0x1234;
342         deUint32                                        tfID = 0x1234;
343         const char* tfVarying           = "gl_Position";
344
345         ctx.glGenTransformFeedbacks             (1, &tfID);
346         ctx.glGenBuffers                                (1, &buf);
347
348         ctx.glUseProgram                                (program1.getProgram());
349         ctx.glTransformFeedbackVaryings (program1.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
350         ctx.glLinkProgram                               (program1.getProgram());
351         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID);
352         ctx.glBindBuffer                                (GL_TRANSFORM_FEEDBACK_BUFFER, buf);
353         ctx.glBufferData                                (GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
354         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
355         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
356         ctx.expectError                                 (GL_NO_ERROR);
357
358         ctx.glUseProgram                                (program2.getProgram());
359         ctx.expectError                         (GL_INVALID_OPERATION);
360
361         ctx.glPauseTransformFeedback    ();
362         ctx.glUseProgram                                (program2.getProgram());
363         ctx.expectError                         (GL_NO_ERROR);
364
365         ctx.glEndTransformFeedback              ();
366         ctx.glDeleteTransformFeedbacks  (1, &tfID);
367         ctx.glDeleteBuffers                             (1, &buf);
368         ctx.expectError                         (GL_NO_ERROR);
369         ctx.endSection();
370
371         ctx.glUseProgram(0);
372         ctx.glDeleteShader(shader);
373 }
374
375 void delete_program (NegativeTestContext& ctx)
376 {
377         ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
378         ctx.glDeleteProgram(-1);
379         ctx.expectError(GL_INVALID_VALUE);
380         ctx.endSection();
381 }
382
383 void validate_program (NegativeTestContext& ctx)
384 {
385         GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
386
387         ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
388         ctx.glValidateProgram(-1);
389         ctx.expectError(GL_INVALID_VALUE);
390         ctx.endSection();
391
392         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
393         ctx.glValidateProgram(shader);
394         ctx.expectError(GL_INVALID_OPERATION);
395         ctx.endSection();
396
397         ctx.glDeleteShader(shader);
398 }
399
400 void get_program_binary (NegativeTestContext& ctx)
401 {
402         glu::ShaderProgram                              program                 (ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
403         glu::ShaderProgram                              programInvalid  (ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, ""));
404         GLenum                                                  binaryFormat    = -1;
405         GLsizei                                                 binaryLength    = -1;
406         GLint                                                   binaryPtr               = -1;
407         GLint                                                   bufSize                 = -1;
408         GLint                                                   linkStatus              = -1;
409
410         ctx.beginSection("GL_INVALID_OPERATION is generated if bufSize is less than the size of GL_PROGRAM_BINARY_LENGTH for program.");
411         ctx.glGetProgramiv              (program.getProgram(), GL_PROGRAM_BINARY_LENGTH,        &bufSize);
412         ctx.expectError         (GL_NO_ERROR);
413         ctx.glGetProgramiv              (program.getProgram(), GL_LINK_STATUS,                          &linkStatus);
414         ctx.getLog() << TestLog::Message << "// GL_PROGRAM_BINARY_LENGTH = " << bufSize << TestLog::EndMessage;
415         ctx.getLog() << TestLog::Message << "// GL_LINK_STATUS = " << linkStatus << TestLog::EndMessage;
416         ctx.expectError         (GL_NO_ERROR);
417
418         ctx.glGetProgramBinary  (program.getProgram(), 0, &binaryLength, &binaryFormat, &binaryPtr);
419         ctx.expectError         (GL_INVALID_OPERATION);
420         if (bufSize > 0)
421         {
422                 ctx.glGetProgramBinary  (program.getProgram(), bufSize-1, &binaryLength, &binaryFormat, &binaryPtr);
423                 ctx.expectError         (GL_INVALID_OPERATION);
424         }
425         ctx.endSection();
426
427         ctx.beginSection("GL_INVALID_OPERATION is generated if GL_LINK_STATUS for the program object is false.");
428         ctx.glGetProgramiv              (programInvalid.getProgram(), GL_PROGRAM_BINARY_LENGTH, &bufSize);
429         ctx.expectError         (GL_NO_ERROR);
430         ctx.glGetProgramiv              (programInvalid.getProgram(), GL_LINK_STATUS,                   &linkStatus);
431         ctx.getLog() << TestLog::Message << "// GL_PROGRAM_BINARY_LENGTH = " << bufSize << TestLog::EndMessage;
432         ctx.getLog() << TestLog::Message << "// GL_LINK_STATUS = " << linkStatus << TestLog::EndMessage;
433         ctx.expectError         (GL_NO_ERROR);
434
435         ctx.glGetProgramBinary  (programInvalid.getProgram(), bufSize, &binaryLength, &binaryFormat, &binaryPtr);
436         ctx.expectError         (GL_INVALID_OPERATION);
437         ctx.endSection();
438 }
439
440 void program_binary (NegativeTestContext& ctx)
441 {
442         glu::ShaderProgram              srcProgram              (ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
443         GLuint                                  dstProgram              = ctx.glCreateProgram();
444         GLuint                                  dummyShader             = ctx.glCreateShader(GL_VERTEX_SHADER);
445         GLenum                                  binaryFormat    = -1;
446         GLsizei                                 binaryLength    = -1;
447         std::vector<deUint8>    binaryBuf;
448         GLint                                   bufSize                 = -1;
449         GLint                                   linkStatus              = -1;
450
451         ctx.glGetProgramiv              (srcProgram.getProgram(), GL_PROGRAM_BINARY_LENGTH,     &bufSize);
452         ctx.glGetProgramiv              (srcProgram.getProgram(), GL_LINK_STATUS,                       &linkStatus);
453         ctx.getLog() << TestLog::Message << "// GL_PROGRAM_BINARY_LENGTH = " << bufSize << TestLog::EndMessage;
454         ctx.getLog() << TestLog::Message << "// GL_LINK_STATUS = " << linkStatus << TestLog::EndMessage;
455
456         TCU_CHECK(bufSize >= 0);
457         if (bufSize > 0)
458         {
459                 binaryBuf.resize(bufSize);
460                 ctx.glGetProgramBinary  (srcProgram.getProgram(), bufSize, &binaryLength, &binaryFormat, &binaryBuf[0]);
461                 ctx.expectError                 (GL_NO_ERROR);
462
463                 ctx.beginSection("GL_INVALID_OPERATION is generated if program is not the name of an existing program object.");
464                 ctx.glProgramBinary             (dummyShader, binaryFormat, &binaryBuf[0], binaryLength);
465                 ctx.expectError                 (GL_INVALID_OPERATION);
466                 ctx.endSection();
467
468                 ctx.beginSection("GL_INVALID_ENUM is generated if binaryFormat is not a value recognized by the implementation.");
469                 ctx.glProgramBinary             (dstProgram, -1, &binaryBuf[0], binaryLength);
470                 ctx.expectError                 (GL_INVALID_ENUM);
471                 ctx.endSection();
472         }
473
474         ctx.glDeleteShader(dummyShader);
475         ctx.glDeleteProgram(dstProgram);
476 }
477
478 void program_parameteri (NegativeTestContext& ctx)
479 {
480         GLuint  program = ctx.glCreateProgram();
481
482         ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of an existing program object.");
483         ctx.glProgramParameteri         (0, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
484         ctx.expectError                 (GL_INVALID_VALUE);
485         ctx.endSection();
486
487         ctx.beginSection("GL_INVALID_ENUM is generated if pname is not GL_PROGRAM_BINARY_RETRIEVABLE_HINT.");
488         ctx.glProgramParameteri         (program, -1, GL_TRUE);
489         ctx.expectError                 (GL_INVALID_ENUM);
490         ctx.endSection();
491
492         ctx.beginSection("GL_INVALID_VALUE is generated if value is not GL_FALSE or GL_TRUE.");
493         ctx.glProgramParameteri         (program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, 2);
494         ctx.expectError                 (GL_INVALID_VALUE);
495         ctx.endSection();
496
497         ctx.glDeleteProgram(program);
498 }
499
500 void gen_samplers (NegativeTestContext& ctx)
501 {
502         ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
503         GLuint sampler = 0;
504         ctx.glGenSamplers       (-1, &sampler);
505         ctx.expectError (GL_INVALID_VALUE);
506         ctx.endSection();
507 }
508
509 void bind_sampler (NegativeTestContext& ctx)
510 {
511         int                             maxTexImageUnits = 0x1234;
512         GLuint                  sampler = 0;
513         ctx.glGetIntegerv       (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTexImageUnits);
514         ctx.glGenSamplers       (1, &sampler);
515
516         ctx.beginSection("GL_INVALID_VALUE is generated if unit is greater than or equal to the value of GL_MAX_COMBIED_TEXTURE_IMAGE_UNITS.");
517         ctx.glBindSampler       (maxTexImageUnits, sampler);
518         ctx.expectError (GL_INVALID_VALUE);
519         ctx.endSection();
520
521         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not zero or a name previously returned from a call to ctx.glGenSamplers.");
522         ctx.glBindSampler       (1, -1);
523         ctx.expectError (GL_INVALID_OPERATION);
524         ctx.endSection();
525
526         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler has been deleted by a call to ctx.glDeleteSamplers.");
527         ctx.glDeleteSamplers(1, &sampler);
528         ctx.glBindSampler       (1, sampler);
529         ctx.expectError (GL_INVALID_OPERATION);
530         ctx.endSection();
531 }
532
533 void delete_samplers (NegativeTestContext& ctx)
534 {
535         ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
536         ctx.glDeleteSamplers(-1, 0);
537         ctx.expectError (GL_INVALID_VALUE);
538         ctx.endSection();
539 }
540
541 void get_sampler_parameteriv (NegativeTestContext& ctx)
542 {
543         int                             params = 0x1234;
544         GLuint                  sampler = 0;
545         ctx.glGenSamplers       (1, &sampler);
546
547         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object returned from a previous call to ctx.glGenSamplers.");
548         ctx.glGetSamplerParameteriv     (-1, GL_TEXTURE_MAG_FILTER, &params);
549         ctx.expectError                 (GL_INVALID_OPERATION);
550         ctx.endSection();
551
552         ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted value.");
553         ctx.glGetSamplerParameteriv     (sampler, -1, &params);
554         ctx.expectError                 (GL_INVALID_ENUM);
555         ctx.endSection();
556
557         ctx.glDeleteSamplers(1, &sampler);
558 }
559
560 void get_sampler_parameterfv (NegativeTestContext& ctx)
561 {
562         float                           params  = 0.0f;
563         GLuint                          sampler = 0;
564         ctx.glGenSamplers       (1, &sampler);
565
566         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object returned from a previous call to ctx.glGenSamplers.");
567         ctx.glGetSamplerParameterfv     (-1, GL_TEXTURE_MAG_FILTER, &params);
568         ctx.expectError                 (GL_INVALID_OPERATION);
569         ctx.endSection();
570
571         ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted value.");
572         ctx.glGetSamplerParameterfv     (sampler, -1, &params);
573         ctx.expectError                 (GL_INVALID_ENUM);
574         ctx.endSection();
575
576         ctx.glDeleteSamplers(1, &sampler);
577 }
578
579 void sampler_parameteri (NegativeTestContext& ctx)
580 {
581         GLuint                  sampler = 0;
582         ctx.glGenSamplers       (1, &sampler);
583
584         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously returned from a call to ctx.glGenSamplers.");
585         ctx.glSamplerParameteri         (-1, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
586         ctx.expectError                 (GL_INVALID_OPERATION);
587         ctx.endSection();
588
589         ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value of pname) and does not.");
590         ctx.glSamplerParameteri         (sampler, GL_TEXTURE_WRAP_S, -1);
591         ctx.expectError                 (GL_INVALID_ENUM);
592         ctx.endSection();
593
594         ctx.glDeleteSamplers(1, &sampler);
595 }
596
597 void sampler_parameteriv (NegativeTestContext& ctx)
598 {
599         int                             params = 0x1234;
600         GLuint                  sampler = 0;
601         ctx.glGenSamplers       (1, &sampler);
602
603         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously returned from a call to ctx.glGenSamplers.");
604         params = GL_CLAMP_TO_EDGE;
605         ctx.glSamplerParameteriv        (-1, GL_TEXTURE_WRAP_S, &params);
606         ctx.expectError                 (GL_INVALID_OPERATION);
607         ctx.endSection();
608
609         ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value of pname) and does not.");
610         params = -1;
611         ctx.glSamplerParameteriv        (sampler, GL_TEXTURE_WRAP_S, &params);
612         ctx.expectError                 (GL_INVALID_ENUM);
613         ctx.endSection();
614
615         ctx.glDeleteSamplers(1, &sampler);
616 }
617
618 void sampler_parameterf (NegativeTestContext& ctx)
619 {
620         GLuint                  sampler = 0;
621         ctx.glGenSamplers       (1, &sampler);
622
623         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously returned from a call to ctx.glGenSamplers.");
624         ctx.glSamplerParameterf         (-1, GL_TEXTURE_MIN_LOD, -1000.0f);
625         ctx.expectError                 (GL_INVALID_OPERATION);
626         ctx.endSection();
627
628         ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value of pname) and does not.");
629         ctx.glSamplerParameterf         (sampler, GL_TEXTURE_WRAP_S, -1.0f);
630         ctx.expectError                 (GL_INVALID_ENUM);
631         ctx.endSection();
632
633         ctx.glDeleteSamplers(1, &sampler);
634 }
635
636 void sampler_parameterfv (NegativeTestContext& ctx)
637 {
638         float                   params;
639         GLuint                  sampler = 0;
640         ctx.glGenSamplers       (1, &sampler);
641
642         ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously returned from a call to ctx.glGenSamplers.");
643         params = -1000.0f;
644         ctx.glSamplerParameterfv        (-1, GL_TEXTURE_WRAP_S, &params);
645         ctx.expectError                 (GL_INVALID_OPERATION);
646         ctx.endSection();
647
648         ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value of pname) and does not.");
649         params = -1.0f;
650         ctx.glSamplerParameterfv        (sampler, GL_TEXTURE_WRAP_S, &params);
651         ctx.expectError                 (GL_INVALID_ENUM);
652         ctx.endSection();
653
654         ctx.glDeleteSamplers(1, &sampler);
655 }
656
657 // Shader data commands
658
659 void get_attrib_location (NegativeTestContext& ctx)
660 {
661         GLuint programEmpty             = ctx.glCreateProgram();
662         GLuint shader                   = ctx.glCreateShader(GL_VERTEX_SHADER);
663
664         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
665
666         ctx.beginSection("GL_INVALID_OPERATION is generated if program has not been successfully linked.");
667         ctx.glBindAttribLocation                (programEmpty, 0, "test");
668         ctx.glGetAttribLocation                 (programEmpty, "test");
669         ctx.expectError                         (GL_INVALID_OPERATION);
670         ctx.endSection();
671
672         ctx.beginSection("GL_INVALID_VALUE is generated if program is not a program or shader object.");
673         ctx.glUseProgram                                (program.getProgram());
674         ctx.glBindAttribLocation                (program.getProgram(), 0, "test");
675         ctx.expectError                         (GL_NO_ERROR);
676         ctx.glGetAttribLocation                 (program.getProgram(), "test");
677         ctx.expectError                         (GL_NO_ERROR);
678         ctx.glGetAttribLocation                 (-2, "test");
679         ctx.expectError                         (GL_INVALID_VALUE);
680         ctx.endSection();
681
682         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
683         ctx.glGetAttribLocation                 (shader, "test");
684         ctx.expectError                         (GL_INVALID_OPERATION);
685         ctx.endSection();
686
687         ctx.glUseProgram                                (0);
688         ctx.glDeleteShader                              (shader);
689         ctx.glDeleteProgram                             (programEmpty);
690 }
691
692 void get_uniform_location (NegativeTestContext& ctx)
693 {
694         GLuint programEmpty = ctx.glCreateProgram();
695         GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
696
697         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
698
699         ctx.beginSection("GL_INVALID_OPERATION is generated if program has not been successfully linked.");
700         ctx.glGetUniformLocation(programEmpty, "test");
701         ctx.expectError(GL_INVALID_OPERATION);
702         ctx.endSection();
703
704         ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
705         ctx.glUseProgram(program.getProgram());
706         ctx.glGetUniformLocation(-2, "test");
707         ctx.expectError(GL_INVALID_VALUE);
708         ctx.endSection();
709
710         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
711         ctx.glGetAttribLocation(shader, "test");
712         ctx.expectError(GL_INVALID_OPERATION);
713         ctx.endSection();
714
715         ctx.glUseProgram(0);
716         ctx.glDeleteProgram(programEmpty);
717         ctx.glDeleteShader(shader);
718 }
719
720 void bind_attrib_location (NegativeTestContext& ctx)
721 {
722         GLuint program = ctx.glCreateProgram();
723         GLuint maxIndex = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
724         GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
725
726         ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
727         ctx.glBindAttribLocation(program, maxIndex, "test");
728         ctx.expectError(GL_INVALID_VALUE);
729         ctx.endSection();
730
731         ctx.beginSection("GL_INVALID_OPERATION is generated if name starts with the reserved prefix \"gl_\".");
732         ctx.glBindAttribLocation(program, maxIndex-1, "gl_test");
733         ctx.expectError(GL_INVALID_OPERATION);
734         ctx.endSection();
735
736         ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
737         ctx.glBindAttribLocation(-1, maxIndex-1, "test");
738         ctx.expectError(GL_INVALID_VALUE);
739         ctx.endSection();
740
741         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
742         ctx.glBindAttribLocation(shader, maxIndex-1, "test");
743         ctx.expectError(GL_INVALID_OPERATION);
744         ctx.endSection();
745
746         ctx.glDeleteProgram(program);
747         ctx.glDeleteShader(shader);
748 }
749
750 void uniform_block_binding (NegativeTestContext& ctx)
751 {
752         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformBlockVertSource, uniformTestFragSource));
753
754         ctx.glUseProgram        (program.getProgram());
755
756         GLint                   maxUniformBufferBindings        = -1;
757         GLint                   numActiveUniforms                       = -1;
758         GLint                   numActiveBlocks                         = -1;
759         ctx.glGetIntegerv       (GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings);
760         ctx.glGetProgramiv      (program.getProgram(), GL_ACTIVE_UNIFORMS,                      &numActiveUniforms);
761         ctx.glGetProgramiv      (program.getProgram(), GL_ACTIVE_UNIFORM_BLOCKS,        &numActiveBlocks);
762         ctx.getLog() << TestLog::Message << "// GL_MAX_UNIFORM_BUFFER_BINDINGS = " << maxUniformBufferBindings << TestLog::EndMessage;
763         ctx.getLog() << TestLog::Message << "// GL_ACTIVE_UNIFORMS = "                          << numActiveUniforms            << TestLog::EndMessage;
764         ctx.getLog() << TestLog::Message << "// GL_ACTIVE_UNIFORM_BLOCKS = "            << numActiveBlocks                      << TestLog::EndMessage;
765         ctx.expectError (GL_NO_ERROR);
766
767         ctx.beginSection("GL_INVALID_VALUE is generated if uniformBlockIndex is not an active uniform block index of program.");
768         ctx.glUniformBlockBinding(program.getProgram(), -1, 0);
769         ctx.expectError(GL_INVALID_VALUE);
770         ctx.glUniformBlockBinding(program.getProgram(), 5, 0);
771         ctx.expectError(GL_INVALID_VALUE);
772         ctx.endSection();
773
774         ctx.beginSection("GL_INVALID_VALUE is generated if uniformBlockBinding is greater than or equal to the value of GL_MAX_UNIFORM_BUFFER_BINDINGS.");
775         ctx.glUniformBlockBinding(program.getProgram(), maxUniformBufferBindings, 0);
776         ctx.expectError(GL_INVALID_VALUE);
777         ctx.endSection();
778
779         ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of a program object generated by the GL.");
780         ctx.glUniformBlockBinding(-1, 0, 0);
781         ctx.expectError(GL_INVALID_VALUE);
782         ctx.endSection();
783 }
784
785 // ctx.glUniform*f
786
787 void uniformf_invalid_program (NegativeTestContext& ctx)
788 {
789         ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
790         ctx.glUseProgram(0);
791         ctx.glUniform1f(-1, 0.0f);
792         ctx.expectError(GL_INVALID_OPERATION);
793         ctx.glUniform2f(-1, 0.0f, 0.0f);
794         ctx.expectError(GL_INVALID_OPERATION);
795         ctx.glUniform3f(-1, 0.0f, 0.0f, 0.0f);
796         ctx.expectError(GL_INVALID_OPERATION);
797         ctx.glUniform4f(-1, 0.0f, 0.0f, 0.0f, 0.0f);
798         ctx.expectError(GL_INVALID_OPERATION);
799         ctx.endSection();
800 }
801
802 void uniformf_incompatible_type (NegativeTestContext& ctx)
803 {
804         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
805
806         ctx.glUseProgram(program.getProgram());
807         GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");     // vec4
808         GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");    // ivec4
809         GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");    // uvec4
810         GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f");  // sampler2D
811         ctx.expectError(GL_NO_ERROR);
812
813         if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
814         {
815                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
816                 ctx.fail("Failed to retrieve uniform location");
817         }
818
819         ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the ctx.glUniform command.");
820         ctx.glUseProgram(program.getProgram());
821         ctx.glUniform1f(vec4_v, 0.0f);
822         ctx.expectError(GL_INVALID_OPERATION);
823         ctx.glUniform2f(vec4_v, 0.0f, 0.0f);
824         ctx.expectError(GL_INVALID_OPERATION);
825         ctx.glUniform3f(vec4_v, 0.0f, 0.0f, 0.0f);
826         ctx.expectError(GL_INVALID_OPERATION);
827         ctx.glUniform4f(vec4_v, 0.0f, 0.0f, 0.0f, 0.0f);
828         ctx.expectError(GL_NO_ERROR);
829         ctx.endSection();
830
831         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}f is used to load a uniform variable of type int, ivec2, ivec3, ivec4, unsigned int, uvec2, uvec3, uvec4.");
832         ctx.glUseProgram(program.getProgram());
833         ctx.glUniform4f(ivec4_f, 0.0f, 0.0f, 0.0f, 0.0f);
834         ctx.expectError(GL_INVALID_OPERATION);
835         ctx.glUniform4f(uvec4_f, 0.0f, 0.0f, 0.0f, 0.0f);
836         ctx.expectError(GL_INVALID_OPERATION);
837         ctx.endSection();
838
839         ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than ctx.glUniform1i and ctx.glUniform1iv.");
840         ctx.glUseProgram(program.getProgram());
841         ctx.glUniform1f(sampler_f, 0.0f);
842         ctx.expectError(GL_INVALID_OPERATION);
843         ctx.endSection();
844
845         ctx.glUseProgram(0);
846 }
847
848 void uniformf_invalid_location (NegativeTestContext& ctx)
849 {
850         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
851
852         ctx.glUseProgram(program.getProgram());
853         ctx.expectError(GL_NO_ERROR);
854
855         ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.");
856         ctx.glUseProgram(program.getProgram());
857         ctx.glUniform1f(-2, 0.0f);
858         ctx.expectError(GL_INVALID_OPERATION);
859         ctx.glUniform2f(-2, 0.0f, 0.0f);
860         ctx.expectError(GL_INVALID_OPERATION);
861         ctx.glUniform3f(-2, 0.0f, 0.0f, 0.0f);
862         ctx.expectError(GL_INVALID_OPERATION);
863         ctx.glUniform4f(-2, 0.0f, 0.0f, 0.0f, 0.0f);
864         ctx.expectError(GL_INVALID_OPERATION);
865
866         ctx.glUseProgram(program.getProgram());
867         ctx.glUniform1f(-1, 0.0f);
868         ctx.expectError(GL_NO_ERROR);
869         ctx.glUniform2f(-1, 0.0f, 0.0f);
870         ctx.expectError(GL_NO_ERROR);
871         ctx.glUniform3f(-1, 0.0f, 0.0f, 0.0f);
872         ctx.expectError(GL_NO_ERROR);
873         ctx.glUniform4f(-1, 0.0f, 0.0f, 0.0f, 0.0f);
874         ctx.expectError(GL_NO_ERROR);
875         ctx.endSection();
876
877         ctx.glUseProgram(0);
878 }
879
880 // ctx.glUniform*fv
881
882 void uniformfv_invalid_program (NegativeTestContext& ctx)
883 {
884         std::vector<GLfloat> data(4);
885
886         ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
887         ctx.glUseProgram(0);
888         ctx.glUniform1fv(-1, 1, &data[0]);
889         ctx.expectError(GL_INVALID_OPERATION);
890         ctx.glUniform2fv(-1, 1, &data[0]);
891         ctx.expectError(GL_INVALID_OPERATION);
892         ctx.glUniform3fv(-1, 1, &data[0]);
893         ctx.expectError(GL_INVALID_OPERATION);
894         ctx.glUniform4fv(-1, 1, &data[0]);
895         ctx.expectError(GL_INVALID_OPERATION);
896         ctx.endSection();
897 }
898
899 void uniformfv_incompatible_type (NegativeTestContext& ctx)
900 {
901         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
902
903         ctx.glUseProgram(program.getProgram());
904         GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");     // vec4
905         GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");    // ivec4
906         GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");    // uvec4
907         GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f");  // sampler2D
908         ctx.expectError(GL_NO_ERROR);
909
910         if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
911         {
912                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
913                 ctx.fail("Failed to retrieve uniform location");
914         }
915
916         std::vector<GLfloat> data(4);
917
918         ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the ctx.glUniform command.");
919         ctx.glUseProgram(program.getProgram());
920         ctx.glUniform1fv(vec4_v, 1, &data[0]);
921         ctx.expectError(GL_INVALID_OPERATION);
922         ctx.glUniform2fv(vec4_v, 1, &data[0]);
923         ctx.expectError(GL_INVALID_OPERATION);
924         ctx.glUniform3fv(vec4_v, 1, &data[0]);
925         ctx.expectError(GL_INVALID_OPERATION);
926         ctx.glUniform4fv(vec4_v, 1, &data[0]);
927         ctx.expectError(GL_NO_ERROR);
928         ctx.endSection();
929
930         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}fv is used to load a uniform variable of type int, ivec2, ivec3, ivec4, unsigned int, uvec2, uvec3, uvec4.");
931         ctx.glUseProgram(program.getProgram());
932         ctx.glUniform4fv(ivec4_f, 1, &data[0]);
933         ctx.expectError(GL_INVALID_OPERATION);
934         ctx.glUniform4fv(uvec4_f, 1, &data[0]);
935         ctx.expectError(GL_INVALID_OPERATION);
936         ctx.endSection();
937
938         ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than ctx.glUniform1i and ctx.glUniform1iv.");
939         ctx.glUseProgram(program.getProgram());
940         ctx.glUniform1fv(sampler_f, 1, &data[0]);
941         ctx.expectError(GL_INVALID_OPERATION);
942         ctx.endSection();
943
944         ctx.glUseProgram(0);
945 }
946
947 void uniformfv_invalid_location (NegativeTestContext& ctx)
948 {
949         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
950
951         ctx.glUseProgram(program.getProgram());
952         ctx.expectError(GL_NO_ERROR);
953
954         std::vector<GLfloat> data(4);
955
956         ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.");
957         ctx.glUseProgram(program.getProgram());
958         ctx.glUniform1fv(-2, 1, &data[0]);
959         ctx.expectError(GL_INVALID_OPERATION);
960         ctx.glUniform2fv(-2, 1, &data[0]);
961         ctx.expectError(GL_INVALID_OPERATION);
962         ctx.glUniform3fv(-2, 1, &data[0]);
963         ctx.expectError(GL_INVALID_OPERATION);
964         ctx.glUniform4fv(-2, 1, &data[0]);
965         ctx.expectError(GL_INVALID_OPERATION);
966
967         ctx.glUseProgram(program.getProgram());
968         ctx.glUniform1fv(-1, 1, &data[0]);
969         ctx.expectError(GL_NO_ERROR);
970         ctx.glUniform2fv(-1, 1, &data[0]);
971         ctx.expectError(GL_NO_ERROR);
972         ctx.glUniform3fv(-1, 1, &data[0]);
973         ctx.expectError(GL_NO_ERROR);
974         ctx.glUniform4fv(-1, 1, &data[0]);
975         ctx.expectError(GL_NO_ERROR);
976         ctx.endSection();
977
978         ctx.glUseProgram(0);
979 }
980
981 void uniformfv_invalid_count (NegativeTestContext& ctx)
982 {
983         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
984
985         ctx.glUseProgram        (program.getProgram());
986         GLint vec4_v                    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");     // vec4
987         ctx.expectError(GL_NO_ERROR);
988
989         if (vec4_v == -1)
990         {
991                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
992                 ctx.fail("Failed to retrieve uniform location");
993         }
994
995         std::vector<GLfloat> data(8);
996
997         ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable is not an array variable.");
998         ctx.glUseProgram(program.getProgram());
999         ctx.glUniform1fv(vec4_v, 2, &data[0]);
1000         ctx.expectError(GL_INVALID_OPERATION);
1001         ctx.glUniform2fv(vec4_v, 2, &data[0]);
1002         ctx.expectError(GL_INVALID_OPERATION);
1003         ctx.glUniform3fv(vec4_v, 2, &data[0]);
1004         ctx.expectError(GL_INVALID_OPERATION);
1005         ctx.glUniform4fv(vec4_v, 2, &data[0]);
1006         ctx.expectError(GL_INVALID_OPERATION);
1007         ctx.endSection();
1008
1009         ctx.glUseProgram(0);
1010 }
1011
1012 // ctx.glUniform*i
1013
1014 void uniformi_invalid_program (NegativeTestContext& ctx)
1015 {
1016         ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1017         ctx.glUseProgram(0);
1018         ctx.glUniform1i(-1, 0);
1019         ctx.expectError(GL_INVALID_OPERATION);
1020         ctx.glUniform2i(-1, 0, 0);
1021         ctx.expectError(GL_INVALID_OPERATION);
1022         ctx.glUniform3i(-1, 0, 0, 0);
1023         ctx.expectError(GL_INVALID_OPERATION);
1024         ctx.glUniform4i(-1, 0, 0, 0, 0);
1025         ctx.expectError(GL_INVALID_OPERATION);
1026         ctx.endSection();
1027 }
1028
1029 void uniformi_incompatible_type (NegativeTestContext& ctx)
1030 {
1031         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1032
1033         ctx.glUseProgram(program.getProgram());
1034         GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");     // vec4
1035         GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");    // ivec4
1036         GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");    // uvec4
1037         GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f");  // sampler2D
1038         ctx.expectError(GL_NO_ERROR);
1039
1040         if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1041         {
1042                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1043                 ctx.fail("Failed to retrieve uniform location");
1044         }
1045
1046         ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the ctx.glUniform command.");
1047         ctx.glUseProgram(program.getProgram());
1048         ctx.glUniform1i(ivec4_f, 0);
1049         ctx.expectError(GL_INVALID_OPERATION);
1050         ctx.glUniform2i(ivec4_f, 0, 0);
1051         ctx.expectError(GL_INVALID_OPERATION);
1052         ctx.glUniform3i(ivec4_f, 0, 0, 0);
1053         ctx.expectError(GL_INVALID_OPERATION);
1054         ctx.glUniform4i(ivec4_f, 0, 0, 0, 0);
1055         ctx.expectError(GL_NO_ERROR);
1056         ctx.endSection();
1057
1058         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of type unsigned int, uvec2, uvec3, uvec4, or an array of these.");
1059         ctx.glUseProgram(program.getProgram());
1060         ctx.glUniform1i(uvec4_f, 0);
1061         ctx.expectError(GL_INVALID_OPERATION);
1062         ctx.glUniform2i(uvec4_f, 0, 0);
1063         ctx.expectError(GL_INVALID_OPERATION);
1064         ctx.glUniform3i(uvec4_f, 0, 0, 0);
1065         ctx.expectError(GL_INVALID_OPERATION);
1066         ctx.glUniform4i(uvec4_f, 0, 0, 0, 0);
1067         ctx.expectError(GL_INVALID_OPERATION);
1068         ctx.endSection();
1069
1070         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of type float, vec2, vec3, or vec4.");
1071         ctx.glUseProgram(program.getProgram());
1072         ctx.glUniform1i(vec4_v, 0);
1073         ctx.expectError(GL_INVALID_OPERATION);
1074         ctx.glUniform2i(vec4_v, 0, 0);
1075         ctx.expectError(GL_INVALID_OPERATION);
1076         ctx.glUniform3i(vec4_v, 0, 0, 0);
1077         ctx.expectError(GL_INVALID_OPERATION);
1078         ctx.glUniform4i(vec4_v, 0, 0, 0, 0);
1079         ctx.expectError(GL_INVALID_OPERATION);
1080         ctx.endSection();
1081
1082         ctx.glUseProgram(0);
1083 }
1084
1085 void uniformi_invalid_location (NegativeTestContext& ctx)
1086 {
1087         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1088
1089         ctx.glUseProgram(program.getProgram());
1090         ctx.expectError(GL_NO_ERROR);
1091
1092         ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.");
1093         ctx.glUseProgram(program.getProgram());
1094         ctx.glUniform1i(-2, 0);
1095         ctx.expectError(GL_INVALID_OPERATION);
1096         ctx.glUniform2i(-2, 0, 0);
1097         ctx.expectError(GL_INVALID_OPERATION);
1098         ctx.glUniform3i(-2, 0, 0, 0);
1099         ctx.expectError(GL_INVALID_OPERATION);
1100         ctx.glUniform4i(-2, 0, 0, 0, 0);
1101         ctx.expectError(GL_INVALID_OPERATION);
1102
1103         ctx.glUseProgram(program.getProgram());
1104         ctx.glUniform1i(-1, 0);
1105         ctx.expectError(GL_NO_ERROR);
1106         ctx.glUniform2i(-1, 0, 0);
1107         ctx.expectError(GL_NO_ERROR);
1108         ctx.glUniform3i(-1, 0, 0, 0);
1109         ctx.expectError(GL_NO_ERROR);
1110         ctx.glUniform4i(-1, 0, 0, 0, 0);
1111         ctx.expectError(GL_NO_ERROR);
1112         ctx.endSection();
1113
1114         ctx.glUseProgram(0);
1115 }
1116
1117 // ctx.glUniform*iv
1118
1119 void uniformiv_invalid_program (NegativeTestContext& ctx)
1120 {
1121         std::vector<GLint> data(4);
1122
1123         ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1124         ctx.glUseProgram(0);
1125         ctx.glUniform1iv(-1, 1, &data[0]);
1126         ctx.expectError(GL_INVALID_OPERATION);
1127         ctx.glUniform2iv(-1, 1, &data[0]);
1128         ctx.expectError(GL_INVALID_OPERATION);
1129         ctx.glUniform3iv(-1, 1, &data[0]);
1130         ctx.expectError(GL_INVALID_OPERATION);
1131         ctx.glUniform4iv(-1, 1, &data[0]);
1132         ctx.expectError(GL_INVALID_OPERATION);
1133         ctx.endSection();
1134 }
1135
1136 void uniformiv_incompatible_type (NegativeTestContext& ctx)
1137 {
1138         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1139
1140         ctx.glUseProgram(program.getProgram());
1141         GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");     // vec4
1142         GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");    // ivec4
1143         GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");    // uvec4
1144         GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f");  // sampler2D
1145         ctx.expectError(GL_NO_ERROR);
1146
1147         if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1148         {
1149                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1150                 ctx.fail("Failed to retrieve uniform location");
1151         }
1152
1153         std::vector<GLint> data(4);
1154
1155         ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the ctx.glUniform command.");
1156         ctx.glUseProgram(program.getProgram());
1157         ctx.glUniform1iv(ivec4_f, 1, &data[0]);
1158         ctx.expectError(GL_INVALID_OPERATION);
1159         ctx.glUniform2iv(ivec4_f, 1, &data[0]);
1160         ctx.expectError(GL_INVALID_OPERATION);
1161         ctx.glUniform3iv(ivec4_f, 1, &data[0]);
1162         ctx.expectError(GL_INVALID_OPERATION);
1163         ctx.glUniform4iv(ivec4_f, 1, &data[0]);
1164         ctx.expectError(GL_NO_ERROR);
1165         ctx.endSection();
1166
1167         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}iv is used to load a uniform variable of type float, vec2, vec3, or vec4.");
1168         ctx.glUseProgram(program.getProgram());
1169         ctx.glUniform1iv(vec4_v, 1, &data[0]);
1170         ctx.expectError(GL_INVALID_OPERATION);
1171         ctx.glUniform2iv(vec4_v, 1, &data[0]);
1172         ctx.expectError(GL_INVALID_OPERATION);
1173         ctx.glUniform3iv(vec4_v, 1, &data[0]);
1174         ctx.expectError(GL_INVALID_OPERATION);
1175         ctx.glUniform4iv(vec4_v, 1, &data[0]);
1176         ctx.expectError(GL_INVALID_OPERATION);
1177         ctx.endSection();
1178
1179         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}iv is used to load a uniform variable of type unsigned int, uvec2, uvec3 or uvec4.");
1180         ctx.glUseProgram(program.getProgram());
1181         ctx.glUniform1iv(uvec4_f, 1, &data[0]);
1182         ctx.expectError(GL_INVALID_OPERATION);
1183         ctx.glUniform2iv(uvec4_f, 1, &data[0]);
1184         ctx.expectError(GL_INVALID_OPERATION);
1185         ctx.glUniform3iv(uvec4_f, 1, &data[0]);
1186         ctx.expectError(GL_INVALID_OPERATION);
1187         ctx.glUniform4iv(uvec4_f, 1, &data[0]);
1188         ctx.expectError(GL_INVALID_OPERATION);
1189         ctx.endSection();
1190
1191         ctx.glUseProgram(0);
1192 }
1193
1194 void uniformiv_invalid_location (NegativeTestContext& ctx)
1195 {
1196         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1197
1198         ctx.glUseProgram(program.getProgram());
1199         ctx.expectError(GL_NO_ERROR);
1200
1201         std::vector<GLint> data(4);
1202
1203         ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.");
1204         ctx.glUseProgram(program.getProgram());
1205         ctx.glUniform1iv(-2, 1, &data[0]);
1206         ctx.expectError(GL_INVALID_OPERATION);
1207         ctx.glUniform2iv(-2, 1, &data[0]);
1208         ctx.expectError(GL_INVALID_OPERATION);
1209         ctx.glUniform3iv(-2, 1, &data[0]);
1210         ctx.expectError(GL_INVALID_OPERATION);
1211         ctx.glUniform4iv(-2, 1, &data[0]);
1212         ctx.expectError(GL_INVALID_OPERATION);
1213
1214         ctx.glUseProgram(program.getProgram());
1215         ctx.glUniform1iv(-1, 1, &data[0]);
1216         ctx.expectError(GL_NO_ERROR);
1217         ctx.glUniform2iv(-1, 1, &data[0]);
1218         ctx.expectError(GL_NO_ERROR);
1219         ctx.glUniform3iv(-1, 1, &data[0]);
1220         ctx.expectError(GL_NO_ERROR);
1221         ctx.glUniform4iv(-1, 1, &data[0]);
1222         ctx.expectError(GL_NO_ERROR);
1223         ctx.endSection();
1224
1225         ctx.glUseProgram(0);
1226 }
1227
1228 void uniformiv_invalid_count (NegativeTestContext& ctx)
1229 {
1230         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1231
1232         ctx.glUseProgram                        (program.getProgram());
1233         GLint ivec4_f                   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f"); // ivec4
1234         ctx.expectError(GL_NO_ERROR);
1235
1236         if (ivec4_f == -1)
1237         {
1238                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1239                 ctx.fail("Failed to retrieve uniform location");
1240         }
1241
1242         std::vector<GLint> data(8);
1243
1244         ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable is not an array variable.");
1245         ctx.glUseProgram(program.getProgram());
1246         ctx.glUniform1iv(ivec4_f, 2, &data[0]);
1247         ctx.expectError(GL_INVALID_OPERATION);
1248         ctx.glUniform2iv(ivec4_f, 2, &data[0]);
1249         ctx.expectError(GL_INVALID_OPERATION);
1250         ctx.glUniform3iv(ivec4_f, 2, &data[0]);
1251         ctx.expectError(GL_INVALID_OPERATION);
1252         ctx.glUniform4iv(ivec4_f, 2, &data[0]);
1253         ctx.expectError(GL_INVALID_OPERATION);
1254         ctx.endSection();
1255
1256         ctx.glUseProgram(0);
1257 }
1258
1259 // ctx.glUniform{1234}ui
1260
1261 void uniformui_invalid_program (NegativeTestContext& ctx)
1262 {
1263         ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1264         ctx.glUseProgram(0);
1265         ctx.glUniform1ui(-1, 0);
1266         ctx.expectError(GL_INVALID_OPERATION);
1267         ctx.glUniform2ui(-1, 0, 0);
1268         ctx.expectError(GL_INVALID_OPERATION);
1269         ctx.glUniform3ui(-1, 0, 0, 0);
1270         ctx.expectError(GL_INVALID_OPERATION);
1271         ctx.glUniform4ui(-1, 0, 0, 0, 0);
1272         ctx.expectError(GL_INVALID_OPERATION);
1273         ctx.endSection();
1274 }
1275
1276 void uniformui_incompatible_type (NegativeTestContext& ctx)
1277 {
1278         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1279
1280         ctx.glUseProgram(program.getProgram());
1281         GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");     // vec4
1282         GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");    // ivec4
1283         GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");    // uvec4
1284         GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f");  // sampler2D
1285         ctx.expectError(GL_NO_ERROR);
1286
1287         if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1288         {
1289                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1290                 ctx.fail("Failed to retrieve uniform location");
1291         }
1292
1293         ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the ctx.glUniform command.");
1294         ctx.glUseProgram(program.getProgram());
1295         ctx.glUniform1ui(uvec4_f, 0);
1296         ctx.expectError(GL_INVALID_OPERATION);
1297         ctx.glUniform2ui(uvec4_f, 0, 0);
1298         ctx.expectError(GL_INVALID_OPERATION);
1299         ctx.glUniform3ui(uvec4_f, 0, 0, 0);
1300         ctx.expectError(GL_INVALID_OPERATION);
1301         ctx.glUniform4ui(uvec4_f, 0, 0, 0, 0);
1302         ctx.expectError(GL_NO_ERROR);
1303         ctx.endSection();
1304
1305         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of type int, ivec2, ivec3, ivec4, or an array of these.");
1306         ctx.glUseProgram(program.getProgram());
1307         ctx.glUniform1ui(ivec4_f, 0);
1308         ctx.expectError(GL_INVALID_OPERATION);
1309         ctx.glUniform2ui(ivec4_f, 0, 0);
1310         ctx.expectError(GL_INVALID_OPERATION);
1311         ctx.glUniform3ui(ivec4_f, 0, 0, 0);
1312         ctx.expectError(GL_INVALID_OPERATION);
1313         ctx.glUniform4ui(ivec4_f, 0, 0, 0, 0);
1314         ctx.expectError(GL_INVALID_OPERATION);
1315         ctx.endSection();
1316
1317         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of type float, vec2, vec3, or vec4.");
1318         ctx.glUseProgram(program.getProgram());
1319         ctx.glUniform1ui(vec4_v, 0);
1320         ctx.expectError(GL_INVALID_OPERATION);
1321         ctx.glUniform2ui(vec4_v, 0, 0);
1322         ctx.expectError(GL_INVALID_OPERATION);
1323         ctx.glUniform3ui(vec4_v, 0, 0, 0);
1324         ctx.expectError(GL_INVALID_OPERATION);
1325         ctx.glUniform4ui(vec4_v, 0, 0, 0, 0);
1326         ctx.expectError(GL_INVALID_OPERATION);
1327         ctx.endSection();
1328
1329         ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than ctx.glUniform1i and ctx.glUniform1iv.");
1330         ctx.glUseProgram(program.getProgram());
1331         ctx.glUniform1ui(sampler_f, 0);
1332         ctx.expectError(GL_INVALID_OPERATION);
1333         ctx.endSection();
1334
1335         ctx.glUseProgram(0);
1336 }
1337
1338 void uniformui_invalid_location (NegativeTestContext& ctx)
1339 {
1340         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1341
1342         ctx.glUseProgram(program.getProgram());
1343         ctx.expectError(GL_NO_ERROR);
1344
1345         ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.");
1346         ctx.glUseProgram(program.getProgram());
1347         ctx.glUniform1i(-2, 0);
1348         ctx.expectError(GL_INVALID_OPERATION);
1349         ctx.glUniform2i(-2, 0, 0);
1350         ctx.expectError(GL_INVALID_OPERATION);
1351         ctx.glUniform3i(-2, 0, 0, 0);
1352         ctx.expectError(GL_INVALID_OPERATION);
1353         ctx.glUniform4i(-2, 0, 0, 0, 0);
1354         ctx.expectError(GL_INVALID_OPERATION);
1355
1356         ctx.glUseProgram(program.getProgram());
1357         ctx.glUniform1i(-1, 0);
1358         ctx.expectError(GL_NO_ERROR);
1359         ctx.glUniform2i(-1, 0, 0);
1360         ctx.expectError(GL_NO_ERROR);
1361         ctx.glUniform3i(-1, 0, 0, 0);
1362         ctx.expectError(GL_NO_ERROR);
1363         ctx.glUniform4i(-1, 0, 0, 0, 0);
1364         ctx.expectError(GL_NO_ERROR);
1365         ctx.endSection();
1366
1367         ctx.glUseProgram(0);
1368 }
1369
1370 // ctx.glUniform{1234}uiv
1371
1372 void uniformuiv_invalid_program (NegativeTestContext& ctx)
1373 {
1374         std::vector<GLuint> data(4);
1375
1376         ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1377         ctx.glUseProgram(0);
1378         ctx.glUniform1uiv(-1, 1, &data[0]);
1379         ctx.expectError(GL_INVALID_OPERATION);
1380         ctx.glUniform2uiv(-1, 1, &data[0]);
1381         ctx.expectError(GL_INVALID_OPERATION);
1382         ctx.glUniform3uiv(-1, 1, &data[0]);
1383         ctx.expectError(GL_INVALID_OPERATION);
1384         ctx.glUniform4uiv(-1, 1, &data[0]);
1385         ctx.expectError(GL_INVALID_OPERATION);
1386         ctx.endSection();
1387 }
1388
1389 void uniformuiv_incompatible_type (NegativeTestContext& ctx)
1390 {
1391         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1392
1393         ctx.glUseProgram(program.getProgram());
1394         GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");     // vec4
1395         GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");    // ivec4
1396         GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");    // uvec4
1397         GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f");  // sampler2D
1398         ctx.expectError(GL_NO_ERROR);
1399
1400         if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1401         {
1402                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1403                 ctx.fail("Failed to retrieve uniform location");
1404         }
1405
1406         std::vector<GLuint> data(4);
1407
1408         ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the ctx.glUniform command.");
1409         ctx.glUseProgram(program.getProgram());
1410         ctx.glUniform1uiv(uvec4_f, 1, &data[0]);
1411         ctx.expectError(GL_INVALID_OPERATION);
1412         ctx.glUniform2uiv(uvec4_f, 1, &data[0]);
1413         ctx.expectError(GL_INVALID_OPERATION);
1414         ctx.glUniform3uiv(uvec4_f, 1, &data[0]);
1415         ctx.expectError(GL_INVALID_OPERATION);
1416         ctx.glUniform4uiv(uvec4_f, 1, &data[0]);
1417         ctx.expectError(GL_NO_ERROR);
1418         ctx.endSection();
1419
1420         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}uiv is used to load a uniform variable of type float, vec2, vec3, or vec4.");
1421         ctx.glUseProgram(program.getProgram());
1422         ctx.glUniform1uiv(vec4_v, 1, &data[0]);
1423         ctx.expectError(GL_INVALID_OPERATION);
1424         ctx.glUniform2uiv(vec4_v, 1, &data[0]);
1425         ctx.expectError(GL_INVALID_OPERATION);
1426         ctx.glUniform3uiv(vec4_v, 1, &data[0]);
1427         ctx.expectError(GL_INVALID_OPERATION);
1428         ctx.glUniform4uiv(vec4_v, 1, &data[0]);
1429         ctx.expectError(GL_INVALID_OPERATION);
1430         ctx.endSection();
1431
1432         ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}uiv is used to load a uniform variable of type int, ivec2, ivec3 or ivec4.");
1433         ctx.glUseProgram(program.getProgram());
1434         ctx.glUniform1uiv(ivec4_f, 1, &data[0]);
1435         ctx.expectError(GL_INVALID_OPERATION);
1436         ctx.glUniform2uiv(ivec4_f, 1, &data[0]);
1437         ctx.expectError(GL_INVALID_OPERATION);
1438         ctx.glUniform3uiv(ivec4_f, 1, &data[0]);
1439         ctx.expectError(GL_INVALID_OPERATION);
1440         ctx.glUniform4uiv(ivec4_f, 1, &data[0]);
1441         ctx.expectError(GL_INVALID_OPERATION);
1442         ctx.endSection();
1443
1444         ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than ctx.glUniform1i and ctx.glUniform1iv.");
1445         ctx.glUseProgram(program.getProgram());
1446         ctx.glUniform1uiv(sampler_f, 1, &data[0]);
1447         ctx.expectError(GL_INVALID_OPERATION);
1448         ctx.endSection();
1449
1450         ctx.glUseProgram(0);
1451 }
1452
1453 void uniformuiv_invalid_location (NegativeTestContext& ctx)
1454 {
1455         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1456
1457         ctx.glUseProgram(program.getProgram());
1458         ctx.expectError(GL_NO_ERROR);
1459
1460         std::vector<GLuint> data(4);
1461
1462         ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.");
1463         ctx.glUseProgram(program.getProgram());
1464         ctx.glUniform1uiv(-2, 1, &data[0]);
1465         ctx.expectError(GL_INVALID_OPERATION);
1466         ctx.glUniform2uiv(-2, 1, &data[0]);
1467         ctx.expectError(GL_INVALID_OPERATION);
1468         ctx.glUniform3uiv(-2, 1, &data[0]);
1469         ctx.expectError(GL_INVALID_OPERATION);
1470         ctx.glUniform4uiv(-2, 1, &data[0]);
1471         ctx.expectError(GL_INVALID_OPERATION);
1472
1473         ctx.glUseProgram(program.getProgram());
1474         ctx.glUniform1uiv(-1, 1, &data[0]);
1475         ctx.expectError(GL_NO_ERROR);
1476         ctx.glUniform2uiv(-1, 1, &data[0]);
1477         ctx.expectError(GL_NO_ERROR);
1478         ctx.glUniform3uiv(-1, 1, &data[0]);
1479         ctx.expectError(GL_NO_ERROR);
1480         ctx.glUniform4uiv(-1, 1, &data[0]);
1481         ctx.expectError(GL_NO_ERROR);
1482         ctx.endSection();
1483
1484         ctx.glUseProgram(0);
1485 }
1486
1487 void uniformuiv_invalid_count (NegativeTestContext& ctx)
1488 {
1489         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1490
1491         ctx.glUseProgram                        (program.getProgram());
1492         int uvec4_f                             = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f"); // uvec4
1493         ctx.expectError(GL_NO_ERROR);
1494
1495         if (uvec4_f == -1)
1496         {
1497                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1498                 ctx.fail("Failed to retrieve uniform location");
1499         }
1500
1501         std::vector<GLuint> data(8);
1502
1503         ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable is not an array variable.");
1504         ctx.glUseProgram(program.getProgram());
1505         ctx.glUniform1uiv(uvec4_f, 2, &data[0]);
1506         ctx.expectError(GL_INVALID_OPERATION);
1507         ctx.glUniform2uiv(uvec4_f, 2, &data[0]);
1508         ctx.expectError(GL_INVALID_OPERATION);
1509         ctx.glUniform3uiv(uvec4_f, 2, &data[0]);
1510         ctx.expectError(GL_INVALID_OPERATION);
1511         ctx.glUniform4uiv(uvec4_f, 2, &data[0]);
1512         ctx.expectError(GL_INVALID_OPERATION);
1513         ctx.endSection();
1514
1515         ctx.glUseProgram(0);
1516 }
1517
1518
1519 // ctx.glUniformMatrix*fv
1520
1521 void uniform_matrixfv_invalid_program (NegativeTestContext& ctx)
1522 {
1523         std::vector<GLfloat> data(16);
1524
1525         ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1526         ctx.glUseProgram(0);
1527         ctx.glUniformMatrix2fv(-1, 1, GL_FALSE, &data[0]);
1528         ctx.expectError(GL_INVALID_OPERATION);
1529         ctx.glUniformMatrix3fv(-1, 1, GL_FALSE, &data[0]);
1530         ctx.expectError(GL_INVALID_OPERATION);
1531         ctx.glUniformMatrix4fv(-1, 1, GL_FALSE, &data[0]);
1532         ctx.expectError(GL_INVALID_OPERATION);
1533
1534         ctx.glUniformMatrix2x3fv(-1, 1, GL_FALSE, &data[0]);
1535         ctx.expectError(GL_INVALID_OPERATION);
1536         ctx.glUniformMatrix3x2fv(-1, 1, GL_FALSE, &data[0]);
1537         ctx.expectError(GL_INVALID_OPERATION);
1538         ctx.glUniformMatrix2x4fv(-1, 1, GL_FALSE, &data[0]);
1539         ctx.expectError(GL_INVALID_OPERATION);
1540         ctx.glUniformMatrix4x2fv(-1, 1, GL_FALSE, &data[0]);
1541         ctx.expectError(GL_INVALID_OPERATION);
1542         ctx.glUniformMatrix3x4fv(-1, 1, GL_FALSE, &data[0]);
1543         ctx.expectError(GL_INVALID_OPERATION);
1544         ctx.glUniformMatrix4x3fv(-1, 1, GL_FALSE, &data[0]);
1545         ctx.expectError(GL_INVALID_OPERATION);
1546         ctx.endSection();
1547 }
1548
1549 void uniform_matrixfv_incompatible_type (NegativeTestContext& ctx)
1550 {
1551         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1552
1553         ctx.glUseProgram                        (program.getProgram());
1554         GLint mat4_v                    = ctx.glGetUniformLocation(program.getProgram(), "mat4_v");     // mat4
1555         GLint sampler_f                 = ctx.glGetUniformLocation(program.getProgram(), "sampler_f");  // sampler2D
1556         ctx.expectError(GL_NO_ERROR);
1557
1558         if (mat4_v == -1 || sampler_f == -1)
1559         {
1560                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1561                 ctx.fail("Failed to retrieve uniform location");
1562         }
1563
1564         std::vector<GLfloat> data(16);
1565
1566         ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader does not match the size indicated by the ctx.glUniform command.");
1567         ctx.glUseProgram(program.getProgram());
1568         ctx.glUniformMatrix2fv(mat4_v, 1, GL_FALSE, &data[0]);
1569         ctx.expectError(GL_INVALID_OPERATION);
1570         ctx.glUniformMatrix3fv(mat4_v, 1, GL_FALSE, &data[0]);
1571         ctx.expectError(GL_INVALID_OPERATION);
1572         ctx.glUniformMatrix4fv(mat4_v, 1, GL_FALSE, &data[0]);
1573         ctx.expectError(GL_NO_ERROR);
1574
1575         ctx.glUniformMatrix2x3fv(mat4_v, 1, GL_FALSE, &data[0]);
1576         ctx.expectError(GL_INVALID_OPERATION);
1577         ctx.glUniformMatrix3x2fv(mat4_v, 1, GL_FALSE, &data[0]);
1578         ctx.expectError(GL_INVALID_OPERATION);
1579         ctx.glUniformMatrix2x4fv(mat4_v, 1, GL_FALSE, &data[0]);
1580         ctx.expectError(GL_INVALID_OPERATION);
1581         ctx.glUniformMatrix4x2fv(mat4_v, 1, GL_FALSE, &data[0]);
1582         ctx.expectError(GL_INVALID_OPERATION);
1583         ctx.glUniformMatrix3x4fv(mat4_v, 1, GL_FALSE, &data[0]);
1584         ctx.expectError(GL_INVALID_OPERATION);
1585         ctx.glUniformMatrix4x3fv(mat4_v, 1, GL_FALSE, &data[0]);
1586         ctx.expectError(GL_INVALID_OPERATION);
1587         ctx.endSection();
1588
1589         ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than ctx.glUniform1i and ctx.glUniform1iv.");
1590         ctx.glUseProgram(program.getProgram());
1591         ctx.glUniformMatrix2fv(sampler_f, 1, GL_FALSE, &data[0]);
1592         ctx.expectError(GL_INVALID_OPERATION);
1593         ctx.glUniformMatrix3fv(sampler_f, 1, GL_FALSE, &data[0]);
1594         ctx.expectError(GL_INVALID_OPERATION);
1595         ctx.glUniformMatrix4fv(sampler_f, 1, GL_FALSE, &data[0]);
1596         ctx.expectError(GL_INVALID_OPERATION);
1597
1598         ctx.glUniformMatrix2x3fv(sampler_f, 1, GL_FALSE, &data[0]);
1599         ctx.expectError(GL_INVALID_OPERATION);
1600         ctx.glUniformMatrix3x2fv(sampler_f, 1, GL_FALSE, &data[0]);
1601         ctx.expectError(GL_INVALID_OPERATION);
1602         ctx.glUniformMatrix2x4fv(sampler_f, 1, GL_FALSE, &data[0]);
1603         ctx.expectError(GL_INVALID_OPERATION);
1604         ctx.glUniformMatrix4x2fv(sampler_f, 1, GL_FALSE, &data[0]);
1605         ctx.expectError(GL_INVALID_OPERATION);
1606         ctx.glUniformMatrix3x4fv(sampler_f, 1, GL_FALSE, &data[0]);
1607         ctx.expectError(GL_INVALID_OPERATION);
1608         ctx.glUniformMatrix4x3fv(sampler_f, 1, GL_FALSE, &data[0]);
1609         ctx.expectError(GL_INVALID_OPERATION);
1610         ctx.endSection();
1611
1612         ctx.glUseProgram(0);
1613 }
1614
1615 void uniform_matrixfv_invalid_location (NegativeTestContext& ctx)
1616 {
1617         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1618
1619         ctx.glUseProgram(program.getProgram());
1620         ctx.expectError(GL_NO_ERROR);
1621
1622         std::vector<GLfloat> data(16);
1623
1624         ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current program object and location is not equal to -1.");
1625         ctx.glUseProgram(program.getProgram());
1626         ctx.glUniformMatrix2fv(-2, 1, GL_FALSE, &data[0]);
1627         ctx.expectError(GL_INVALID_OPERATION);
1628         ctx.glUniformMatrix3fv(-2, 1, GL_FALSE, &data[0]);
1629         ctx.expectError(GL_INVALID_OPERATION);
1630         ctx.glUniformMatrix4fv(-2, 1, GL_FALSE, &data[0]);
1631         ctx.expectError(GL_INVALID_OPERATION);
1632
1633         ctx.glUniformMatrix2x3fv(-2, 1, GL_FALSE, &data[0]);
1634         ctx.expectError(GL_INVALID_OPERATION);
1635         ctx.glUniformMatrix3x2fv(-2, 1, GL_FALSE, &data[0]);
1636         ctx.expectError(GL_INVALID_OPERATION);
1637         ctx.glUniformMatrix2x4fv(-2, 1, GL_FALSE, &data[0]);
1638         ctx.expectError(GL_INVALID_OPERATION);
1639         ctx.glUniformMatrix4x2fv(-2, 1, GL_FALSE, &data[0]);
1640         ctx.expectError(GL_INVALID_OPERATION);
1641         ctx.glUniformMatrix3x4fv(-2, 1, GL_FALSE, &data[0]);
1642         ctx.expectError(GL_INVALID_OPERATION);
1643         ctx.glUniformMatrix4x3fv(-2, 1, GL_FALSE, &data[0]);
1644         ctx.expectError(GL_INVALID_OPERATION);
1645
1646         ctx.glUseProgram(program.getProgram());
1647         ctx.glUniformMatrix2fv(-1, 1, GL_FALSE, &data[0]);
1648         ctx.expectError(GL_NO_ERROR);
1649         ctx.glUniformMatrix3fv(-1, 1, GL_FALSE, &data[0]);
1650         ctx.expectError(GL_NO_ERROR);
1651         ctx.glUniformMatrix4fv(-1, 1, GL_FALSE, &data[0]);
1652         ctx.expectError(GL_NO_ERROR);
1653
1654         ctx.glUniformMatrix2x3fv(-1, 1, GL_FALSE, &data[0]);
1655         ctx.expectError(GL_NO_ERROR);
1656         ctx.glUniformMatrix3x2fv(-1, 1, GL_FALSE, &data[0]);
1657         ctx.expectError(GL_NO_ERROR);
1658         ctx.glUniformMatrix2x4fv(-1, 1, GL_FALSE, &data[0]);
1659         ctx.expectError(GL_NO_ERROR);
1660         ctx.glUniformMatrix4x2fv(-1, 1, GL_FALSE, &data[0]);
1661         ctx.expectError(GL_NO_ERROR);
1662         ctx.glUniformMatrix3x4fv(-1, 1, GL_FALSE, &data[0]);
1663         ctx.expectError(GL_NO_ERROR);
1664         ctx.glUniformMatrix4x3fv(-1, 1, GL_FALSE, &data[0]);
1665         ctx.expectError(GL_NO_ERROR);
1666         ctx.endSection();
1667
1668         ctx.glUseProgram(0);
1669 }
1670
1671 void uniform_matrixfv_invalid_count (NegativeTestContext& ctx)
1672 {
1673         glu::ShaderProgram program(ctx.getRenderContext(), glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1674
1675         ctx.glUseProgram                        (program.getProgram());
1676         GLint mat4_v                    = ctx.glGetUniformLocation(program.getProgram(), "mat4_v"); // mat4
1677         ctx.expectError(GL_NO_ERROR);
1678
1679         if (mat4_v == -1)
1680         {
1681                 ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1682                 ctx.fail("Failed to retrieve uniform location");
1683         }
1684
1685         std::vector<GLfloat> data(32);
1686
1687         ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable is not an array variable.");
1688         ctx.glUseProgram(program.getProgram());
1689         ctx.glUniformMatrix2fv(mat4_v, 2, GL_FALSE, &data[0]);
1690         ctx.expectError(GL_INVALID_OPERATION);
1691         ctx.glUniformMatrix3fv(mat4_v, 2, GL_FALSE, &data[0]);
1692         ctx.expectError(GL_INVALID_OPERATION);
1693         ctx.glUniformMatrix4fv(mat4_v, 2, GL_FALSE, &data[0]);
1694         ctx.expectError(GL_INVALID_OPERATION);
1695
1696         ctx.glUniformMatrix2x3fv(mat4_v, 1, GL_FALSE, &data[0]);
1697         ctx.expectError(GL_INVALID_OPERATION);
1698         ctx.glUniformMatrix3x2fv(mat4_v, 1, GL_FALSE, &data[0]);
1699         ctx.expectError(GL_INVALID_OPERATION);
1700         ctx.glUniformMatrix2x4fv(mat4_v, 1, GL_FALSE, &data[0]);
1701         ctx.expectError(GL_INVALID_OPERATION);
1702         ctx.glUniformMatrix4x2fv(mat4_v, 1, GL_FALSE, &data[0]);
1703         ctx.expectError(GL_INVALID_OPERATION);
1704         ctx.glUniformMatrix3x4fv(mat4_v, 1, GL_FALSE, &data[0]);
1705         ctx.expectError(GL_INVALID_OPERATION);
1706         ctx.glUniformMatrix4x3fv(mat4_v, 1, GL_FALSE, &data[0]);
1707         ctx.expectError(GL_INVALID_OPERATION);
1708         ctx.endSection();
1709
1710         ctx.glUseProgram(0);
1711 }
1712
1713 // Transform feedback
1714 void gen_transform_feedbacks (NegativeTestContext& ctx)
1715 {
1716         ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
1717         GLuint id = 0;
1718         ctx.glGenTransformFeedbacks(-1, &id);
1719         ctx.expectError(GL_INVALID_VALUE);
1720         ctx.endSection();
1721 }
1722
1723 void bind_transform_feedback (NegativeTestContext& ctx)
1724 {
1725         GLuint                                          tfID[2];
1726         glu::ShaderProgram                      program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1727         deUint32                                        buf = 0x1234;
1728         const char* tfVarying           = "gl_Position";
1729
1730         ctx.glGenBuffers                                (1, &buf);
1731         ctx.glGenTransformFeedbacks             (2, tfID);
1732
1733         ctx.beginSection("GL_INVALID_ENUM is generated if target is not GL_TRANSFORM_FEEDBACK.");
1734         ctx.glBindTransformFeedback(-1, tfID[0]);
1735         ctx.expectError(GL_INVALID_ENUM);
1736         ctx.endSection();
1737
1738         ctx.beginSection("GL_INVALID_OPERATION is generated if the transform feedback operation is active on the currently bound transform feedback object, and is not paused.");
1739         ctx.glUseProgram                                (program.getProgram());
1740         ctx.glTransformFeedbackVaryings (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1741         ctx.glLinkProgram                               (program.getProgram());
1742         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID[0]);
1743         ctx.glBindBuffer                                (GL_TRANSFORM_FEEDBACK_BUFFER, buf);
1744         ctx.glBufferData                                (GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
1745         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1746         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1747         ctx.expectError                         (GL_NO_ERROR);
1748
1749         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID[1]);
1750         ctx.expectError                         (GL_INVALID_OPERATION);
1751
1752         ctx.glEndTransformFeedback              ();
1753         ctx.expectError                         (GL_NO_ERROR);
1754         ctx.endSection();
1755
1756         ctx.glUseProgram                                (0);
1757         ctx.glDeleteBuffers                             (1, &buf);
1758         ctx.glDeleteTransformFeedbacks  (2, tfID);
1759         ctx.expectError                         (GL_NO_ERROR);
1760 }
1761
1762 void delete_transform_feedbacks (NegativeTestContext& ctx)
1763 {
1764         GLuint id = 0;
1765         ctx.glGenTransformFeedbacks(1, &id);
1766
1767         ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
1768         ctx.glDeleteTransformFeedbacks(-1, &id);
1769         ctx.expectError(GL_INVALID_VALUE);
1770         ctx.endSection();
1771
1772         ctx.glDeleteTransformFeedbacks(1, &id);
1773 }
1774
1775 void begin_transform_feedback (NegativeTestContext& ctx)
1776 {
1777         GLuint                                          tfID[2];
1778         glu::ShaderProgram                      program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1779         deUint32                                        buf = 0x1234;
1780         const char* tfVarying           = "gl_Position";
1781
1782         ctx.glGenBuffers                                (1, &buf);
1783         ctx.glGenTransformFeedbacks             (2, tfID);
1784
1785         ctx.glUseProgram                                (program.getProgram());
1786         ctx.glTransformFeedbackVaryings (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1787         ctx.glLinkProgram                               (program.getProgram());
1788         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID[0]);
1789         ctx.glBindBuffer                                (GL_TRANSFORM_FEEDBACK_BUFFER, buf);
1790         ctx.glBufferData                                (GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
1791         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1792         ctx.expectError                                 (GL_NO_ERROR);
1793
1794         ctx.beginSection("GL_INVALID_ENUM is generated if primitiveMode is not one of GL_POINTS, GL_LINES, or GL_TRIANGLES.");
1795         ctx.glBeginTransformFeedback    (-1);
1796         ctx.expectError                                 (GL_INVALID_ENUM);
1797         ctx.endSection();
1798
1799         ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is already active.");
1800         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1801         ctx.expectError                                 (GL_NO_ERROR);
1802         ctx.glBeginTransformFeedback    (GL_POINTS);
1803         ctx.expectError                                 (GL_INVALID_OPERATION);
1804         ctx.endSection();
1805
1806         ctx.beginSection("GL_INVALID_OPERATION is generated if any binding point used in transform feedback mode does not have a buffer object bound.");
1807         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
1808         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1809         ctx.expectError                                 (GL_INVALID_OPERATION);
1810         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1811         ctx.endSection();
1812
1813         ctx.beginSection("GL_INVALID_OPERATION is generated if no binding points would be used because no program object is active.");
1814         ctx.glUseProgram                                (0);
1815         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1816         ctx.expectError                                 (GL_INVALID_OPERATION);
1817         ctx.glUseProgram                                (program.getProgram());
1818         ctx.endSection();
1819
1820         ctx.beginSection("GL_INVALID_OPERATION is generated if no binding points would be used because the active program object has specified no varying variables to record.");
1821         ctx.glTransformFeedbackVaryings (program.getProgram(), 0, 0, GL_INTERLEAVED_ATTRIBS);
1822         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1823         ctx.expectError                                 (GL_INVALID_OPERATION);
1824         ctx.endSection();
1825
1826         ctx.glEndTransformFeedback              ();
1827         ctx.glDeleteBuffers                             (1, &buf);
1828         ctx.glDeleteTransformFeedbacks  (2, tfID);
1829         ctx.expectError                                 (GL_NO_ERROR);
1830 }
1831
1832 void pause_transform_feedback (NegativeTestContext& ctx)
1833 {
1834         GLuint                                          tfID[2];
1835         glu::ShaderProgram                      program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1836         deUint32                                        buf = 0x1234;
1837         const char* tfVarying           = "gl_Position";
1838
1839         ctx.glGenBuffers                                (1, &buf);
1840         ctx.glGenTransformFeedbacks             (2, tfID);
1841
1842         ctx.glUseProgram                                (program.getProgram());
1843         ctx.glTransformFeedbackVaryings (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1844         ctx.glLinkProgram                               (program.getProgram());
1845         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID[0]);
1846         ctx.glBindBuffer                                (GL_TRANSFORM_FEEDBACK_BUFFER, buf);
1847         ctx.glBufferData                                (GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
1848         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1849         ctx.expectError                                 (GL_NO_ERROR);
1850
1851         ctx.beginSection("GL_INVALID_OPERATION is generated if the currently bound transform feedback object is not active or is paused.");
1852         ctx.glPauseTransformFeedback    ();
1853         ctx.expectError                                 (GL_INVALID_OPERATION);
1854         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1855         ctx.glPauseTransformFeedback    ();
1856         ctx.expectError                                 (GL_NO_ERROR);
1857         ctx.glPauseTransformFeedback    ();
1858         ctx.expectError                                 (GL_INVALID_OPERATION);
1859         ctx.endSection();
1860
1861         ctx.glEndTransformFeedback              ();
1862         ctx.glDeleteBuffers                             (1, &buf);
1863         ctx.glDeleteTransformFeedbacks  (2, tfID);
1864         ctx.expectError                                 (GL_NO_ERROR);
1865 }
1866
1867 void resume_transform_feedback (NegativeTestContext& ctx)
1868 {
1869         GLuint                                          tfID[2];
1870         glu::ShaderProgram                      program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1871         deUint32                                        buf = 0x1234;
1872         const char* tfVarying           = "gl_Position";
1873
1874         ctx.glGenBuffers                                (1, &buf);
1875         ctx.glGenTransformFeedbacks             (2, tfID);
1876
1877         ctx.glUseProgram                                (program.getProgram());
1878         ctx.glTransformFeedbackVaryings (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1879         ctx.glLinkProgram                               (program.getProgram());
1880         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID[0]);
1881         ctx.glBindBuffer                                (GL_TRANSFORM_FEEDBACK_BUFFER, buf);
1882         ctx.glBufferData                                (GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
1883         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1884         ctx.expectError                                 (GL_NO_ERROR);
1885
1886         ctx.beginSection("GL_INVALID_OPERATION is generated if the currently bound transform feedback object is not active or is not paused.");
1887         ctx.glResumeTransformFeedback   ();
1888         ctx.expectError                                 (GL_INVALID_OPERATION);
1889         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1890         ctx.glResumeTransformFeedback   ();
1891         ctx.expectError                                 (GL_INVALID_OPERATION);
1892         ctx.glPauseTransformFeedback    ();
1893         ctx.glResumeTransformFeedback   ();
1894         ctx.expectError                                 (GL_NO_ERROR);
1895         ctx.endSection();
1896
1897         ctx.glEndTransformFeedback              ();
1898         ctx.glDeleteBuffers                             (1, &buf);
1899         ctx.glDeleteTransformFeedbacks  (2, tfID);
1900         ctx.expectError                                 (GL_NO_ERROR);
1901 }
1902
1903 void end_transform_feedback (NegativeTestContext& ctx)
1904 {
1905         GLuint                                          tfID = 0;
1906         glu::ShaderProgram                      program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1907         deUint32                                        buf = 0x1234;
1908         const char* tfVarying           = "gl_Position";
1909
1910         ctx.glGenBuffers                                (1, &buf);
1911         ctx.glGenTransformFeedbacks             (1, &tfID);
1912
1913         ctx.glUseProgram                                (program.getProgram());
1914         ctx.glTransformFeedbackVaryings (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1915         ctx.glLinkProgram                               (program.getProgram());
1916         ctx.glBindTransformFeedback             (GL_TRANSFORM_FEEDBACK, tfID);
1917         ctx.glBindBuffer                                (GL_TRANSFORM_FEEDBACK_BUFFER, buf);
1918         ctx.glBufferData                                (GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
1919         ctx.glBindBufferBase                    (GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
1920         ctx.expectError                                 (GL_NO_ERROR);
1921
1922         ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is not active.");
1923         ctx.glEndTransformFeedback              ();
1924         ctx.expectError                                 (GL_INVALID_OPERATION);
1925         ctx.glBeginTransformFeedback    (GL_TRIANGLES);
1926         ctx.glEndTransformFeedback              ();
1927         ctx.expectError                                 (GL_NO_ERROR);
1928         ctx.endSection();
1929
1930         ctx.glDeleteBuffers                             (1, &buf);
1931         ctx.glDeleteTransformFeedbacks  (1, &tfID);
1932         ctx.expectError                                 (GL_NO_ERROR);
1933 }
1934
1935 void get_transform_feedback_varying (NegativeTestContext& ctx)
1936 {
1937         GLuint                                  tfID = 0;
1938         glu::ShaderProgram              program                 (ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1939         glu::ShaderProgram              programInvalid  (ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, ""));
1940         const char* tfVarying   = "gl_Position";
1941         int                                             maxTransformFeedbackVaryings = 0;
1942
1943         GLsizei                                 length;
1944         GLsizei                                 size;
1945         GLenum                                  type;
1946         char                                    name[32];
1947
1948         ctx.glGenTransformFeedbacks                             (1, &tfID);
1949
1950         ctx.glTransformFeedbackVaryings                 (program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1951         ctx.expectError                                         (GL_NO_ERROR);
1952         ctx.glLinkProgram                                               (program.getProgram());
1953         ctx.expectError                                         (GL_NO_ERROR);
1954
1955         ctx.glBindTransformFeedback                             (GL_TRANSFORM_FEEDBACK, tfID);
1956         ctx.expectError                                         (GL_NO_ERROR);
1957
1958         ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of a program object.");
1959         ctx.glGetTransformFeedbackVarying               (-1, 0, 32, &length, &size, &type, &name[0]);
1960         ctx.expectError                                         (GL_INVALID_VALUE);
1961         ctx.endSection();
1962
1963         ctx.beginSection("GL_INVALID_VALUE is generated if index is greater or equal to the value of GL_TRANSFORM_FEEDBACK_VARYINGS.");
1964         ctx.glGetProgramiv                                              (program.getProgram(), GL_TRANSFORM_FEEDBACK_VARYINGS, &maxTransformFeedbackVaryings);
1965         ctx.glGetTransformFeedbackVarying               (program.getProgram(), maxTransformFeedbackVaryings, 32, &length, &size, &type, &name[0]);
1966         ctx.expectError                                         (GL_INVALID_VALUE);
1967         ctx.endSection();
1968
1969         ctx.beginSection("GL_INVALID_OPERATION or GL_INVALID_VALUE is generated program has not been linked.");
1970         ctx.glGetTransformFeedbackVarying               (programInvalid.getProgram(), 0, 32, &length, &size, &type, &name[0]);
1971         ctx.expectError                                         (GL_INVALID_OPERATION, GL_INVALID_VALUE);
1972         ctx.endSection();
1973
1974         ctx.glDeleteTransformFeedbacks                  (1, &tfID);
1975         ctx.expectError                                         (GL_NO_ERROR);
1976 }
1977
1978 void transform_feedback_varyings (NegativeTestContext& ctx)
1979 {
1980         GLuint                                  tfID = 0;
1981         glu::ShaderProgram              program(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
1982         const char* tfVarying   = "gl_Position";
1983         GLint                                   maxTransformFeedbackSeparateAttribs = 0;
1984
1985         ctx.glGenTransformFeedbacks                             (1, &tfID);
1986         ctx.expectError                                         (GL_NO_ERROR);
1987
1988         ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of a program object.");
1989         ctx.glTransformFeedbackVaryings                 (0, 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
1990         ctx.expectError                                         (GL_INVALID_VALUE);
1991         ctx.endSection();
1992
1993         ctx.beginSection("GL_INVALID_VALUE is generated if bufferMode is GL_SEPARATE_ATTRIBS and count is greater than GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS.");
1994         ctx.glGetIntegerv                                               (GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &maxTransformFeedbackSeparateAttribs);
1995         ctx.glTransformFeedbackVaryings                 (program.getProgram(), maxTransformFeedbackSeparateAttribs+1, &tfVarying, GL_SEPARATE_ATTRIBS);
1996         ctx.expectError                                         (GL_INVALID_VALUE);
1997         ctx.endSection();
1998
1999         ctx.glDeleteTransformFeedbacks                  (1, &tfID);
2000         ctx.expectError                                         (GL_NO_ERROR);
2001 }
2002
2003 std::vector<FunctionContainer> getNegativeShaderApiTestFunctions ()
2004 {
2005         FunctionContainer funcs[] =
2006         {
2007                 {create_shader,                                                 "create_shader",                                                "Invalid glCreateShader() usage"                           },
2008                 {shader_source,                                                 "shader_source",                                                "Invalid glShaderSource() usage"                           },
2009                 {compile_shader,                                                "compile_shader",                                               "Invalid glCompileShader() usage"                          },
2010                 {delete_shader,                                                 "delete_shader",                                                "Invalid glDeleteShader() usage"                           },
2011                 {shader_binary,                                                 "shader_binary",                                                "Invalid glShaderBinary() usage"                           },
2012                 {attach_shader,                                                 "attach_shader",                                                "Invalid glAttachShader() usage"                           },
2013                 {detach_shader,                                                 "detach_shader",                                                "Invalid glDetachShader() usage"                           },
2014                 {link_program,                                                  "link_program",                                                 "Invalid glLinkProgram() usage"                            },
2015                 {use_program,                                                   "use_program",                                                  "Invalid glUseProgram() usage"                             },
2016                 {delete_program,                                                "delete_program",                                               "Invalid glDeleteProgram() usage"                          },
2017                 {validate_program,                                              "validate_program",                                             "Invalid glValidateProgram() usage"                        },
2018                 {get_program_binary,                                    "get_program_binary",                                   "Invalid glGetProgramBinary() usage"               },
2019                 {program_binary,                                                "program_binary",                                               "Invalid glProgramBinary() usage"                          },
2020                 {program_parameteri,                                    "program_parameteri",                                   "Invalid glProgramParameteri() usage"              },
2021                 {gen_samplers,                                                  "gen_samplers",                                                 "Invalid glGenSamplers() usage"                            },
2022                 {bind_sampler,                                                  "bind_sampler",                                                 "Invalid glBindSampler() usage"                            },
2023                 {delete_samplers,                                               "delete_samplers",                                              "Invalid glDeleteSamplers() usage"                         },
2024                 {get_sampler_parameteriv,                               "get_sampler_parameteriv",                              "Invalid glGetSamplerParameteriv() usage"          },
2025                 {get_sampler_parameterfv,                               "get_sampler_parameterfv",                              "Invalid glGetSamplerParameterfv() usage"          },
2026                 {sampler_parameteri,                                    "sampler_parameteri",                                   "Invalid glSamplerParameteri() usage"              },
2027                 {sampler_parameteriv,                                   "sampler_parameteriv",                                  "Invalid glSamplerParameteriv() usage"             },
2028                 {sampler_parameterf,                                    "sampler_parameterf",                                   "Invalid glSamplerParameterf() usage"              },
2029                 {sampler_parameterfv,                                   "sampler_parameterfv",                                  "Invalid glSamplerParameterfv() usage"             },
2030                 {get_attrib_location,                                   "get_attrib_location",                                  "Invalid glGetAttribLocation() usage"              },
2031                 {get_uniform_location,                                  "get_uniform_location",                                 "Invalid glGetUniformLocation() usage"             },
2032                 {bind_attrib_location,                                  "bind_attrib_location",                                 "Invalid glBindAttribLocation() usage"             },
2033                 {uniform_block_binding,                                 "uniform_block_binding",                                "Invalid glUniformBlockBinding() usage"            },
2034                 {uniformf_invalid_program,                              "uniformf_invalid_program",                             "Invalid glUniform{1234}f() usage"                         },
2035                 {uniformf_incompatible_type,                    "uniformf_incompatible_type",                   "Invalid glUniform{1234}f() usage"                         },
2036                 {uniformf_invalid_location,                             "uniformf_invalid_location",                    "Invalid glUniform{1234}f() usage"                         },
2037                 {uniformfv_invalid_program,                             "uniformfv_invalid_program",                    "Invalid glUniform{1234}fv() usage"                        },
2038                 {uniformfv_incompatible_type,                   "uniformfv_incompatible_type",                  "Invalid glUniform{1234}fv() usage"                        },
2039                 {uniformfv_invalid_location,                    "uniformfv_invalid_location",                   "Invalid glUniform{1234}fv() usage"                        },
2040                 {uniformfv_invalid_count,                               "uniformfv_invalid_count",                              "Invalid glUniform{1234}fv() usage"                        },
2041                 {uniformi_invalid_program,                              "uniformi_invalid_program",                             "Invalid glUniform{1234}i() usage"                         },
2042                 {uniformi_incompatible_type,                    "uniformi_incompatible_type",                   "Invalid glUniform{1234}i() usage"                         },
2043                 {uniformi_invalid_location,                             "uniformi_invalid_location",                    "Invalid glUniform{1234}i() usage"                         },
2044                 {uniformiv_invalid_program,                             "uniformiv_invalid_program",                    "Invalid glUniform{1234}iv() usage"                        },
2045                 {uniformiv_incompatible_type,                   "uniformiv_incompatible_type",                  "Invalid glUniform{1234}iv() usage"                        },
2046                 {uniformiv_invalid_location,                    "uniformiv_invalid_location",                   "Invalid glUniform{1234}iv() usage"                        },
2047                 {uniformiv_invalid_count,                               "uniformiv_invalid_count",                              "Invalid glUniform{1234}iv() usage"                        },
2048                 {uniformui_invalid_program,                             "uniformui_invalid_program",                    "Invalid glUniform{234}ui() usage"                         },
2049                 {uniformui_incompatible_type,                   "uniformui_incompatible_type",                  "Invalid glUniform{1234}ui() usage"                        },
2050                 {uniformui_invalid_location,                    "uniformui_invalid_location",                   "Invalid glUniform{1234}ui() usage"                        },
2051                 {uniformuiv_invalid_program,                    "uniformuiv_invalid_program",                   "Invalid glUniform{234}uiv() usage"                        },
2052                 {uniformuiv_incompatible_type,                  "uniformuiv_incompatible_type",                 "Invalid glUniform{1234}uiv() usage"               },
2053                 {uniformuiv_invalid_location,                   "uniformuiv_invalid_location",                  "Invalid glUniform{1234}uiv() usage"               },
2054                 {uniformuiv_invalid_count,                              "uniformuiv_invalid_count",                             "Invalid glUniform{1234}uiv() usage"               },
2055                 {uniform_matrixfv_invalid_program,              "uniform_matrixfv_invalid_program",             "Invalid glUniformMatrix{234}fv() usage"           },
2056                 {uniform_matrixfv_incompatible_type,    "uniform_matrixfv_incompatible_type",   "Invalid glUniformMatrix{234}fv() usage"           },
2057                 {uniform_matrixfv_invalid_location,             "uniform_matrixfv_invalid_location",    "Invalid glUniformMatrix{234}fv() usage"           },
2058                 {uniform_matrixfv_invalid_count,                "uniform_matrixfv_invalid_count",               "Invalid glUniformMatrix{234}fv() usage"           },
2059                 {gen_transform_feedbacks,                               "gen_transform_feedbacks",                              "Invalid glGenTransformFeedbacks() usage"          },
2060                 {bind_transform_feedback,                               "bind_transform_feedback",                              "Invalid glBindTransformFeedback() usage"          },
2061                 {delete_transform_feedbacks,                    "delete_transform_feedbacks",                   "Invalid glDeleteTransformFeedbacks() usage"   },
2062                 {begin_transform_feedback,                              "begin_transform_feedback",                             "Invalid glBeginTransformFeedback() usage"         },
2063                 {pause_transform_feedback,                              "pause_transform_feedback",                             "Invalid glPauseTransformFeedback() usage"         },
2064                 {resume_transform_feedback,                             "resume_transform_feedback",                    "Invalid glResumeTransformFeedback() usage"        },
2065                 {end_transform_feedback,                                "end_transform_feedback",                               "Invalid glEndTransformFeedback() usage"           },
2066                 {get_transform_feedback_varying,                "get_transform_feedback_varying",               "Invalid glGetTransformFeedbackVarying() usage"},
2067                 {transform_feedback_varyings,                   "transform_feedback_varyings",                  "Invalid glTransformFeedbackVaryings() usage"  },
2068         };
2069
2070         return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
2071 }
2072
2073 } // NegativeTestShared
2074 } // Functional
2075 } // gles31
2076 } // deqp