xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fNegativeShaderApiTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
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 #include "gluContextInfo.hpp"
35 #include "gluRenderContext.hpp"
36 
37 namespace deqp
38 {
39 namespace gles31
40 {
41 namespace Functional
42 {
43 namespace NegativeTestShared
44 {
45 using glu::CallLogWrapper;
46 using tcu::TestLog;
47 using namespace glw;
48 
49 static const char *vertexShaderSource = "#version 300 es\n"
50                                         "void main (void)\n"
51                                         "{\n"
52                                         "    gl_Position = vec4(0.0);\n"
53                                         "}\n\0";
54 
55 static const char *fragmentShaderSource = "#version 300 es\n"
56                                           "layout(location = 0) out mediump vec4 fragColor;"
57                                           "void main (void)\n"
58                                           "{\n"
59                                           "    fragColor = vec4(0.0);\n"
60                                           "}\n\0";
61 
62 static const char *uniformTestVertSource = "#version 300 es\n"
63                                            "uniform mediump vec4 vec4_v;\n"
64                                            "uniform mediump mat4 mat4_v;\n"
65                                            "void main (void)\n"
66                                            "{\n"
67                                            "    gl_Position = mat4_v * vec4_v;\n"
68                                            "}\n\0";
69 
70 static const char *uniformTestFragSource = "#version 300 es\n"
71                                            "uniform mediump ivec4 ivec4_f;\n"
72                                            "uniform mediump uvec4 uvec4_f;\n"
73                                            "uniform sampler2D sampler_f;\n"
74                                            "layout(location = 0) out mediump vec4 fragColor;"
75                                            "void main (void)\n"
76                                            "{\n"
77                                            "    fragColor.xy = (vec4(uvec4_f) + vec4(ivec4_f)).xy;\n"
78                                            "    fragColor.zw = texture(sampler_f, vec2(0.0, 0.0)).zw;\n"
79                                            "}\n\0";
80 
81 static const char *uniformBlockVertSource = "#version 300 es\n"
82                                             "layout(shared) uniform Block { lowp float var; };\n"
83                                             "void main (void)\n"
84                                             "{\n"
85                                             "    gl_Position = vec4(var);\n"
86                                             "}\n\0";
87 
supportsES32orGL45(NegativeTestContext & ctx)88 static bool supportsES32orGL45(NegativeTestContext &ctx)
89 {
90     return contextSupports(ctx.getRenderContext().getType(), glu::ApiType::es(3, 2)) ||
91            contextSupports(ctx.getRenderContext().getType(), glu::ApiType::core(4, 5));
92 }
93 
94 // Shader control commands
create_shader(NegativeTestContext & ctx)95 void create_shader(NegativeTestContext &ctx)
96 {
97     ctx.beginSection("GL_INVALID_ENUM is generated if shaderType is not an accepted value.");
98     ctx.glCreateShader(-1);
99     ctx.expectError(GL_INVALID_ENUM);
100     ctx.endSection();
101 }
102 
shader_source(NegativeTestContext & ctx)103 void shader_source(NegativeTestContext &ctx)
104 {
105     // make notAShader not a shader id
106     const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
107     ctx.glDeleteShader(notAShader);
108 
109     ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
110     ctx.glShaderSource(notAShader, 0, 0, 0);
111     ctx.expectError(GL_INVALID_VALUE);
112     ctx.endSection();
113 
114     ctx.beginSection("GL_INVALID_VALUE is generated if count is less than 0.");
115     GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
116     ctx.glShaderSource(shader, -1, 0, 0);
117     ctx.expectError(GL_INVALID_VALUE);
118     ctx.endSection();
119 
120     ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
121     GLuint program = ctx.glCreateProgram();
122     ctx.glShaderSource(program, 0, 0, 0);
123     ctx.expectError(GL_INVALID_OPERATION);
124     ctx.endSection();
125 
126     ctx.glDeleteProgram(program);
127     ctx.glDeleteShader(shader);
128 }
129 
compile_shader(NegativeTestContext & ctx)130 void compile_shader(NegativeTestContext &ctx)
131 {
132     const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
133     ctx.glDeleteShader(notAShader);
134 
135     ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
136     ctx.glCompileShader(notAShader);
137     ctx.expectError(GL_INVALID_VALUE);
138     ctx.endSection();
139 
140     ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
141     GLuint program = ctx.glCreateProgram();
142     ctx.glCompileShader(program);
143     ctx.expectError(GL_INVALID_OPERATION);
144     ctx.endSection();
145 
146     ctx.glDeleteProgram(program);
147 }
148 
delete_shader(NegativeTestContext & ctx)149 void delete_shader(NegativeTestContext &ctx)
150 {
151     const GLuint notAShader = ctx.glCreateShader(GL_VERTEX_SHADER);
152     ctx.glDeleteShader(notAShader);
153 
154     ctx.beginSection("GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL.");
155     ctx.glDeleteShader(notAShader);
156     ctx.expectError(GL_INVALID_VALUE);
157     ctx.endSection();
158 }
159 
shader_binary(NegativeTestContext & ctx)160 void shader_binary(NegativeTestContext &ctx)
161 {
162     std::vector<int32_t> binaryFormats;
163     bool shaderBinarySupported = !binaryFormats.empty();
164     GLuint shaders[2];
165     GLuint shaderPair[2];
166     GLuint nonProgram[2];
167     GLuint shaderProgram[2];
168 
169     {
170         int32_t numFormats = 0x1234;
171         ctx.glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &numFormats);
172 
173         if (numFormats == 0)
174             ctx.getLog() << TestLog::Message << "// No supported extensions available." << TestLog::EndMessage;
175         else
176         {
177             binaryFormats.resize(numFormats);
178             ctx.glGetIntegerv(GL_SHADER_BINARY_FORMATS, &binaryFormats[0]);
179         }
180     }
181 
182     if (!shaderBinarySupported)
183         ctx.getLog() << TestLog::Message << "// Shader binaries not supported." << TestLog::EndMessage;
184     else
185         ctx.getLog() << TestLog::Message << "// Shader binaries supported" << TestLog::EndMessage;
186 
187     shaders[0]       = ctx.glCreateShader(GL_VERTEX_SHADER);
188     shaders[1]       = ctx.glCreateShader(GL_VERTEX_SHADER);
189     shaderPair[0]    = ctx.glCreateShader(GL_VERTEX_SHADER);
190     shaderPair[1]    = ctx.glCreateShader(GL_FRAGMENT_SHADER);
191     nonProgram[0]    = -1;
192     nonProgram[1]    = -1;
193     shaderProgram[0] = ctx.glCreateShader(GL_VERTEX_SHADER);
194     shaderProgram[1] = ctx.glCreateProgram();
195 
196     ctx.beginSection("GL_INVALID_ENUM is generated if binaryFormat is not an accepted value.");
197     ctx.glShaderBinary(1, &shaders[0], -1, 0, 0);
198     ctx.expectError(GL_INVALID_ENUM);
199     ctx.endSection();
200 
201     if (shaderBinarySupported)
202     {
203         ctx.beginSection("GL_INVALID_VALUE is generated if the data pointed to by binary does not match the format "
204                          "specified by binaryFormat.");
205         const GLbyte data = 0x005F;
206         ctx.glShaderBinary(1, &shaders[0], binaryFormats[0], &data, 1);
207         ctx.expectError(GL_INVALID_VALUE);
208         ctx.endSection();
209 
210         ctx.beginSection("GL_INVALID_OPERATION is generated if more than one of the handles in shaders refers to the "
211                          "same type of shader, or GL_INVALID_VALUE due to invalid data pointer.");
212         ctx.glShaderBinary(2, &shaders[0], binaryFormats[0], 0, 0);
213         ctx.expectError(GL_INVALID_OPERATION, GL_INVALID_VALUE);
214         ctx.endSection();
215 
216         ctx.beginSection("GL_INVALID_VALUE is generated if count or length is negative.");
217         ctx.glShaderBinary(2, &shaderPair[0], binaryFormats[0], 0, -1);
218         ctx.expectError(GL_INVALID_VALUE);
219         ctx.glShaderBinary(-1, &shaderPair[0], binaryFormats[0], 0, 0);
220         ctx.expectError(GL_INVALID_VALUE);
221         ctx.endSection();
222 
223         ctx.beginSection(
224             "GL_INVALID_VALUE is generated if shaders contains anything other than shader or program objects.");
225         ctx.glShaderBinary(2, &nonProgram[0], binaryFormats[0], 0, 0);
226         ctx.expectError(GL_INVALID_VALUE);
227         ctx.endSection();
228 
229         ctx.beginSection("GL_INVALID_OPERATION is generated if shaders refers to a program object.");
230         ctx.glShaderBinary(2, &shaderProgram[0], binaryFormats[0], 0, 0);
231         ctx.expectError(GL_INVALID_OPERATION);
232         ctx.endSection();
233     }
234 
235     ctx.glDeleteShader(shaders[0]);
236     ctx.glDeleteShader(shaders[1]);
237 }
238 
attach_shader(NegativeTestContext & ctx)239 void attach_shader(NegativeTestContext &ctx)
240 {
241     GLuint shader1 = ctx.glCreateShader(GL_VERTEX_SHADER);
242     GLuint shader2 = ctx.glCreateShader(GL_VERTEX_SHADER);
243     GLuint program = ctx.glCreateProgram();
244 
245     const GLuint notAShader  = ctx.glCreateShader(GL_VERTEX_SHADER);
246     const GLuint notAProgram = ctx.glCreateProgram();
247 
248     ctx.glDeleteShader(notAShader);
249     ctx.glDeleteProgram(notAProgram);
250 
251     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
252     ctx.glAttachShader(shader1, shader1);
253     ctx.expectError(GL_INVALID_OPERATION);
254     ctx.endSection();
255 
256     ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
257     ctx.glAttachShader(program, program);
258     ctx.expectError(GL_INVALID_OPERATION);
259     ctx.glAttachShader(shader1, program);
260     ctx.expectError(GL_INVALID_OPERATION);
261     ctx.endSection();
262 
263     ctx.beginSection("GL_INVALID_VALUE is generated if either program or shader is not a value generated by OpenGL.");
264     ctx.glAttachShader(program, notAShader);
265     ctx.expectError(GL_INVALID_VALUE);
266     ctx.glAttachShader(notAProgram, shader1);
267     ctx.expectError(GL_INVALID_VALUE);
268     ctx.glAttachShader(notAProgram, notAShader);
269     ctx.expectError(GL_INVALID_VALUE);
270     ctx.endSection();
271 
272     ctx.beginSection("GL_INVALID_OPERATION is generated if shader is already attached to program.");
273     ctx.glAttachShader(program, shader1);
274     ctx.expectError(GL_NO_ERROR);
275     ctx.glAttachShader(program, shader1);
276     ctx.expectError(GL_INVALID_OPERATION);
277     ctx.endSection();
278 
279     if (glu::isContextTypeES(ctx.getRenderContext().getType()))
280     {
281         ctx.beginSection(
282             "GL_INVALID_OPERATION is generated if a shader of the same type as shader is already attached to program.");
283         ctx.glAttachShader(program, shader2);
284         ctx.expectError(GL_INVALID_OPERATION);
285         ctx.endSection();
286     }
287 
288     ctx.glDeleteProgram(program);
289     ctx.glDeleteShader(shader1);
290     ctx.glDeleteShader(shader2);
291 }
292 
detach_shader(NegativeTestContext & ctx)293 void detach_shader(NegativeTestContext &ctx)
294 {
295     GLuint shader  = ctx.glCreateShader(GL_VERTEX_SHADER);
296     GLuint program = ctx.glCreateProgram();
297 
298     const GLuint notAShader  = ctx.glCreateShader(GL_VERTEX_SHADER);
299     const GLuint notAProgram = ctx.glCreateProgram();
300 
301     ctx.glDeleteShader(notAShader);
302     ctx.glDeleteProgram(notAProgram);
303 
304     ctx.beginSection("GL_INVALID_VALUE is generated if either program or shader is not a value generated by OpenGL.");
305     ctx.glDetachShader(notAProgram, shader);
306     ctx.expectError(GL_INVALID_VALUE);
307     ctx.glDetachShader(program, notAShader);
308     ctx.expectError(GL_INVALID_VALUE);
309     ctx.glDetachShader(notAProgram, notAShader);
310     ctx.expectError(GL_INVALID_VALUE);
311     ctx.endSection();
312 
313     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
314     ctx.glDetachShader(shader, shader);
315     ctx.expectError(GL_INVALID_OPERATION);
316     ctx.endSection();
317 
318     ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not a shader object.");
319     ctx.glDetachShader(program, program);
320     ctx.expectError(GL_INVALID_OPERATION);
321     ctx.glDetachShader(shader, program);
322     ctx.expectError(GL_INVALID_OPERATION);
323     ctx.endSection();
324 
325     ctx.beginSection("GL_INVALID_OPERATION is generated if shader is not attached to program.");
326     ctx.glDetachShader(program, shader);
327     ctx.expectError(GL_INVALID_OPERATION);
328     ctx.endSection();
329 
330     ctx.glDeleteProgram(program);
331     ctx.glDeleteShader(shader);
332 }
333 
link_program(NegativeTestContext & ctx)334 void link_program(NegativeTestContext &ctx)
335 {
336     GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
337 
338     const GLuint notAProgram = ctx.glCreateProgram();
339     ctx.glDeleteProgram(notAProgram);
340 
341     ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
342     ctx.glLinkProgram(notAProgram);
343     ctx.expectError(GL_INVALID_VALUE);
344     ctx.endSection();
345 
346     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
347     ctx.glLinkProgram(shader);
348     ctx.expectError(GL_INVALID_OPERATION);
349     ctx.endSection();
350 
351     ctx.glDeleteShader(shader);
352 
353     ctx.beginSection("GL_INVALID_OPERATION is generated if program is the currently active program object and "
354                      "transform feedback mode is active.");
355     glu::ShaderProgram program(ctx.getRenderContext(),
356                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
357     uint32_t buf          = 0x1234;
358     uint32_t tfID         = 0x1234;
359     const char *tfVarying = "gl_Position";
360 
361     ctx.glGenTransformFeedbacks(1, &tfID);
362     ctx.glGenBuffers(1, &buf);
363 
364     ctx.glUseProgram(program.getProgram());
365     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
366     ctx.glLinkProgram(program.getProgram());
367     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
368     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
369     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
370     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
371     ctx.glBeginTransformFeedback(GL_TRIANGLES);
372     ctx.expectError(GL_NO_ERROR);
373 
374     ctx.glLinkProgram(program.getProgram());
375     ctx.expectError(GL_INVALID_OPERATION);
376 
377     ctx.glEndTransformFeedback();
378     ctx.glDeleteTransformFeedbacks(1, &tfID);
379     ctx.glDeleteBuffers(1, &buf);
380     ctx.expectError(GL_NO_ERROR);
381     ctx.endSection();
382 }
383 
use_program(NegativeTestContext & ctx)384 void use_program(NegativeTestContext &ctx)
385 {
386     GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
387 
388     const GLuint notAProgram = ctx.glCreateProgram();
389     ctx.glDeleteProgram(notAProgram);
390 
391     ctx.beginSection("GL_INVALID_VALUE is generated if program is neither 0 nor a value generated by OpenGL.");
392     ctx.glUseProgram(notAProgram);
393     ctx.expectError(GL_INVALID_VALUE);
394     ctx.endSection();
395 
396     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
397     ctx.glUseProgram(shader);
398     ctx.expectError(GL_INVALID_OPERATION);
399     ctx.endSection();
400 
401     ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback mode is active and not paused.");
402     glu::ShaderProgram program1(ctx.getRenderContext(),
403                                 glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
404     glu::ShaderProgram program2(ctx.getRenderContext(),
405                                 glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
406     uint32_t buf          = 0x1234;
407     uint32_t tfID         = 0x1234;
408     const char *tfVarying = "gl_Position";
409 
410     ctx.glGenTransformFeedbacks(1, &tfID);
411     ctx.glGenBuffers(1, &buf);
412 
413     ctx.glUseProgram(program1.getProgram());
414     ctx.glTransformFeedbackVaryings(program1.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
415     ctx.glLinkProgram(program1.getProgram());
416     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
417     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
418     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
419     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
420     ctx.glBeginTransformFeedback(GL_TRIANGLES);
421     ctx.expectError(GL_NO_ERROR);
422 
423     ctx.glUseProgram(program2.getProgram());
424     ctx.expectError(GL_INVALID_OPERATION);
425 
426     ctx.glPauseTransformFeedback();
427     ctx.glUseProgram(program2.getProgram());
428     ctx.expectError(GL_NO_ERROR);
429 
430     ctx.glEndTransformFeedback();
431     ctx.glDeleteTransformFeedbacks(1, &tfID);
432     ctx.glDeleteBuffers(1, &buf);
433     ctx.expectError(GL_NO_ERROR);
434     ctx.endSection();
435 
436     ctx.glUseProgram(0);
437     ctx.glDeleteShader(shader);
438 }
439 
delete_program(NegativeTestContext & ctx)440 void delete_program(NegativeTestContext &ctx)
441 {
442     GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
443 
444     const GLuint notAProgram = ctx.glCreateProgram();
445     ctx.glDeleteProgram(notAProgram);
446 
447     ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
448     ctx.glDeleteProgram(notAProgram);
449     ctx.expectError(GL_INVALID_VALUE);
450     ctx.endSection();
451 
452     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not zero and is the name of a shader object.");
453     ctx.glDeleteProgram(shader);
454     ctx.expectError(GL_INVALID_OPERATION);
455     ctx.endSection();
456 
457     ctx.glDeleteShader(shader);
458 }
459 
validate_program(NegativeTestContext & ctx)460 void validate_program(NegativeTestContext &ctx)
461 {
462     GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
463 
464     const GLuint notAProgram = ctx.glCreateProgram();
465     ctx.glDeleteProgram(notAProgram);
466 
467     ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
468     ctx.glValidateProgram(notAProgram);
469     ctx.expectError(GL_INVALID_VALUE);
470     ctx.endSection();
471 
472     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
473     ctx.glValidateProgram(shader);
474     ctx.expectError(GL_INVALID_OPERATION);
475     ctx.endSection();
476 
477     ctx.glDeleteShader(shader);
478 }
479 
get_program_binary(NegativeTestContext & ctx)480 void get_program_binary(NegativeTestContext &ctx)
481 {
482     glu::ShaderProgram program(ctx.getRenderContext(),
483                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
484     glu::ShaderProgram programInvalid(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, ""));
485     GLenum binaryFormat  = -1;
486     GLsizei binaryLength = -1;
487     GLint binaryPtr      = -1;
488     GLint bufSize        = -1;
489     GLint linkStatus     = -1;
490 
491     ctx.beginSection(
492         "GL_INVALID_OPERATION is generated if bufSize is less than the size of GL_PROGRAM_BINARY_LENGTH for program.");
493     ctx.glGetProgramiv(program.getProgram(), GL_PROGRAM_BINARY_LENGTH, &bufSize);
494     ctx.expectError(GL_NO_ERROR);
495     ctx.glGetProgramiv(program.getProgram(), GL_LINK_STATUS, &linkStatus);
496     ctx.getLog() << TestLog::Message << "// GL_PROGRAM_BINARY_LENGTH = " << bufSize << TestLog::EndMessage;
497     ctx.getLog() << TestLog::Message << "// GL_LINK_STATUS = " << linkStatus << TestLog::EndMessage;
498     ctx.expectError(GL_NO_ERROR);
499 
500     ctx.glGetProgramBinary(program.getProgram(), 0, &binaryLength, &binaryFormat, &binaryPtr);
501     ctx.expectError(GL_INVALID_OPERATION);
502     if (bufSize > 0)
503     {
504         ctx.glGetProgramBinary(program.getProgram(), bufSize - 1, &binaryLength, &binaryFormat, &binaryPtr);
505         ctx.expectError(GL_INVALID_OPERATION);
506     }
507     ctx.endSection();
508 
509     ctx.beginSection("GL_INVALID_OPERATION is generated if GL_LINK_STATUS for the program object is false.");
510     ctx.glGetProgramiv(programInvalid.getProgram(), GL_PROGRAM_BINARY_LENGTH, &bufSize);
511     ctx.expectError(GL_NO_ERROR);
512     ctx.glGetProgramiv(programInvalid.getProgram(), GL_LINK_STATUS, &linkStatus);
513     ctx.getLog() << TestLog::Message << "// GL_PROGRAM_BINARY_LENGTH = " << bufSize << TestLog::EndMessage;
514     ctx.getLog() << TestLog::Message << "// GL_LINK_STATUS = " << linkStatus << TestLog::EndMessage;
515     ctx.expectError(GL_NO_ERROR);
516 
517     if (!linkStatus)
518     {
519         ctx.glGetProgramBinary(programInvalid.getProgram(), bufSize, &binaryLength, &binaryFormat, &binaryPtr);
520         ctx.expectError(GL_INVALID_OPERATION);
521         ctx.endSection();
522     }
523     else
524     {
525         if (isContextTypeES(ctx.getRenderContext().getType()))
526             ctx.fail("Program should not have linked");
527     }
528 }
529 
program_binary(NegativeTestContext & ctx)530 void program_binary(NegativeTestContext &ctx)
531 {
532     glu::ShaderProgram srcProgram(ctx.getRenderContext(),
533                                   glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
534     GLuint dstProgram    = ctx.glCreateProgram();
535     GLuint unusedShader  = ctx.glCreateShader(GL_VERTEX_SHADER);
536     GLenum binaryFormat  = -1;
537     GLsizei binaryLength = -1;
538     std::vector<uint8_t> binaryBuf;
539     GLint bufSize    = -1;
540     GLint linkStatus = -1;
541 
542     ctx.glGetProgramiv(srcProgram.getProgram(), GL_PROGRAM_BINARY_LENGTH, &bufSize);
543     ctx.glGetProgramiv(srcProgram.getProgram(), GL_LINK_STATUS, &linkStatus);
544     ctx.getLog() << TestLog::Message << "// GL_PROGRAM_BINARY_LENGTH = " << bufSize << TestLog::EndMessage;
545     ctx.getLog() << TestLog::Message << "// GL_LINK_STATUS = " << linkStatus << TestLog::EndMessage;
546 
547     TCU_CHECK(bufSize >= 0);
548     if (bufSize > 0)
549     {
550         binaryBuf.resize(bufSize);
551         ctx.glGetProgramBinary(srcProgram.getProgram(), bufSize, &binaryLength, &binaryFormat, &binaryBuf[0]);
552         ctx.expectError(GL_NO_ERROR);
553 
554         ctx.beginSection("GL_INVALID_OPERATION is generated if program is not the name of an existing program object.");
555         ctx.glProgramBinary(unusedShader, binaryFormat, &binaryBuf[0], binaryLength);
556         ctx.expectError(GL_INVALID_OPERATION);
557         ctx.endSection();
558 
559         ctx.beginSection(
560             "GL_INVALID_ENUM is generated if binaryFormat is not a value recognized by the implementation.");
561         ctx.glProgramBinary(dstProgram, -1, &binaryBuf[0], binaryLength);
562         ctx.expectError(GL_INVALID_ENUM);
563         ctx.endSection();
564     }
565 
566     ctx.glDeleteShader(unusedShader);
567     ctx.glDeleteProgram(dstProgram);
568 }
569 
program_parameteri(NegativeTestContext & ctx)570 void program_parameteri(NegativeTestContext &ctx)
571 {
572     GLuint program = ctx.glCreateProgram();
573     GLuint shader  = ctx.glCreateShader(GL_VERTEX_SHADER);
574 
575     const GLuint notAProgram = ctx.glCreateProgram();
576     ctx.glDeleteProgram(notAProgram);
577 
578     ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of an existing program object.");
579     ctx.glProgramParameteri(notAProgram, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
580     ctx.expectError(GL_INVALID_VALUE);
581     ctx.endSection();
582 
583     ctx.beginSection("GL_INVALID_OPERATION is generated if program is the name of a shader object.");
584     ctx.glProgramParameteri(shader, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
585     ctx.expectError(GL_INVALID_OPERATION);
586     ctx.endSection();
587 
588     ctx.beginSection(
589         "GL_INVALID_ENUM is generated if pname is not GL_PROGRAM_BINARY_RETRIEVABLE_HINT or PROGRAM_SEPARABLE.");
590     ctx.glProgramParameteri(program, -1, GL_TRUE);
591     ctx.expectError(GL_INVALID_ENUM);
592     ctx.endSection();
593 
594     ctx.beginSection("GL_INVALID_VALUE is generated if value is not GL_FALSE or GL_TRUE.");
595     ctx.glProgramParameteri(program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, 2);
596     ctx.expectError(GL_INVALID_VALUE);
597     ctx.endSection();
598 
599     ctx.glDeleteProgram(program);
600     ctx.glDeleteShader(shader);
601 }
602 
gen_samplers(NegativeTestContext & ctx)603 void gen_samplers(NegativeTestContext &ctx)
604 {
605     ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
606     GLuint sampler = 0;
607     ctx.glGenSamplers(-1, &sampler);
608     ctx.expectError(GL_INVALID_VALUE);
609     ctx.endSection();
610 }
611 
bind_sampler(NegativeTestContext & ctx)612 void bind_sampler(NegativeTestContext &ctx)
613 {
614     int maxTexImageUnits = 0x1234;
615     GLuint sampler       = 0;
616     ctx.glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTexImageUnits);
617     ctx.glGenSamplers(1, &sampler);
618 
619     ctx.beginSection("GL_INVALID_VALUE is generated if unit is greater than or equal to the value of "
620                      "GL_MAX_COMBIED_TEXTURE_IMAGE_UNITS.");
621     ctx.glBindSampler(maxTexImageUnits, sampler);
622     ctx.expectError(GL_INVALID_VALUE);
623     ctx.endSection();
624 
625     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not zero or a name previously returned from a "
626                      "call to ctx.glGenSamplers.");
627     ctx.glBindSampler(1, -1);
628     ctx.expectError(GL_INVALID_OPERATION);
629     ctx.endSection();
630 
631     ctx.beginSection(
632         "GL_INVALID_OPERATION is generated if sampler has been deleted by a call to ctx.glDeleteSamplers.");
633     ctx.glDeleteSamplers(1, &sampler);
634     ctx.glBindSampler(1, sampler);
635     ctx.expectError(GL_INVALID_OPERATION);
636     ctx.endSection();
637 }
638 
delete_samplers(NegativeTestContext & ctx)639 void delete_samplers(NegativeTestContext &ctx)
640 {
641     ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
642     ctx.glDeleteSamplers(-1, 0);
643     ctx.expectError(GL_INVALID_VALUE);
644     ctx.endSection();
645 }
646 
get_sampler_parameteriv(NegativeTestContext & ctx)647 void get_sampler_parameteriv(NegativeTestContext &ctx)
648 {
649     int params     = 0x1234;
650     GLuint sampler = 0;
651     ctx.glGenSamplers(1, &sampler);
652 
653     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object returned from a "
654                      "previous call to ctx.glGenSamplers.");
655     ctx.glGetSamplerParameteriv(-1, GL_TEXTURE_MAG_FILTER, &params);
656     ctx.expectError(GL_INVALID_OPERATION);
657     ctx.endSection();
658 
659     ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted value.");
660     ctx.glGetSamplerParameteriv(sampler, -1, &params);
661     ctx.expectError(GL_INVALID_ENUM);
662     ctx.endSection();
663 
664     ctx.glDeleteSamplers(1, &sampler);
665 }
666 
get_sampler_parameterfv(NegativeTestContext & ctx)667 void get_sampler_parameterfv(NegativeTestContext &ctx)
668 {
669     float params   = 0.0f;
670     GLuint sampler = 0;
671     ctx.glGenSamplers(1, &sampler);
672 
673     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object returned from a "
674                      "previous call to ctx.glGenSamplers.");
675     ctx.glGetSamplerParameterfv(-1, GL_TEXTURE_MAG_FILTER, &params);
676     ctx.expectError(GL_INVALID_OPERATION);
677     ctx.endSection();
678 
679     ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted value.");
680     ctx.glGetSamplerParameterfv(sampler, -1, &params);
681     ctx.expectError(GL_INVALID_ENUM);
682     ctx.endSection();
683 
684     ctx.glDeleteSamplers(1, &sampler);
685 }
686 
get_sampler_parameterIiv(NegativeTestContext & ctx)687 void get_sampler_parameterIiv(NegativeTestContext &ctx)
688 {
689     if (!supportsES32orGL45(ctx))
690         throw tcu::NotSupportedError("glGetSamplerParameterIiv is not supported.", DE_NULL, __FILE__, __LINE__);
691 
692     GLuint sampler      = 0x1234;
693     GLint borderColor[] = {0x1234, 0x4123, 0x3412, 0x2341};
694 
695     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object returned from a "
696                      "previous call to ctx.glGenSamplers.");
697     ctx.glGetSamplerParameterIiv(sampler, GL_TEXTURE_BORDER_COLOR, &borderColor[0]);
698     ctx.expectError(GL_INVALID_OPERATION);
699     ctx.endSection();
700 
701     ctx.glGenSamplers(1, &sampler);
702 
703     ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted value.");
704     ctx.glGetSamplerParameterIiv(sampler, -1, &borderColor[0]);
705     ctx.expectError(GL_INVALID_ENUM);
706     ctx.endSection();
707 
708     ctx.glDeleteSamplers(1, &sampler);
709 }
710 
get_sampler_parameterIuiv(NegativeTestContext & ctx)711 void get_sampler_parameterIuiv(NegativeTestContext &ctx)
712 {
713     if (!supportsES32orGL45(ctx))
714         throw tcu::NotSupportedError("glGetSamplerParameterIuiv is not supported.", DE_NULL, __FILE__, __LINE__);
715 
716     GLuint sampler       = 0x1234;
717     GLuint borderColor[] = {0x1234, 0x4123, 0x3412, 0x2341};
718 
719     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object returned from a "
720                      "previous call to ctx.glGenSamplers.");
721     ctx.glGetSamplerParameterIuiv(sampler, GL_TEXTURE_BORDER_COLOR, &borderColor[0]);
722     ctx.expectError(GL_INVALID_OPERATION);
723     ctx.endSection();
724 
725     ctx.glGenSamplers(1, &sampler);
726 
727     ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted value.");
728     ctx.glGetSamplerParameterIuiv(sampler, -1, &borderColor[0]);
729     ctx.expectError(GL_INVALID_ENUM);
730     ctx.endSection();
731 
732     ctx.glDeleteSamplers(1, &sampler);
733 }
734 
sampler_parameteri(NegativeTestContext & ctx)735 void sampler_parameteri(NegativeTestContext &ctx)
736 {
737     GLuint sampler = 0;
738 
739     ctx.glGenSamplers(1, &sampler);
740 
741     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously "
742                      "returned from a call to ctx.glGenSamplers.");
743     ctx.glSamplerParameteri(-1, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
744     ctx.expectError(GL_INVALID_OPERATION);
745     ctx.endSection();
746 
747     ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value "
748                      "of pname) and does not.");
749     ctx.glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, -1);
750     ctx.expectError(GL_INVALID_ENUM);
751     ctx.endSection();
752 
753     if (supportsES32orGL45(ctx))
754     {
755         ctx.beginSection("GL_INVALID_ENUM is generated if glSamplerParameteri is called for a non-scalar parameter.");
756         ctx.glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, 0);
757         ctx.expectError(GL_INVALID_ENUM);
758         ctx.endSection();
759     }
760 
761     ctx.glDeleteSamplers(1, &sampler);
762 }
763 
sampler_parameteriv(NegativeTestContext & ctx)764 void sampler_parameteriv(NegativeTestContext &ctx)
765 {
766     int params     = 0x1234;
767     GLuint sampler = 0;
768     ctx.glGenSamplers(1, &sampler);
769 
770     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously "
771                      "returned from a call to ctx.glGenSamplers.");
772     params = GL_CLAMP_TO_EDGE;
773     ctx.glSamplerParameteriv(-1, GL_TEXTURE_WRAP_S, &params);
774     ctx.expectError(GL_INVALID_OPERATION);
775     ctx.endSection();
776 
777     ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value "
778                      "of pname) and does not.");
779     params = -1;
780     ctx.glSamplerParameteriv(sampler, GL_TEXTURE_WRAP_S, &params);
781     ctx.expectError(GL_INVALID_ENUM);
782     ctx.endSection();
783 
784     ctx.glDeleteSamplers(1, &sampler);
785 }
786 
sampler_parameterf(NegativeTestContext & ctx)787 void sampler_parameterf(NegativeTestContext &ctx)
788 {
789     GLuint sampler = 0;
790 
791     ctx.glGenSamplers(1, &sampler);
792 
793     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously "
794                      "returned from a call to ctx.glGenSamplers.");
795     ctx.glSamplerParameterf(-1, GL_TEXTURE_MIN_LOD, -1000.0f);
796     ctx.expectError(GL_INVALID_OPERATION);
797     ctx.endSection();
798 
799     ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value "
800                      "of pname) and does not.");
801     ctx.glSamplerParameterf(sampler, GL_TEXTURE_WRAP_S, -1.0f);
802     ctx.expectError(GL_INVALID_ENUM);
803     ctx.endSection();
804 
805     if (supportsES32orGL45(ctx))
806     {
807         ctx.beginSection("GL_INVALID_ENUM is generated if glSamplerParameterf is called for a non-scalar parameter.");
808         ctx.glSamplerParameteri(sampler, GL_TEXTURE_BORDER_COLOR, 0);
809         ctx.expectError(GL_INVALID_ENUM);
810         ctx.endSection();
811     }
812 
813     ctx.glDeleteSamplers(1, &sampler);
814 }
815 
sampler_parameterfv(NegativeTestContext & ctx)816 void sampler_parameterfv(NegativeTestContext &ctx)
817 {
818     float params;
819     GLuint sampler = 0;
820     ctx.glGenSamplers(1, &sampler);
821 
822     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously "
823                      "returned from a call to ctx.glGenSamplers.");
824     params = -1000.0f;
825     ctx.glSamplerParameterfv(-1, GL_TEXTURE_WRAP_S, &params);
826     ctx.expectError(GL_INVALID_OPERATION);
827     ctx.endSection();
828 
829     ctx.beginSection("GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value "
830                      "of pname) and does not.");
831     params = -1.0f;
832     ctx.glSamplerParameterfv(sampler, GL_TEXTURE_WRAP_S, &params);
833     ctx.expectError(GL_INVALID_ENUM);
834     ctx.endSection();
835 
836     ctx.glDeleteSamplers(1, &sampler);
837 }
838 
sampler_parameterIiv(NegativeTestContext & ctx)839 void sampler_parameterIiv(NegativeTestContext &ctx)
840 {
841     if (!supportsES32orGL45(ctx))
842         throw tcu::NotSupportedError("glSamplerParameterIiv is not supported.", DE_NULL, __FILE__, __LINE__);
843 
844     GLuint sampler;
845     GLint color[] = {0, 0, 0, 0};
846 
847     ctx.glGenSamplers(1, &sampler);
848 
849     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously "
850                      "returned from a call to ctx.glGenSamplers.");
851     ctx.glSamplerParameterIiv(-1, GL_TEXTURE_BORDER_COLOR, color);
852     ctx.expectError(GL_INVALID_OPERATION);
853     ctx.endSection();
854 
855     ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted sampler state name.");
856     ctx.glSamplerParameterIiv(sampler, -1, color);
857     ctx.expectError(GL_INVALID_ENUM);
858     ctx.endSection();
859 }
860 
sampler_parameterIuiv(NegativeTestContext & ctx)861 void sampler_parameterIuiv(NegativeTestContext &ctx)
862 {
863     if (!supportsES32orGL45(ctx))
864         throw tcu::NotSupportedError("glSamplerParameterIuiv is not supported.", DE_NULL, __FILE__, __LINE__);
865 
866     GLuint sampler;
867     GLuint color[] = {0, 0, 0, 0};
868 
869     ctx.glGenSamplers(1, &sampler);
870 
871     ctx.beginSection("GL_INVALID_OPERATION is generated if sampler is not the name of a sampler object previously "
872                      "returned from a call to ctx.glGenSamplers.");
873     ctx.glSamplerParameterIuiv(-1, GL_TEXTURE_BORDER_COLOR, color);
874     ctx.expectError(GL_INVALID_OPERATION);
875     ctx.endSection();
876 
877     ctx.beginSection("GL_INVALID_ENUM is generated if pname is not an accepted sampler state name.");
878     ctx.glSamplerParameterIuiv(sampler, -1, color);
879     ctx.expectError(GL_INVALID_ENUM);
880     ctx.endSection();
881 }
882 
883 // Shader data commands
884 
get_attrib_location(NegativeTestContext & ctx)885 void get_attrib_location(NegativeTestContext &ctx)
886 {
887     GLuint programEmpty = ctx.glCreateProgram();
888     GLuint shader       = ctx.glCreateShader(GL_VERTEX_SHADER);
889 
890     glu::ShaderProgram program(ctx.getRenderContext(),
891                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
892 
893     const GLuint notAProgram = ctx.glCreateProgram();
894     ctx.glDeleteProgram(notAProgram);
895 
896     ctx.beginSection("GL_INVALID_OPERATION is generated if program has not been successfully linked.");
897     ctx.glBindAttribLocation(programEmpty, 0, "test");
898     ctx.glGetAttribLocation(programEmpty, "test");
899     ctx.expectError(GL_INVALID_OPERATION);
900     ctx.endSection();
901 
902     ctx.beginSection("GL_INVALID_VALUE is generated if program is not a program or shader object.");
903     ctx.glUseProgram(program.getProgram());
904     ctx.glBindAttribLocation(program.getProgram(), 0, "test");
905     ctx.expectError(GL_NO_ERROR);
906     ctx.glGetAttribLocation(program.getProgram(), "test");
907     ctx.expectError(GL_NO_ERROR);
908     ctx.glGetAttribLocation(notAProgram, "test");
909     ctx.expectError(GL_INVALID_VALUE);
910     ctx.endSection();
911 
912     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
913     ctx.glGetAttribLocation(shader, "test");
914     ctx.expectError(GL_INVALID_OPERATION);
915     ctx.endSection();
916 
917     ctx.glUseProgram(0);
918     ctx.glDeleteShader(shader);
919     ctx.glDeleteProgram(programEmpty);
920 }
921 
get_uniform_location(NegativeTestContext & ctx)922 void get_uniform_location(NegativeTestContext &ctx)
923 {
924     GLuint programEmpty = ctx.glCreateProgram();
925     GLuint shader       = ctx.glCreateShader(GL_VERTEX_SHADER);
926 
927     glu::ShaderProgram program(ctx.getRenderContext(),
928                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
929 
930     const GLuint notAProgram = ctx.glCreateProgram();
931     ctx.glDeleteProgram(notAProgram);
932 
933     ctx.beginSection("GL_INVALID_OPERATION is generated if program has not been successfully linked.");
934     ctx.glGetUniformLocation(programEmpty, "test");
935     ctx.expectError(GL_INVALID_OPERATION);
936     ctx.endSection();
937 
938     ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
939     ctx.glUseProgram(program.getProgram());
940     ctx.glGetUniformLocation(notAProgram, "test");
941     ctx.expectError(GL_INVALID_VALUE);
942     ctx.endSection();
943 
944     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
945     ctx.glGetAttribLocation(shader, "test");
946     ctx.expectError(GL_INVALID_OPERATION);
947     ctx.endSection();
948 
949     ctx.glUseProgram(0);
950     ctx.glDeleteProgram(programEmpty);
951     ctx.glDeleteShader(shader);
952 }
953 
bind_attrib_location(NegativeTestContext & ctx)954 void bind_attrib_location(NegativeTestContext &ctx)
955 {
956     GLuint program  = ctx.glCreateProgram();
957     GLuint maxIndex = ctx.getInteger(GL_MAX_VERTEX_ATTRIBS);
958     GLuint shader   = ctx.glCreateShader(GL_VERTEX_SHADER);
959 
960     ctx.beginSection("GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.");
961     ctx.glBindAttribLocation(program, maxIndex, "test");
962     ctx.expectError(GL_INVALID_VALUE);
963     ctx.endSection();
964 
965     ctx.beginSection("GL_INVALID_OPERATION is generated if name starts with the reserved prefix \"gl_\".");
966     ctx.glBindAttribLocation(program, maxIndex - 1, "gl_test");
967     ctx.expectError(GL_INVALID_OPERATION);
968     ctx.endSection();
969 
970     ctx.beginSection("GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.");
971     ctx.glBindAttribLocation(-1, maxIndex - 1, "test");
972     ctx.expectError(GL_INVALID_VALUE);
973     ctx.endSection();
974 
975     ctx.beginSection("GL_INVALID_OPERATION is generated if program is not a program object.");
976     ctx.glBindAttribLocation(shader, maxIndex - 1, "test");
977     ctx.expectError(GL_INVALID_OPERATION);
978     ctx.endSection();
979 
980     ctx.glDeleteProgram(program);
981     ctx.glDeleteShader(shader);
982 }
983 
uniform_block_binding(NegativeTestContext & ctx)984 void uniform_block_binding(NegativeTestContext &ctx)
985 {
986     GLint maxUniformBufferBindings = -1;
987     GLint numActiveUniforms        = -1;
988     GLint numActiveBlocks          = -1;
989     GLuint shader                  = -1;
990     glu::ShaderProgram program(ctx.getRenderContext(),
991                                glu::makeVtxFragSources(uniformBlockVertSource, uniformTestFragSource));
992 
993     shader = ctx.glCreateShader(GL_VERTEX_SHADER);
994     ctx.glUseProgram(program.getProgram());
995 
996     ctx.glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &maxUniformBufferBindings);
997     ctx.glGetProgramiv(program.getProgram(), GL_ACTIVE_UNIFORMS, &numActiveUniforms);
998     ctx.glGetProgramiv(program.getProgram(), GL_ACTIVE_UNIFORM_BLOCKS, &numActiveBlocks);
999     ctx.getLog() << TestLog::Message << "// GL_MAX_UNIFORM_BUFFER_BINDINGS = " << maxUniformBufferBindings
1000                  << TestLog::EndMessage;
1001     ctx.getLog() << TestLog::Message << "// GL_ACTIVE_UNIFORMS = " << numActiveUniforms << TestLog::EndMessage;
1002     ctx.getLog() << TestLog::Message << "// GL_ACTIVE_UNIFORM_BLOCKS = " << numActiveBlocks << TestLog::EndMessage;
1003     ctx.expectError(GL_NO_ERROR);
1004 
1005     ctx.beginSection(
1006         "GL_INVALID_VALUE is generated if uniformBlockIndex is not an active uniform block index of program.");
1007     ctx.glUniformBlockBinding(program.getProgram(), -1, 0);
1008     ctx.expectError(GL_INVALID_VALUE);
1009     ctx.glUniformBlockBinding(program.getProgram(), 5, 0);
1010     ctx.expectError(GL_INVALID_VALUE);
1011     ctx.endSection();
1012 
1013     ctx.beginSection("GL_INVALID_VALUE is generated if uniformBlockBinding is greater than or equal to the value of "
1014                      "GL_MAX_UNIFORM_BUFFER_BINDINGS.");
1015     ctx.glUniformBlockBinding(program.getProgram(), maxUniformBufferBindings, 0);
1016     ctx.expectError(GL_INVALID_VALUE);
1017     ctx.endSection();
1018 
1019     ctx.beginSection(
1020         "GL_INVALID_VALUE is generated if program is not the name of a program object generated by the GL.");
1021     ctx.glUniformBlockBinding(-1, 0, 0);
1022     ctx.expectError(GL_INVALID_VALUE);
1023     ctx.endSection();
1024 
1025     ctx.beginSection("GL_INVALID_OPERATION is generated if program is the name of a shader object.");
1026     ctx.glUniformBlockBinding(shader, 0, 0);
1027     ctx.expectError(GL_INVALID_OPERATION);
1028     ctx.endSection();
1029 
1030     ctx.glDeleteShader(shader);
1031 }
1032 
1033 // ctx.glUniform*f
1034 
uniformf_invalid_program(NegativeTestContext & ctx)1035 void uniformf_invalid_program(NegativeTestContext &ctx)
1036 {
1037     ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1038     ctx.glUseProgram(0);
1039     ctx.glUniform1f(-1, 0.0f);
1040     ctx.expectError(GL_INVALID_OPERATION);
1041     ctx.glUniform2f(-1, 0.0f, 0.0f);
1042     ctx.expectError(GL_INVALID_OPERATION);
1043     ctx.glUniform3f(-1, 0.0f, 0.0f, 0.0f);
1044     ctx.expectError(GL_INVALID_OPERATION);
1045     ctx.glUniform4f(-1, 0.0f, 0.0f, 0.0f, 0.0f);
1046     ctx.expectError(GL_INVALID_OPERATION);
1047     ctx.endSection();
1048 }
1049 
uniformf_incompatible_type(NegativeTestContext & ctx)1050 void uniformf_incompatible_type(NegativeTestContext &ctx)
1051 {
1052     glu::ShaderProgram program(ctx.getRenderContext(),
1053                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1054 
1055     ctx.glUseProgram(program.getProgram());
1056     GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");    // vec4
1057     GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");   // ivec4
1058     GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");   // uvec4
1059     GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f"); // sampler2D
1060     ctx.expectError(GL_NO_ERROR);
1061 
1062     if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1063     {
1064         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1065         ctx.fail("Failed to retrieve uniform location");
1066     }
1067 
1068     ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader "
1069                      "does not match the size indicated by the ctx.glUniform command.");
1070     ctx.glUseProgram(program.getProgram());
1071     ctx.glUniform1f(vec4_v, 0.0f);
1072     ctx.expectError(GL_INVALID_OPERATION);
1073     ctx.glUniform2f(vec4_v, 0.0f, 0.0f);
1074     ctx.expectError(GL_INVALID_OPERATION);
1075     ctx.glUniform3f(vec4_v, 0.0f, 0.0f, 0.0f);
1076     ctx.expectError(GL_INVALID_OPERATION);
1077     ctx.glUniform4f(vec4_v, 0.0f, 0.0f, 0.0f, 0.0f);
1078     ctx.expectError(GL_NO_ERROR);
1079     ctx.endSection();
1080 
1081     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}f is used to load a uniform variable of "
1082                      "type int, ivec2, ivec3, ivec4, unsigned int, uvec2, uvec3, uvec4.");
1083     ctx.glUseProgram(program.getProgram());
1084     ctx.glUniform4f(ivec4_f, 0.0f, 0.0f, 0.0f, 0.0f);
1085     ctx.expectError(GL_INVALID_OPERATION);
1086     ctx.glUniform4f(uvec4_f, 0.0f, 0.0f, 0.0f, 0.0f);
1087     ctx.expectError(GL_INVALID_OPERATION);
1088     ctx.endSection();
1089 
1090     ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than "
1091                      "ctx.glUniform1i and ctx.glUniform1iv.");
1092     ctx.glUseProgram(program.getProgram());
1093     ctx.glUniform1f(sampler_f, 0.0f);
1094     ctx.expectError(GL_INVALID_OPERATION);
1095     ctx.endSection();
1096 
1097     ctx.glUseProgram(0);
1098 }
1099 
uniformf_invalid_location(NegativeTestContext & ctx)1100 void uniformf_invalid_location(NegativeTestContext &ctx)
1101 {
1102     glu::ShaderProgram program(ctx.getRenderContext(),
1103                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1104 
1105     ctx.glUseProgram(program.getProgram());
1106     ctx.expectError(GL_NO_ERROR);
1107 
1108     ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current "
1109                      "program object and location is not equal to -1.");
1110     ctx.glUseProgram(program.getProgram());
1111     ctx.glUniform1f(-2, 0.0f);
1112     ctx.expectError(GL_INVALID_OPERATION);
1113     ctx.glUniform2f(-2, 0.0f, 0.0f);
1114     ctx.expectError(GL_INVALID_OPERATION);
1115     ctx.glUniform3f(-2, 0.0f, 0.0f, 0.0f);
1116     ctx.expectError(GL_INVALID_OPERATION);
1117     ctx.glUniform4f(-2, 0.0f, 0.0f, 0.0f, 0.0f);
1118     ctx.expectError(GL_INVALID_OPERATION);
1119 
1120     ctx.glUseProgram(program.getProgram());
1121     ctx.glUniform1f(-1, 0.0f);
1122     ctx.expectError(GL_NO_ERROR);
1123     ctx.glUniform2f(-1, 0.0f, 0.0f);
1124     ctx.expectError(GL_NO_ERROR);
1125     ctx.glUniform3f(-1, 0.0f, 0.0f, 0.0f);
1126     ctx.expectError(GL_NO_ERROR);
1127     ctx.glUniform4f(-1, 0.0f, 0.0f, 0.0f, 0.0f);
1128     ctx.expectError(GL_NO_ERROR);
1129     ctx.endSection();
1130 
1131     ctx.glUseProgram(0);
1132 }
1133 
1134 // ctx.glUniform*fv
1135 
uniformfv_invalid_program(NegativeTestContext & ctx)1136 void uniformfv_invalid_program(NegativeTestContext &ctx)
1137 {
1138     std::vector<GLfloat> data(4);
1139 
1140     ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1141     ctx.glUseProgram(0);
1142     ctx.glUniform1fv(-1, 1, &data[0]);
1143     ctx.expectError(GL_INVALID_OPERATION);
1144     ctx.glUniform2fv(-1, 1, &data[0]);
1145     ctx.expectError(GL_INVALID_OPERATION);
1146     ctx.glUniform3fv(-1, 1, &data[0]);
1147     ctx.expectError(GL_INVALID_OPERATION);
1148     ctx.glUniform4fv(-1, 1, &data[0]);
1149     ctx.expectError(GL_INVALID_OPERATION);
1150     ctx.endSection();
1151 }
1152 
uniformfv_incompatible_type(NegativeTestContext & ctx)1153 void uniformfv_incompatible_type(NegativeTestContext &ctx)
1154 {
1155     glu::ShaderProgram program(ctx.getRenderContext(),
1156                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1157 
1158     ctx.glUseProgram(program.getProgram());
1159     GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");    // vec4
1160     GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");   // ivec4
1161     GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");   // uvec4
1162     GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f"); // sampler2D
1163     ctx.expectError(GL_NO_ERROR);
1164 
1165     if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1166     {
1167         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1168         ctx.fail("Failed to retrieve uniform location");
1169     }
1170 
1171     std::vector<GLfloat> data(4);
1172 
1173     ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader "
1174                      "does not match the size indicated by the ctx.glUniform command.");
1175     ctx.glUseProgram(program.getProgram());
1176     ctx.glUniform1fv(vec4_v, 1, &data[0]);
1177     ctx.expectError(GL_INVALID_OPERATION);
1178     ctx.glUniform2fv(vec4_v, 1, &data[0]);
1179     ctx.expectError(GL_INVALID_OPERATION);
1180     ctx.glUniform3fv(vec4_v, 1, &data[0]);
1181     ctx.expectError(GL_INVALID_OPERATION);
1182     ctx.glUniform4fv(vec4_v, 1, &data[0]);
1183     ctx.expectError(GL_NO_ERROR);
1184     ctx.endSection();
1185 
1186     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}fv is used to load a uniform variable of "
1187                      "type int, ivec2, ivec3, ivec4, unsigned int, uvec2, uvec3, uvec4.");
1188     ctx.glUseProgram(program.getProgram());
1189     ctx.glUniform4fv(ivec4_f, 1, &data[0]);
1190     ctx.expectError(GL_INVALID_OPERATION);
1191     ctx.glUniform4fv(uvec4_f, 1, &data[0]);
1192     ctx.expectError(GL_INVALID_OPERATION);
1193     ctx.endSection();
1194 
1195     ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than "
1196                      "ctx.glUniform1i and ctx.glUniform1iv.");
1197     ctx.glUseProgram(program.getProgram());
1198     ctx.glUniform1fv(sampler_f, 1, &data[0]);
1199     ctx.expectError(GL_INVALID_OPERATION);
1200     ctx.endSection();
1201 
1202     ctx.glUseProgram(0);
1203 }
1204 
uniformfv_invalid_location(NegativeTestContext & ctx)1205 void uniformfv_invalid_location(NegativeTestContext &ctx)
1206 {
1207     glu::ShaderProgram program(ctx.getRenderContext(),
1208                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1209 
1210     ctx.glUseProgram(program.getProgram());
1211     ctx.expectError(GL_NO_ERROR);
1212 
1213     std::vector<GLfloat> data(4);
1214 
1215     ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current "
1216                      "program object and location is not equal to -1.");
1217     ctx.glUseProgram(program.getProgram());
1218     ctx.glUniform1fv(-2, 1, &data[0]);
1219     ctx.expectError(GL_INVALID_OPERATION);
1220     ctx.glUniform2fv(-2, 1, &data[0]);
1221     ctx.expectError(GL_INVALID_OPERATION);
1222     ctx.glUniform3fv(-2, 1, &data[0]);
1223     ctx.expectError(GL_INVALID_OPERATION);
1224     ctx.glUniform4fv(-2, 1, &data[0]);
1225     ctx.expectError(GL_INVALID_OPERATION);
1226 
1227     ctx.glUseProgram(program.getProgram());
1228     ctx.glUniform1fv(-1, 1, &data[0]);
1229     ctx.expectError(GL_NO_ERROR);
1230     ctx.glUniform2fv(-1, 1, &data[0]);
1231     ctx.expectError(GL_NO_ERROR);
1232     ctx.glUniform3fv(-1, 1, &data[0]);
1233     ctx.expectError(GL_NO_ERROR);
1234     ctx.glUniform4fv(-1, 1, &data[0]);
1235     ctx.expectError(GL_NO_ERROR);
1236     ctx.endSection();
1237 
1238     ctx.glUseProgram(0);
1239 }
1240 
uniformfv_invalid_count(NegativeTestContext & ctx)1241 void uniformfv_invalid_count(NegativeTestContext &ctx)
1242 {
1243     glu::ShaderProgram program(ctx.getRenderContext(),
1244                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1245 
1246     ctx.glUseProgram(program.getProgram());
1247     GLint vec4_v = ctx.glGetUniformLocation(program.getProgram(), "vec4_v"); // vec4
1248     ctx.expectError(GL_NO_ERROR);
1249 
1250     if (vec4_v == -1)
1251     {
1252         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1253         ctx.fail("Failed to retrieve uniform location");
1254     }
1255 
1256     std::vector<GLfloat> data(8);
1257 
1258     ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable "
1259                      "is not an array variable.");
1260     ctx.glUseProgram(program.getProgram());
1261     ctx.glUniform1fv(vec4_v, 2, &data[0]);
1262     ctx.expectError(GL_INVALID_OPERATION);
1263     ctx.glUniform2fv(vec4_v, 2, &data[0]);
1264     ctx.expectError(GL_INVALID_OPERATION);
1265     ctx.glUniform3fv(vec4_v, 2, &data[0]);
1266     ctx.expectError(GL_INVALID_OPERATION);
1267     ctx.glUniform4fv(vec4_v, 2, &data[0]);
1268     ctx.expectError(GL_INVALID_OPERATION);
1269     ctx.endSection();
1270 
1271     ctx.glUseProgram(0);
1272 }
1273 
1274 // ctx.glUniform*i
1275 
uniformi_invalid_program(NegativeTestContext & ctx)1276 void uniformi_invalid_program(NegativeTestContext &ctx)
1277 {
1278     ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1279     ctx.glUseProgram(0);
1280     ctx.glUniform1i(-1, 0);
1281     ctx.expectError(GL_INVALID_OPERATION);
1282     ctx.glUniform2i(-1, 0, 0);
1283     ctx.expectError(GL_INVALID_OPERATION);
1284     ctx.glUniform3i(-1, 0, 0, 0);
1285     ctx.expectError(GL_INVALID_OPERATION);
1286     ctx.glUniform4i(-1, 0, 0, 0, 0);
1287     ctx.expectError(GL_INVALID_OPERATION);
1288     ctx.endSection();
1289 }
1290 
uniformi_incompatible_type(NegativeTestContext & ctx)1291 void uniformi_incompatible_type(NegativeTestContext &ctx)
1292 {
1293     glu::ShaderProgram program(ctx.getRenderContext(),
1294                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1295 
1296     ctx.glUseProgram(program.getProgram());
1297     GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");    // vec4
1298     GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");   // ivec4
1299     GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");   // uvec4
1300     GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f"); // sampler2D
1301     ctx.expectError(GL_NO_ERROR);
1302 
1303     if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1304     {
1305         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1306         ctx.fail("Failed to retrieve uniform location");
1307     }
1308 
1309     ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader "
1310                      "does not match the size indicated by the ctx.glUniform command.");
1311     ctx.glUseProgram(program.getProgram());
1312     ctx.glUniform1i(ivec4_f, 0);
1313     ctx.expectError(GL_INVALID_OPERATION);
1314     ctx.glUniform2i(ivec4_f, 0, 0);
1315     ctx.expectError(GL_INVALID_OPERATION);
1316     ctx.glUniform3i(ivec4_f, 0, 0, 0);
1317     ctx.expectError(GL_INVALID_OPERATION);
1318     ctx.glUniform4i(ivec4_f, 0, 0, 0, 0);
1319     ctx.expectError(GL_NO_ERROR);
1320     ctx.endSection();
1321 
1322     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of "
1323                      "type unsigned int, uvec2, uvec3, uvec4, or an array of these.");
1324     ctx.glUseProgram(program.getProgram());
1325     ctx.glUniform1i(uvec4_f, 0);
1326     ctx.expectError(GL_INVALID_OPERATION);
1327     ctx.glUniform2i(uvec4_f, 0, 0);
1328     ctx.expectError(GL_INVALID_OPERATION);
1329     ctx.glUniform3i(uvec4_f, 0, 0, 0);
1330     ctx.expectError(GL_INVALID_OPERATION);
1331     ctx.glUniform4i(uvec4_f, 0, 0, 0, 0);
1332     ctx.expectError(GL_INVALID_OPERATION);
1333     ctx.endSection();
1334 
1335     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of "
1336                      "type float, vec2, vec3, or vec4.");
1337     ctx.glUseProgram(program.getProgram());
1338     ctx.glUniform1i(vec4_v, 0);
1339     ctx.expectError(GL_INVALID_OPERATION);
1340     ctx.glUniform2i(vec4_v, 0, 0);
1341     ctx.expectError(GL_INVALID_OPERATION);
1342     ctx.glUniform3i(vec4_v, 0, 0, 0);
1343     ctx.expectError(GL_INVALID_OPERATION);
1344     ctx.glUniform4i(vec4_v, 0, 0, 0, 0);
1345     ctx.expectError(GL_INVALID_OPERATION);
1346     ctx.endSection();
1347 
1348     ctx.glUseProgram(0);
1349 }
1350 
uniformi_invalid_location(NegativeTestContext & ctx)1351 void uniformi_invalid_location(NegativeTestContext &ctx)
1352 {
1353     glu::ShaderProgram program(ctx.getRenderContext(),
1354                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1355 
1356     ctx.glUseProgram(program.getProgram());
1357     ctx.expectError(GL_NO_ERROR);
1358 
1359     ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current "
1360                      "program object and location is not equal to -1.");
1361     ctx.glUseProgram(program.getProgram());
1362     ctx.glUniform1i(-2, 0);
1363     ctx.expectError(GL_INVALID_OPERATION);
1364     ctx.glUniform2i(-2, 0, 0);
1365     ctx.expectError(GL_INVALID_OPERATION);
1366     ctx.glUniform3i(-2, 0, 0, 0);
1367     ctx.expectError(GL_INVALID_OPERATION);
1368     ctx.glUniform4i(-2, 0, 0, 0, 0);
1369     ctx.expectError(GL_INVALID_OPERATION);
1370 
1371     ctx.glUseProgram(program.getProgram());
1372     ctx.glUniform1i(-1, 0);
1373     ctx.expectError(GL_NO_ERROR);
1374     ctx.glUniform2i(-1, 0, 0);
1375     ctx.expectError(GL_NO_ERROR);
1376     ctx.glUniform3i(-1, 0, 0, 0);
1377     ctx.expectError(GL_NO_ERROR);
1378     ctx.glUniform4i(-1, 0, 0, 0, 0);
1379     ctx.expectError(GL_NO_ERROR);
1380     ctx.endSection();
1381 
1382     ctx.glUseProgram(0);
1383 }
1384 
1385 // ctx.glUniform*iv
1386 
uniformiv_invalid_program(NegativeTestContext & ctx)1387 void uniformiv_invalid_program(NegativeTestContext &ctx)
1388 {
1389     std::vector<GLint> data(4);
1390 
1391     ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1392     ctx.glUseProgram(0);
1393     ctx.glUniform1iv(-1, 1, &data[0]);
1394     ctx.expectError(GL_INVALID_OPERATION);
1395     ctx.glUniform2iv(-1, 1, &data[0]);
1396     ctx.expectError(GL_INVALID_OPERATION);
1397     ctx.glUniform3iv(-1, 1, &data[0]);
1398     ctx.expectError(GL_INVALID_OPERATION);
1399     ctx.glUniform4iv(-1, 1, &data[0]);
1400     ctx.expectError(GL_INVALID_OPERATION);
1401     ctx.endSection();
1402 }
1403 
uniformiv_incompatible_type(NegativeTestContext & ctx)1404 void uniformiv_incompatible_type(NegativeTestContext &ctx)
1405 {
1406     glu::ShaderProgram program(ctx.getRenderContext(),
1407                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1408 
1409     ctx.glUseProgram(program.getProgram());
1410     GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");    // vec4
1411     GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");   // ivec4
1412     GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");   // uvec4
1413     GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f"); // sampler2D
1414     ctx.expectError(GL_NO_ERROR);
1415 
1416     if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1417     {
1418         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1419         ctx.fail("Failed to retrieve uniform location");
1420     }
1421 
1422     std::vector<GLint> data(4);
1423 
1424     ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader "
1425                      "does not match the size indicated by the ctx.glUniform command.");
1426     ctx.glUseProgram(program.getProgram());
1427     ctx.glUniform1iv(ivec4_f, 1, &data[0]);
1428     ctx.expectError(GL_INVALID_OPERATION);
1429     ctx.glUniform2iv(ivec4_f, 1, &data[0]);
1430     ctx.expectError(GL_INVALID_OPERATION);
1431     ctx.glUniform3iv(ivec4_f, 1, &data[0]);
1432     ctx.expectError(GL_INVALID_OPERATION);
1433     ctx.glUniform4iv(ivec4_f, 1, &data[0]);
1434     ctx.expectError(GL_NO_ERROR);
1435     ctx.endSection();
1436 
1437     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}iv is used to load a uniform variable of "
1438                      "type float, vec2, vec3, or vec4.");
1439     ctx.glUseProgram(program.getProgram());
1440     ctx.glUniform1iv(vec4_v, 1, &data[0]);
1441     ctx.expectError(GL_INVALID_OPERATION);
1442     ctx.glUniform2iv(vec4_v, 1, &data[0]);
1443     ctx.expectError(GL_INVALID_OPERATION);
1444     ctx.glUniform3iv(vec4_v, 1, &data[0]);
1445     ctx.expectError(GL_INVALID_OPERATION);
1446     ctx.glUniform4iv(vec4_v, 1, &data[0]);
1447     ctx.expectError(GL_INVALID_OPERATION);
1448     ctx.endSection();
1449 
1450     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}iv is used to load a uniform variable of "
1451                      "type unsigned int, uvec2, uvec3 or uvec4.");
1452     ctx.glUseProgram(program.getProgram());
1453     ctx.glUniform1iv(uvec4_f, 1, &data[0]);
1454     ctx.expectError(GL_INVALID_OPERATION);
1455     ctx.glUniform2iv(uvec4_f, 1, &data[0]);
1456     ctx.expectError(GL_INVALID_OPERATION);
1457     ctx.glUniform3iv(uvec4_f, 1, &data[0]);
1458     ctx.expectError(GL_INVALID_OPERATION);
1459     ctx.glUniform4iv(uvec4_f, 1, &data[0]);
1460     ctx.expectError(GL_INVALID_OPERATION);
1461     ctx.endSection();
1462 
1463     ctx.glUseProgram(0);
1464 }
1465 
uniformiv_invalid_location(NegativeTestContext & ctx)1466 void uniformiv_invalid_location(NegativeTestContext &ctx)
1467 {
1468     glu::ShaderProgram program(ctx.getRenderContext(),
1469                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1470 
1471     ctx.glUseProgram(program.getProgram());
1472     ctx.expectError(GL_NO_ERROR);
1473 
1474     std::vector<GLint> data(4);
1475 
1476     ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current "
1477                      "program object and location is not equal to -1.");
1478     ctx.glUseProgram(program.getProgram());
1479     ctx.glUniform1iv(-2, 1, &data[0]);
1480     ctx.expectError(GL_INVALID_OPERATION);
1481     ctx.glUniform2iv(-2, 1, &data[0]);
1482     ctx.expectError(GL_INVALID_OPERATION);
1483     ctx.glUniform3iv(-2, 1, &data[0]);
1484     ctx.expectError(GL_INVALID_OPERATION);
1485     ctx.glUniform4iv(-2, 1, &data[0]);
1486     ctx.expectError(GL_INVALID_OPERATION);
1487 
1488     ctx.glUseProgram(program.getProgram());
1489     ctx.glUniform1iv(-1, 1, &data[0]);
1490     ctx.expectError(GL_NO_ERROR);
1491     ctx.glUniform2iv(-1, 1, &data[0]);
1492     ctx.expectError(GL_NO_ERROR);
1493     ctx.glUniform3iv(-1, 1, &data[0]);
1494     ctx.expectError(GL_NO_ERROR);
1495     ctx.glUniform4iv(-1, 1, &data[0]);
1496     ctx.expectError(GL_NO_ERROR);
1497     ctx.endSection();
1498 
1499     ctx.glUseProgram(0);
1500 }
1501 
uniformiv_invalid_count(NegativeTestContext & ctx)1502 void uniformiv_invalid_count(NegativeTestContext &ctx)
1503 {
1504     glu::ShaderProgram program(ctx.getRenderContext(),
1505                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1506 
1507     ctx.glUseProgram(program.getProgram());
1508     GLint ivec4_f = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f"); // ivec4
1509     ctx.expectError(GL_NO_ERROR);
1510 
1511     if (ivec4_f == -1)
1512     {
1513         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1514         ctx.fail("Failed to retrieve uniform location");
1515     }
1516 
1517     std::vector<GLint> data(8);
1518 
1519     ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable "
1520                      "is not an array variable.");
1521     ctx.glUseProgram(program.getProgram());
1522     ctx.glUniform1iv(ivec4_f, 2, &data[0]);
1523     ctx.expectError(GL_INVALID_OPERATION);
1524     ctx.glUniform2iv(ivec4_f, 2, &data[0]);
1525     ctx.expectError(GL_INVALID_OPERATION);
1526     ctx.glUniform3iv(ivec4_f, 2, &data[0]);
1527     ctx.expectError(GL_INVALID_OPERATION);
1528     ctx.glUniform4iv(ivec4_f, 2, &data[0]);
1529     ctx.expectError(GL_INVALID_OPERATION);
1530     ctx.endSection();
1531 
1532     ctx.glUseProgram(0);
1533 }
1534 
1535 // ctx.glUniform{1234}ui
1536 
uniformui_invalid_program(NegativeTestContext & ctx)1537 void uniformui_invalid_program(NegativeTestContext &ctx)
1538 {
1539     ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1540     ctx.glUseProgram(0);
1541     ctx.glUniform1ui(-1, 0);
1542     ctx.expectError(GL_INVALID_OPERATION);
1543     ctx.glUniform2ui(-1, 0, 0);
1544     ctx.expectError(GL_INVALID_OPERATION);
1545     ctx.glUniform3ui(-1, 0, 0, 0);
1546     ctx.expectError(GL_INVALID_OPERATION);
1547     ctx.glUniform4ui(-1, 0, 0, 0, 0);
1548     ctx.expectError(GL_INVALID_OPERATION);
1549     ctx.endSection();
1550 }
1551 
uniformui_incompatible_type(NegativeTestContext & ctx)1552 void uniformui_incompatible_type(NegativeTestContext &ctx)
1553 {
1554     glu::ShaderProgram program(ctx.getRenderContext(),
1555                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1556 
1557     ctx.glUseProgram(program.getProgram());
1558     GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");    // vec4
1559     GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");   // ivec4
1560     GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");   // uvec4
1561     GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f"); // sampler2D
1562     ctx.expectError(GL_NO_ERROR);
1563 
1564     if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1565     {
1566         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1567         ctx.fail("Failed to retrieve uniform location");
1568     }
1569 
1570     ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader "
1571                      "does not match the size indicated by the ctx.glUniform command.");
1572     ctx.glUseProgram(program.getProgram());
1573     ctx.glUniform1ui(uvec4_f, 0);
1574     ctx.expectError(GL_INVALID_OPERATION);
1575     ctx.glUniform2ui(uvec4_f, 0, 0);
1576     ctx.expectError(GL_INVALID_OPERATION);
1577     ctx.glUniform3ui(uvec4_f, 0, 0, 0);
1578     ctx.expectError(GL_INVALID_OPERATION);
1579     ctx.glUniform4ui(uvec4_f, 0, 0, 0, 0);
1580     ctx.expectError(GL_NO_ERROR);
1581     ctx.endSection();
1582 
1583     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of "
1584                      "type int, ivec2, ivec3, ivec4, or an array of these.");
1585     ctx.glUseProgram(program.getProgram());
1586     ctx.glUniform1ui(ivec4_f, 0);
1587     ctx.expectError(GL_INVALID_OPERATION);
1588     ctx.glUniform2ui(ivec4_f, 0, 0);
1589     ctx.expectError(GL_INVALID_OPERATION);
1590     ctx.glUniform3ui(ivec4_f, 0, 0, 0);
1591     ctx.expectError(GL_INVALID_OPERATION);
1592     ctx.glUniform4ui(ivec4_f, 0, 0, 0, 0);
1593     ctx.expectError(GL_INVALID_OPERATION);
1594     ctx.endSection();
1595 
1596     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}i is used to load a uniform variable of "
1597                      "type float, vec2, vec3, or vec4.");
1598     ctx.glUseProgram(program.getProgram());
1599     ctx.glUniform1ui(vec4_v, 0);
1600     ctx.expectError(GL_INVALID_OPERATION);
1601     ctx.glUniform2ui(vec4_v, 0, 0);
1602     ctx.expectError(GL_INVALID_OPERATION);
1603     ctx.glUniform3ui(vec4_v, 0, 0, 0);
1604     ctx.expectError(GL_INVALID_OPERATION);
1605     ctx.glUniform4ui(vec4_v, 0, 0, 0, 0);
1606     ctx.expectError(GL_INVALID_OPERATION);
1607     ctx.endSection();
1608 
1609     ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than "
1610                      "ctx.glUniform1i and ctx.glUniform1iv.");
1611     ctx.glUseProgram(program.getProgram());
1612     ctx.glUniform1ui(sampler_f, 0);
1613     ctx.expectError(GL_INVALID_OPERATION);
1614     ctx.endSection();
1615 
1616     ctx.glUseProgram(0);
1617 }
1618 
uniformui_invalid_location(NegativeTestContext & ctx)1619 void uniformui_invalid_location(NegativeTestContext &ctx)
1620 {
1621     glu::ShaderProgram program(ctx.getRenderContext(),
1622                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1623 
1624     ctx.glUseProgram(program.getProgram());
1625     ctx.expectError(GL_NO_ERROR);
1626 
1627     ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current "
1628                      "program object and location is not equal to -1.");
1629     ctx.glUseProgram(program.getProgram());
1630     ctx.glUniform1i(-2, 0);
1631     ctx.expectError(GL_INVALID_OPERATION);
1632     ctx.glUniform2i(-2, 0, 0);
1633     ctx.expectError(GL_INVALID_OPERATION);
1634     ctx.glUniform3i(-2, 0, 0, 0);
1635     ctx.expectError(GL_INVALID_OPERATION);
1636     ctx.glUniform4i(-2, 0, 0, 0, 0);
1637     ctx.expectError(GL_INVALID_OPERATION);
1638 
1639     ctx.glUseProgram(program.getProgram());
1640     ctx.glUniform1i(-1, 0);
1641     ctx.expectError(GL_NO_ERROR);
1642     ctx.glUniform2i(-1, 0, 0);
1643     ctx.expectError(GL_NO_ERROR);
1644     ctx.glUniform3i(-1, 0, 0, 0);
1645     ctx.expectError(GL_NO_ERROR);
1646     ctx.glUniform4i(-1, 0, 0, 0, 0);
1647     ctx.expectError(GL_NO_ERROR);
1648     ctx.endSection();
1649 
1650     ctx.glUseProgram(0);
1651 }
1652 
1653 // ctx.glUniform{1234}uiv
1654 
uniformuiv_invalid_program(NegativeTestContext & ctx)1655 void uniformuiv_invalid_program(NegativeTestContext &ctx)
1656 {
1657     std::vector<GLuint> data(4);
1658 
1659     ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1660     ctx.glUseProgram(0);
1661     ctx.glUniform1uiv(-1, 1, &data[0]);
1662     ctx.expectError(GL_INVALID_OPERATION);
1663     ctx.glUniform2uiv(-1, 1, &data[0]);
1664     ctx.expectError(GL_INVALID_OPERATION);
1665     ctx.glUniform3uiv(-1, 1, &data[0]);
1666     ctx.expectError(GL_INVALID_OPERATION);
1667     ctx.glUniform4uiv(-1, 1, &data[0]);
1668     ctx.expectError(GL_INVALID_OPERATION);
1669     ctx.endSection();
1670 }
1671 
uniformuiv_incompatible_type(NegativeTestContext & ctx)1672 void uniformuiv_incompatible_type(NegativeTestContext &ctx)
1673 {
1674     glu::ShaderProgram program(ctx.getRenderContext(),
1675                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1676 
1677     ctx.glUseProgram(program.getProgram());
1678     GLint vec4_v    = ctx.glGetUniformLocation(program.getProgram(), "vec4_v");    // vec4
1679     GLint ivec4_f   = ctx.glGetUniformLocation(program.getProgram(), "ivec4_f");   // ivec4
1680     GLint uvec4_f   = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f");   // uvec4
1681     GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f"); // sampler2D
1682     ctx.expectError(GL_NO_ERROR);
1683 
1684     if (vec4_v == -1 || ivec4_f == -1 || uvec4_f == -1 || sampler_f == -1)
1685     {
1686         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1687         ctx.fail("Failed to retrieve uniform location");
1688     }
1689 
1690     std::vector<GLuint> data(4);
1691 
1692     ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader "
1693                      "does not match the size indicated by the ctx.glUniform command.");
1694     ctx.glUseProgram(program.getProgram());
1695     ctx.glUniform1uiv(uvec4_f, 1, &data[0]);
1696     ctx.expectError(GL_INVALID_OPERATION);
1697     ctx.glUniform2uiv(uvec4_f, 1, &data[0]);
1698     ctx.expectError(GL_INVALID_OPERATION);
1699     ctx.glUniform3uiv(uvec4_f, 1, &data[0]);
1700     ctx.expectError(GL_INVALID_OPERATION);
1701     ctx.glUniform4uiv(uvec4_f, 1, &data[0]);
1702     ctx.expectError(GL_NO_ERROR);
1703     ctx.endSection();
1704 
1705     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}uiv is used to load a uniform variable "
1706                      "of type float, vec2, vec3, or vec4.");
1707     ctx.glUseProgram(program.getProgram());
1708     ctx.glUniform1uiv(vec4_v, 1, &data[0]);
1709     ctx.expectError(GL_INVALID_OPERATION);
1710     ctx.glUniform2uiv(vec4_v, 1, &data[0]);
1711     ctx.expectError(GL_INVALID_OPERATION);
1712     ctx.glUniform3uiv(vec4_v, 1, &data[0]);
1713     ctx.expectError(GL_INVALID_OPERATION);
1714     ctx.glUniform4uiv(vec4_v, 1, &data[0]);
1715     ctx.expectError(GL_INVALID_OPERATION);
1716     ctx.endSection();
1717 
1718     ctx.beginSection("GL_INVALID_OPERATION is generated if ctx.glUniform{1234}uiv is used to load a uniform variable "
1719                      "of type int, ivec2, ivec3 or ivec4.");
1720     ctx.glUseProgram(program.getProgram());
1721     ctx.glUniform1uiv(ivec4_f, 1, &data[0]);
1722     ctx.expectError(GL_INVALID_OPERATION);
1723     ctx.glUniform2uiv(ivec4_f, 1, &data[0]);
1724     ctx.expectError(GL_INVALID_OPERATION);
1725     ctx.glUniform3uiv(ivec4_f, 1, &data[0]);
1726     ctx.expectError(GL_INVALID_OPERATION);
1727     ctx.glUniform4uiv(ivec4_f, 1, &data[0]);
1728     ctx.expectError(GL_INVALID_OPERATION);
1729     ctx.endSection();
1730 
1731     ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than "
1732                      "ctx.glUniform1i and ctx.glUniform1iv.");
1733     ctx.glUseProgram(program.getProgram());
1734     ctx.glUniform1uiv(sampler_f, 1, &data[0]);
1735     ctx.expectError(GL_INVALID_OPERATION);
1736     ctx.endSection();
1737 
1738     ctx.glUseProgram(0);
1739 }
1740 
uniformuiv_invalid_location(NegativeTestContext & ctx)1741 void uniformuiv_invalid_location(NegativeTestContext &ctx)
1742 {
1743     glu::ShaderProgram program(ctx.getRenderContext(),
1744                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1745 
1746     ctx.glUseProgram(program.getProgram());
1747     ctx.expectError(GL_NO_ERROR);
1748 
1749     std::vector<GLuint> data(4);
1750 
1751     ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current "
1752                      "program object and location is not equal to -1.");
1753     ctx.glUseProgram(program.getProgram());
1754     ctx.glUniform1uiv(-2, 1, &data[0]);
1755     ctx.expectError(GL_INVALID_OPERATION);
1756     ctx.glUniform2uiv(-2, 1, &data[0]);
1757     ctx.expectError(GL_INVALID_OPERATION);
1758     ctx.glUniform3uiv(-2, 1, &data[0]);
1759     ctx.expectError(GL_INVALID_OPERATION);
1760     ctx.glUniform4uiv(-2, 1, &data[0]);
1761     ctx.expectError(GL_INVALID_OPERATION);
1762 
1763     ctx.glUseProgram(program.getProgram());
1764     ctx.glUniform1uiv(-1, 1, &data[0]);
1765     ctx.expectError(GL_NO_ERROR);
1766     ctx.glUniform2uiv(-1, 1, &data[0]);
1767     ctx.expectError(GL_NO_ERROR);
1768     ctx.glUniform3uiv(-1, 1, &data[0]);
1769     ctx.expectError(GL_NO_ERROR);
1770     ctx.glUniform4uiv(-1, 1, &data[0]);
1771     ctx.expectError(GL_NO_ERROR);
1772     ctx.endSection();
1773 
1774     ctx.glUseProgram(0);
1775 }
1776 
uniformuiv_invalid_count(NegativeTestContext & ctx)1777 void uniformuiv_invalid_count(NegativeTestContext &ctx)
1778 {
1779     glu::ShaderProgram program(ctx.getRenderContext(),
1780                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1781 
1782     ctx.glUseProgram(program.getProgram());
1783     int uvec4_f = ctx.glGetUniformLocation(program.getProgram(), "uvec4_f"); // uvec4
1784     ctx.expectError(GL_NO_ERROR);
1785 
1786     if (uvec4_f == -1)
1787     {
1788         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1789         ctx.fail("Failed to retrieve uniform location");
1790     }
1791 
1792     std::vector<GLuint> data(8);
1793 
1794     ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable "
1795                      "is not an array variable.");
1796     ctx.glUseProgram(program.getProgram());
1797     ctx.glUniform1uiv(uvec4_f, 2, &data[0]);
1798     ctx.expectError(GL_INVALID_OPERATION);
1799     ctx.glUniform2uiv(uvec4_f, 2, &data[0]);
1800     ctx.expectError(GL_INVALID_OPERATION);
1801     ctx.glUniform3uiv(uvec4_f, 2, &data[0]);
1802     ctx.expectError(GL_INVALID_OPERATION);
1803     ctx.glUniform4uiv(uvec4_f, 2, &data[0]);
1804     ctx.expectError(GL_INVALID_OPERATION);
1805     ctx.endSection();
1806 
1807     ctx.glUseProgram(0);
1808 }
1809 
1810 // ctx.glUniformMatrix*fv
1811 
uniform_matrixfv_invalid_program(NegativeTestContext & ctx)1812 void uniform_matrixfv_invalid_program(NegativeTestContext &ctx)
1813 {
1814     std::vector<GLfloat> data(16);
1815 
1816     ctx.beginSection("GL_INVALID_OPERATION is generated if there is no current program object.");
1817     ctx.glUseProgram(0);
1818     ctx.glUniformMatrix2fv(-1, 1, GL_FALSE, &data[0]);
1819     ctx.expectError(GL_INVALID_OPERATION);
1820     ctx.glUniformMatrix3fv(-1, 1, GL_FALSE, &data[0]);
1821     ctx.expectError(GL_INVALID_OPERATION);
1822     ctx.glUniformMatrix4fv(-1, 1, GL_FALSE, &data[0]);
1823     ctx.expectError(GL_INVALID_OPERATION);
1824 
1825     ctx.glUniformMatrix2x3fv(-1, 1, GL_FALSE, &data[0]);
1826     ctx.expectError(GL_INVALID_OPERATION);
1827     ctx.glUniformMatrix3x2fv(-1, 1, GL_FALSE, &data[0]);
1828     ctx.expectError(GL_INVALID_OPERATION);
1829     ctx.glUniformMatrix2x4fv(-1, 1, GL_FALSE, &data[0]);
1830     ctx.expectError(GL_INVALID_OPERATION);
1831     ctx.glUniformMatrix4x2fv(-1, 1, GL_FALSE, &data[0]);
1832     ctx.expectError(GL_INVALID_OPERATION);
1833     ctx.glUniformMatrix3x4fv(-1, 1, GL_FALSE, &data[0]);
1834     ctx.expectError(GL_INVALID_OPERATION);
1835     ctx.glUniformMatrix4x3fv(-1, 1, GL_FALSE, &data[0]);
1836     ctx.expectError(GL_INVALID_OPERATION);
1837     ctx.endSection();
1838 }
1839 
uniform_matrixfv_incompatible_type(NegativeTestContext & ctx)1840 void uniform_matrixfv_incompatible_type(NegativeTestContext &ctx)
1841 {
1842     glu::ShaderProgram program(ctx.getRenderContext(),
1843                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1844 
1845     ctx.glUseProgram(program.getProgram());
1846     GLint mat4_v    = ctx.glGetUniformLocation(program.getProgram(), "mat4_v");    // mat4
1847     GLint sampler_f = ctx.glGetUniformLocation(program.getProgram(), "sampler_f"); // sampler2D
1848     ctx.expectError(GL_NO_ERROR);
1849 
1850     if (mat4_v == -1 || sampler_f == -1)
1851     {
1852         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1853         ctx.fail("Failed to retrieve uniform location");
1854     }
1855 
1856     std::vector<GLfloat> data(16);
1857 
1858     ctx.beginSection("GL_INVALID_OPERATION is generated if the size of the uniform variable declared in the shader "
1859                      "does not match the size indicated by the ctx.glUniform command.");
1860     ctx.glUseProgram(program.getProgram());
1861     ctx.glUniformMatrix2fv(mat4_v, 1, GL_FALSE, &data[0]);
1862     ctx.expectError(GL_INVALID_OPERATION);
1863     ctx.glUniformMatrix3fv(mat4_v, 1, GL_FALSE, &data[0]);
1864     ctx.expectError(GL_INVALID_OPERATION);
1865     ctx.glUniformMatrix4fv(mat4_v, 1, GL_FALSE, &data[0]);
1866     ctx.expectError(GL_NO_ERROR);
1867 
1868     ctx.glUniformMatrix2x3fv(mat4_v, 1, GL_FALSE, &data[0]);
1869     ctx.expectError(GL_INVALID_OPERATION);
1870     ctx.glUniformMatrix3x2fv(mat4_v, 1, GL_FALSE, &data[0]);
1871     ctx.expectError(GL_INVALID_OPERATION);
1872     ctx.glUniformMatrix2x4fv(mat4_v, 1, GL_FALSE, &data[0]);
1873     ctx.expectError(GL_INVALID_OPERATION);
1874     ctx.glUniformMatrix4x2fv(mat4_v, 1, GL_FALSE, &data[0]);
1875     ctx.expectError(GL_INVALID_OPERATION);
1876     ctx.glUniformMatrix3x4fv(mat4_v, 1, GL_FALSE, &data[0]);
1877     ctx.expectError(GL_INVALID_OPERATION);
1878     ctx.glUniformMatrix4x3fv(mat4_v, 1, GL_FALSE, &data[0]);
1879     ctx.expectError(GL_INVALID_OPERATION);
1880     ctx.endSection();
1881 
1882     ctx.beginSection("GL_INVALID_OPERATION is generated if a sampler is loaded using a command other than "
1883                      "ctx.glUniform1i and ctx.glUniform1iv.");
1884     ctx.glUseProgram(program.getProgram());
1885     ctx.glUniformMatrix2fv(sampler_f, 1, GL_FALSE, &data[0]);
1886     ctx.expectError(GL_INVALID_OPERATION);
1887     ctx.glUniformMatrix3fv(sampler_f, 1, GL_FALSE, &data[0]);
1888     ctx.expectError(GL_INVALID_OPERATION);
1889     ctx.glUniformMatrix4fv(sampler_f, 1, GL_FALSE, &data[0]);
1890     ctx.expectError(GL_INVALID_OPERATION);
1891 
1892     ctx.glUniformMatrix2x3fv(sampler_f, 1, GL_FALSE, &data[0]);
1893     ctx.expectError(GL_INVALID_OPERATION);
1894     ctx.glUniformMatrix3x2fv(sampler_f, 1, GL_FALSE, &data[0]);
1895     ctx.expectError(GL_INVALID_OPERATION);
1896     ctx.glUniformMatrix2x4fv(sampler_f, 1, GL_FALSE, &data[0]);
1897     ctx.expectError(GL_INVALID_OPERATION);
1898     ctx.glUniformMatrix4x2fv(sampler_f, 1, GL_FALSE, &data[0]);
1899     ctx.expectError(GL_INVALID_OPERATION);
1900     ctx.glUniformMatrix3x4fv(sampler_f, 1, GL_FALSE, &data[0]);
1901     ctx.expectError(GL_INVALID_OPERATION);
1902     ctx.glUniformMatrix4x3fv(sampler_f, 1, GL_FALSE, &data[0]);
1903     ctx.expectError(GL_INVALID_OPERATION);
1904     ctx.endSection();
1905 
1906     ctx.glUseProgram(0);
1907 }
1908 
uniform_matrixfv_invalid_location(NegativeTestContext & ctx)1909 void uniform_matrixfv_invalid_location(NegativeTestContext &ctx)
1910 {
1911     glu::ShaderProgram program(ctx.getRenderContext(),
1912                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1913 
1914     ctx.glUseProgram(program.getProgram());
1915     ctx.expectError(GL_NO_ERROR);
1916 
1917     std::vector<GLfloat> data(16);
1918 
1919     ctx.beginSection("GL_INVALID_OPERATION is generated if location is an invalid uniform location for the current "
1920                      "program object and location is not equal to -1.");
1921     ctx.glUseProgram(program.getProgram());
1922     ctx.glUniformMatrix2fv(-2, 1, GL_FALSE, &data[0]);
1923     ctx.expectError(GL_INVALID_OPERATION);
1924     ctx.glUniformMatrix3fv(-2, 1, GL_FALSE, &data[0]);
1925     ctx.expectError(GL_INVALID_OPERATION);
1926     ctx.glUniformMatrix4fv(-2, 1, GL_FALSE, &data[0]);
1927     ctx.expectError(GL_INVALID_OPERATION);
1928 
1929     ctx.glUniformMatrix2x3fv(-2, 1, GL_FALSE, &data[0]);
1930     ctx.expectError(GL_INVALID_OPERATION);
1931     ctx.glUniformMatrix3x2fv(-2, 1, GL_FALSE, &data[0]);
1932     ctx.expectError(GL_INVALID_OPERATION);
1933     ctx.glUniformMatrix2x4fv(-2, 1, GL_FALSE, &data[0]);
1934     ctx.expectError(GL_INVALID_OPERATION);
1935     ctx.glUniformMatrix4x2fv(-2, 1, GL_FALSE, &data[0]);
1936     ctx.expectError(GL_INVALID_OPERATION);
1937     ctx.glUniformMatrix3x4fv(-2, 1, GL_FALSE, &data[0]);
1938     ctx.expectError(GL_INVALID_OPERATION);
1939     ctx.glUniformMatrix4x3fv(-2, 1, GL_FALSE, &data[0]);
1940     ctx.expectError(GL_INVALID_OPERATION);
1941 
1942     ctx.glUseProgram(program.getProgram());
1943     ctx.glUniformMatrix2fv(-1, 1, GL_FALSE, &data[0]);
1944     ctx.expectError(GL_NO_ERROR);
1945     ctx.glUniformMatrix3fv(-1, 1, GL_FALSE, &data[0]);
1946     ctx.expectError(GL_NO_ERROR);
1947     ctx.glUniformMatrix4fv(-1, 1, GL_FALSE, &data[0]);
1948     ctx.expectError(GL_NO_ERROR);
1949 
1950     ctx.glUniformMatrix2x3fv(-1, 1, GL_FALSE, &data[0]);
1951     ctx.expectError(GL_NO_ERROR);
1952     ctx.glUniformMatrix3x2fv(-1, 1, GL_FALSE, &data[0]);
1953     ctx.expectError(GL_NO_ERROR);
1954     ctx.glUniformMatrix2x4fv(-1, 1, GL_FALSE, &data[0]);
1955     ctx.expectError(GL_NO_ERROR);
1956     ctx.glUniformMatrix4x2fv(-1, 1, GL_FALSE, &data[0]);
1957     ctx.expectError(GL_NO_ERROR);
1958     ctx.glUniformMatrix3x4fv(-1, 1, GL_FALSE, &data[0]);
1959     ctx.expectError(GL_NO_ERROR);
1960     ctx.glUniformMatrix4x3fv(-1, 1, GL_FALSE, &data[0]);
1961     ctx.expectError(GL_NO_ERROR);
1962     ctx.endSection();
1963 
1964     ctx.glUseProgram(0);
1965 }
1966 
uniform_matrixfv_invalid_count(NegativeTestContext & ctx)1967 void uniform_matrixfv_invalid_count(NegativeTestContext &ctx)
1968 {
1969     glu::ShaderProgram program(ctx.getRenderContext(),
1970                                glu::makeVtxFragSources(uniformTestVertSource, uniformTestFragSource));
1971 
1972     ctx.glUseProgram(program.getProgram());
1973     GLint mat4_v = ctx.glGetUniformLocation(program.getProgram(), "mat4_v"); // mat4
1974     ctx.expectError(GL_NO_ERROR);
1975 
1976     if (mat4_v == -1)
1977     {
1978         ctx.getLog() << TestLog::Message << "// ERROR: Failed to retrieve uniform location" << TestLog::EndMessage;
1979         ctx.fail("Failed to retrieve uniform location");
1980     }
1981 
1982     std::vector<GLfloat> data(32);
1983 
1984     ctx.beginSection("GL_INVALID_OPERATION is generated if count is greater than 1 and the indicated uniform variable "
1985                      "is not an array variable.");
1986     ctx.glUseProgram(program.getProgram());
1987     ctx.glUniformMatrix2fv(mat4_v, 2, GL_FALSE, &data[0]);
1988     ctx.expectError(GL_INVALID_OPERATION);
1989     ctx.glUniformMatrix3fv(mat4_v, 2, GL_FALSE, &data[0]);
1990     ctx.expectError(GL_INVALID_OPERATION);
1991     ctx.glUniformMatrix4fv(mat4_v, 2, GL_FALSE, &data[0]);
1992     ctx.expectError(GL_INVALID_OPERATION);
1993 
1994     ctx.glUniformMatrix2x3fv(mat4_v, 1, GL_FALSE, &data[0]);
1995     ctx.expectError(GL_INVALID_OPERATION);
1996     ctx.glUniformMatrix3x2fv(mat4_v, 1, GL_FALSE, &data[0]);
1997     ctx.expectError(GL_INVALID_OPERATION);
1998     ctx.glUniformMatrix2x4fv(mat4_v, 1, GL_FALSE, &data[0]);
1999     ctx.expectError(GL_INVALID_OPERATION);
2000     ctx.glUniformMatrix4x2fv(mat4_v, 1, GL_FALSE, &data[0]);
2001     ctx.expectError(GL_INVALID_OPERATION);
2002     ctx.glUniformMatrix3x4fv(mat4_v, 1, GL_FALSE, &data[0]);
2003     ctx.expectError(GL_INVALID_OPERATION);
2004     ctx.glUniformMatrix4x3fv(mat4_v, 1, GL_FALSE, &data[0]);
2005     ctx.expectError(GL_INVALID_OPERATION);
2006     ctx.endSection();
2007 
2008     ctx.glUseProgram(0);
2009 }
2010 
2011 // Transform feedback
gen_transform_feedbacks(NegativeTestContext & ctx)2012 void gen_transform_feedbacks(NegativeTestContext &ctx)
2013 {
2014     ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
2015     GLuint id = 0;
2016     ctx.glGenTransformFeedbacks(-1, &id);
2017     ctx.expectError(GL_INVALID_VALUE);
2018     ctx.endSection();
2019 }
2020 
bind_transform_feedback(NegativeTestContext & ctx)2021 void bind_transform_feedback(NegativeTestContext &ctx)
2022 {
2023     GLuint tfID[2];
2024     glu::ShaderProgram program(ctx.getRenderContext(),
2025                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2026     uint32_t buf          = 0x1234;
2027     const char *tfVarying = "gl_Position";
2028 
2029     ctx.glGenBuffers(1, &buf);
2030     ctx.glGenTransformFeedbacks(2, tfID);
2031 
2032     ctx.beginSection("GL_INVALID_ENUM is generated if target is not GL_TRANSFORM_FEEDBACK.");
2033     ctx.glBindTransformFeedback(-1, tfID[0]);
2034     ctx.expectError(GL_INVALID_ENUM);
2035     ctx.endSection();
2036 
2037     ctx.beginSection("GL_INVALID_OPERATION is generated if the transform feedback operation is active on the currently "
2038                      "bound transform feedback object, and is not paused.");
2039     ctx.glUseProgram(program.getProgram());
2040     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2041     ctx.glLinkProgram(program.getProgram());
2042     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[0]);
2043     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
2044     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
2045     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
2046     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2047     ctx.expectError(GL_NO_ERROR);
2048 
2049     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[1]);
2050     ctx.expectError(GL_INVALID_OPERATION);
2051 
2052     ctx.glEndTransformFeedback();
2053     ctx.expectError(GL_NO_ERROR);
2054     ctx.endSection();
2055 
2056     ctx.glUseProgram(0);
2057     ctx.glDeleteBuffers(1, &buf);
2058     ctx.glDeleteTransformFeedbacks(2, tfID);
2059     ctx.expectError(GL_NO_ERROR);
2060 
2061     ctx.beginSection("GL_INVALID_OPERATION is generated if id has been deleted with glDeleteTransformFeedback().");
2062     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[0]);
2063     ctx.expectError(GL_INVALID_OPERATION);
2064     ctx.endSection();
2065 
2066     ctx.beginSection(
2067         "GL_INVALID_OPERATION is generated if id is not 0 or a value returned from glGenTransformFeedbacks().");
2068     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, -1);
2069     ctx.expectError(GL_INVALID_OPERATION);
2070     ctx.endSection();
2071 }
2072 
delete_transform_feedbacks(NegativeTestContext & ctx)2073 void delete_transform_feedbacks(NegativeTestContext &ctx)
2074 {
2075     GLuint id = 0;
2076     GLuint tfID[2];
2077     uint32_t buf          = 0x1234;
2078     const char *tfVarying = "gl_Position";
2079     glu::ShaderProgram program(ctx.getRenderContext(),
2080                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2081 
2082     ctx.glGenBuffers(1, &buf);
2083     ctx.glGenTransformFeedbacks(1, &id);
2084     ctx.glGenTransformFeedbacks(2, tfID);
2085 
2086     ctx.beginSection("GL_INVALID_VALUE is generated if n is negative.");
2087     ctx.glDeleteTransformFeedbacks(-1, &id);
2088     ctx.expectError(GL_INVALID_VALUE);
2089     ctx.endSection();
2090 
2091     ctx.beginSection("GL_INVALID_OPERATION is generated if the transform feedback operation for any object named by "
2092                      "ids is currently active.");
2093     ctx.glUseProgram(program.getProgram());
2094     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2095     ctx.glLinkProgram(program.getProgram());
2096     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[0]);
2097     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
2098     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
2099     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
2100     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2101     ctx.expectError(GL_NO_ERROR);
2102 
2103     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[1]);
2104     ctx.expectError(GL_INVALID_OPERATION);
2105 
2106     ctx.glDeleteTransformFeedbacks(2, tfID);
2107     ctx.expectError(GL_INVALID_OPERATION);
2108 
2109     ctx.glEndTransformFeedback();
2110     ctx.expectError(GL_NO_ERROR);
2111     ctx.endSection();
2112 
2113     ctx.glDeleteTransformFeedbacks(1, &id);
2114     ctx.glDeleteTransformFeedbacks(2, tfID);
2115     ctx.glDeleteBuffers(1, &buf);
2116 }
2117 
begin_transform_feedback(NegativeTestContext & ctx)2118 void begin_transform_feedback(NegativeTestContext &ctx)
2119 {
2120     GLuint tfID[2];
2121     glu::ShaderProgram program(ctx.getRenderContext(),
2122                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2123     uint32_t buf          = 0x1234;
2124     const char *tfVarying = "gl_Position";
2125 
2126     ctx.glGenBuffers(1, &buf);
2127     ctx.glGenTransformFeedbacks(2, tfID);
2128 
2129     ctx.glUseProgram(program.getProgram());
2130     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2131     ctx.glLinkProgram(program.getProgram());
2132     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[0]);
2133     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
2134     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
2135     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
2136     ctx.expectError(GL_NO_ERROR);
2137 
2138     ctx.beginSection(
2139         "GL_INVALID_ENUM is generated if primitiveMode is not one of GL_POINTS, GL_LINES, or GL_TRIANGLES.");
2140     ctx.glBeginTransformFeedback(-1);
2141     ctx.expectError(GL_INVALID_ENUM);
2142     ctx.endSection();
2143 
2144     ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is already active.");
2145     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2146     ctx.expectError(GL_NO_ERROR);
2147     ctx.glBeginTransformFeedback(GL_POINTS);
2148     ctx.expectError(GL_INVALID_OPERATION);
2149     ctx.endSection();
2150 
2151     ctx.beginSection("GL_INVALID_OPERATION is generated if any binding point used in transform feedback mode does not "
2152                      "have a buffer object bound.");
2153     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
2154     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2155     ctx.expectError(GL_INVALID_OPERATION);
2156     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
2157     ctx.endSection();
2158 
2159     ctx.beginSection(
2160         "GL_INVALID_OPERATION is generated if no binding points would be used because no program object is active.");
2161     ctx.glUseProgram(0);
2162     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2163     ctx.expectError(GL_INVALID_OPERATION);
2164     ctx.glUseProgram(program.getProgram());
2165     ctx.endSection();
2166 
2167     ctx.beginSection("GL_INVALID_OPERATION is generated if no binding points would be used because the active program "
2168                      "object has specified no varying variables to record.");
2169     ctx.glTransformFeedbackVaryings(program.getProgram(), 0, 0, GL_INTERLEAVED_ATTRIBS);
2170     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2171     ctx.expectError(GL_INVALID_OPERATION);
2172     ctx.endSection();
2173 
2174     ctx.glEndTransformFeedback();
2175     ctx.glDeleteBuffers(1, &buf);
2176     ctx.glDeleteTransformFeedbacks(2, tfID);
2177     ctx.expectError(GL_NO_ERROR);
2178 }
2179 
pause_transform_feedback(NegativeTestContext & ctx)2180 void pause_transform_feedback(NegativeTestContext &ctx)
2181 {
2182     GLuint tfID[2];
2183     glu::ShaderProgram program(ctx.getRenderContext(),
2184                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2185     uint32_t buf          = 0x1234;
2186     const char *tfVarying = "gl_Position";
2187 
2188     ctx.glGenBuffers(1, &buf);
2189     ctx.glGenTransformFeedbacks(2, tfID);
2190 
2191     ctx.glUseProgram(program.getProgram());
2192     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2193     ctx.glLinkProgram(program.getProgram());
2194     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[0]);
2195     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
2196     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
2197     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
2198     ctx.expectError(GL_NO_ERROR);
2199 
2200     ctx.beginSection("GL_INVALID_OPERATION is generated if the currently bound transform feedback object is not active "
2201                      "or is paused.");
2202     ctx.glPauseTransformFeedback();
2203     ctx.expectError(GL_INVALID_OPERATION);
2204     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2205     ctx.glPauseTransformFeedback();
2206     ctx.expectError(GL_NO_ERROR);
2207     ctx.glPauseTransformFeedback();
2208     ctx.expectError(GL_INVALID_OPERATION);
2209     ctx.endSection();
2210 
2211     ctx.glEndTransformFeedback();
2212     ctx.glDeleteBuffers(1, &buf);
2213     ctx.glDeleteTransformFeedbacks(2, tfID);
2214     ctx.expectError(GL_NO_ERROR);
2215 }
2216 
resume_transform_feedback(NegativeTestContext & ctx)2217 void resume_transform_feedback(NegativeTestContext &ctx)
2218 {
2219     GLuint tfID[2];
2220     glu::ShaderProgram program(ctx.getRenderContext(),
2221                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2222     uint32_t buf          = 0x1234;
2223     const char *tfVarying = "gl_Position";
2224 
2225     ctx.glGenBuffers(1, &buf);
2226     ctx.glGenTransformFeedbacks(2, tfID);
2227 
2228     ctx.glUseProgram(program.getProgram());
2229     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2230     ctx.glLinkProgram(program.getProgram());
2231     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID[0]);
2232     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
2233     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
2234     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
2235     ctx.expectError(GL_NO_ERROR);
2236 
2237     ctx.beginSection("GL_INVALID_OPERATION is generated if the currently bound transform feedback object is not active "
2238                      "or is not paused.");
2239     ctx.glResumeTransformFeedback();
2240     ctx.expectError(GL_INVALID_OPERATION);
2241     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2242     ctx.glResumeTransformFeedback();
2243     ctx.expectError(GL_INVALID_OPERATION);
2244     ctx.glPauseTransformFeedback();
2245     ctx.glResumeTransformFeedback();
2246     ctx.expectError(GL_NO_ERROR);
2247     ctx.endSection();
2248 
2249     ctx.glEndTransformFeedback();
2250     ctx.glDeleteBuffers(1, &buf);
2251     ctx.glDeleteTransformFeedbacks(2, tfID);
2252     ctx.expectError(GL_NO_ERROR);
2253 }
2254 
end_transform_feedback(NegativeTestContext & ctx)2255 void end_transform_feedback(NegativeTestContext &ctx)
2256 {
2257     GLuint tfID = 0;
2258     glu::ShaderProgram program(ctx.getRenderContext(),
2259                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2260     uint32_t buf          = 0x1234;
2261     const char *tfVarying = "gl_Position";
2262 
2263     ctx.glGenBuffers(1, &buf);
2264     ctx.glGenTransformFeedbacks(1, &tfID);
2265 
2266     ctx.glUseProgram(program.getProgram());
2267     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2268     ctx.glLinkProgram(program.getProgram());
2269     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
2270     ctx.glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buf);
2271     ctx.glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 32, DE_NULL, GL_DYNAMIC_DRAW);
2272     ctx.glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buf);
2273     ctx.expectError(GL_NO_ERROR);
2274 
2275     ctx.beginSection("GL_INVALID_OPERATION is generated if transform feedback is not active.");
2276     ctx.glEndTransformFeedback();
2277     ctx.expectError(GL_INVALID_OPERATION);
2278     ctx.glBeginTransformFeedback(GL_TRIANGLES);
2279     ctx.glEndTransformFeedback();
2280     ctx.expectError(GL_NO_ERROR);
2281     ctx.endSection();
2282 
2283     ctx.glDeleteBuffers(1, &buf);
2284     ctx.glDeleteTransformFeedbacks(1, &tfID);
2285     ctx.expectError(GL_NO_ERROR);
2286 }
2287 
get_transform_feedback_varying(NegativeTestContext & ctx)2288 void get_transform_feedback_varying(NegativeTestContext &ctx)
2289 {
2290     GLuint tfID = 0;
2291     glu::ShaderProgram program(ctx.getRenderContext(),
2292                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2293     glu::ShaderProgram programInvalid(ctx.getRenderContext(), glu::makeVtxFragSources(vertexShaderSource, ""));
2294     const char *tfVarying            = "gl_Position";
2295     int maxTransformFeedbackVaryings = 0;
2296 
2297     GLsizei length;
2298     GLsizei size;
2299     GLenum type;
2300     char name[32];
2301 
2302     const GLuint notAProgram = ctx.glCreateProgram();
2303     ctx.glDeleteProgram(notAProgram);
2304 
2305     ctx.glGenTransformFeedbacks(1, &tfID);
2306 
2307     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2308     ctx.expectError(GL_NO_ERROR);
2309     ctx.glLinkProgram(program.getProgram());
2310     ctx.expectError(GL_NO_ERROR);
2311 
2312     ctx.glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfID);
2313     ctx.expectError(GL_NO_ERROR);
2314 
2315     ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of a program object.");
2316     ctx.glGetTransformFeedbackVarying(notAProgram, 0, 32, &length, &size, &type, &name[0]);
2317     ctx.expectError(GL_INVALID_VALUE);
2318     ctx.endSection();
2319 
2320     ctx.beginSection(
2321         "GL_INVALID_VALUE is generated if index is greater or equal to the value of GL_TRANSFORM_FEEDBACK_VARYINGS.");
2322     ctx.glGetProgramiv(program.getProgram(), GL_TRANSFORM_FEEDBACK_VARYINGS, &maxTransformFeedbackVaryings);
2323     ctx.glGetTransformFeedbackVarying(program.getProgram(), maxTransformFeedbackVaryings, 32, &length, &size, &type,
2324                                       &name[0]);
2325     ctx.expectError(GL_INVALID_VALUE);
2326     ctx.endSection();
2327 
2328     ctx.beginSection("GL_INVALID_OPERATION or GL_INVALID_VALUE is generated program has not been linked.");
2329     ctx.glGetTransformFeedbackVarying(programInvalid.getProgram(), 0, 32, &length, &size, &type, &name[0]);
2330     ctx.expectError(GL_INVALID_OPERATION, GL_INVALID_VALUE);
2331     ctx.endSection();
2332 
2333     ctx.glDeleteTransformFeedbacks(1, &tfID);
2334     ctx.expectError(GL_NO_ERROR);
2335 }
2336 
transform_feedback_varyings(NegativeTestContext & ctx)2337 void transform_feedback_varyings(NegativeTestContext &ctx)
2338 {
2339     GLuint tfID   = 0;
2340     GLuint shader = ctx.glCreateShader(GL_VERTEX_SHADER);
2341     glu::ShaderProgram program(ctx.getRenderContext(),
2342                                glu::makeVtxFragSources(vertexShaderSource, fragmentShaderSource));
2343     const char *tfVarying                     = "gl_Position";
2344     GLint maxTransformFeedbackSeparateAttribs = 0;
2345 
2346     const GLuint notAProgram = ctx.glCreateProgram();
2347     ctx.glDeleteProgram(notAProgram);
2348 
2349     ctx.glGenTransformFeedbacks(1, &tfID);
2350     ctx.expectError(GL_NO_ERROR);
2351 
2352     ctx.beginSection("GL_INVALID_VALUE is generated if program is not the name of a program object.");
2353     ctx.glTransformFeedbackVaryings(notAProgram, 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2354     ctx.expectError(GL_INVALID_VALUE);
2355     ctx.endSection();
2356 
2357     ctx.beginSection("GL_INVALID_OPERATION is generated if program is the name of a shader object.");
2358     ctx.glTransformFeedbackVaryings(shader, 1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2359     ctx.expectError(GL_INVALID_OPERATION);
2360     ctx.glDeleteShader(shader);
2361     ctx.endSection();
2362 
2363     ctx.beginSection("GL_INVALID_VALUE is generated if count is negative.");
2364     ctx.glTransformFeedbackVaryings(program.getProgram(), -1, &tfVarying, GL_INTERLEAVED_ATTRIBS);
2365     ctx.expectError(GL_INVALID_VALUE);
2366     ctx.endSection();
2367 
2368     ctx.beginSection("GL_INVALID_ENUM is generated if bufferMode is not SEPARATE_ATTRIBS or INTERLEAVED_ATTRIBS.");
2369     ctx.glTransformFeedbackVaryings(program.getProgram(), 1, &tfVarying, 0);
2370     ctx.expectError(GL_INVALID_ENUM);
2371     ctx.endSection();
2372 
2373     ctx.beginSection("GL_INVALID_VALUE is generated if bufferMode is GL_SEPARATE_ATTRIBS and count is greater than "
2374                      "GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS.");
2375     ctx.glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &maxTransformFeedbackSeparateAttribs);
2376     ctx.glTransformFeedbackVaryings(program.getProgram(), maxTransformFeedbackSeparateAttribs + 1, &tfVarying,
2377                                     GL_SEPARATE_ATTRIBS);
2378     ctx.expectError(GL_INVALID_VALUE);
2379     ctx.endSection();
2380 
2381     ctx.glDeleteTransformFeedbacks(1, &tfID);
2382     ctx.expectError(GL_NO_ERROR);
2383 }
2384 
link_compute_shader(NegativeTestContext & ctx)2385 void link_compute_shader(NegativeTestContext &ctx)
2386 {
2387     const char *computeShaderSource = "#version 320 es\n"
2388                                       "void main (void)\n"
2389                                       "{\n"
2390                                       "}\n\0";
2391     {
2392         const GLenum shaderTypes[] = {GL_VERTEX_SHADER, GL_FRAGMENT_SHADER, GL_GEOMETRY_SHADER, GL_TESS_CONTROL_SHADER,
2393                                       GL_TESS_EVALUATION_SHADER};
2394 
2395         ctx.beginSection("Compute Shader linked with shader of other kind.");
2396         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(shaderTypes); ndx++)
2397         {
2398             GLint linkStatus              = -1;
2399             GLuint program                = ctx.glCreateProgram();
2400             GLuint computeShader          = ctx.glCreateShader(GL_COMPUTE_SHADER);
2401             GLuint otherShader            = ctx.glCreateShader(shaderTypes[ndx]);
2402             const char *otherShaderSource = (shaderTypes[ndx] != GL_GEOMETRY_SHADER) ? computeShaderSource :
2403                                                                                        "#version 320 es\n"
2404                                                                                        "layout(max_vertices = 3) out;\n"
2405                                                                                        "void main(void){}\n\0";
2406 
2407             ctx.glShaderSource(computeShader, 1, &computeShaderSource, DE_NULL);
2408             ctx.glShaderSource(otherShader, 1, &otherShaderSource, DE_NULL);
2409             ctx.glCompileShader(computeShader);
2410             ctx.glCompileShader(otherShader);
2411             ctx.glAttachShader(program, computeShader);
2412             ctx.glAttachShader(program, otherShader);
2413             ctx.glLinkProgram(program);
2414             ctx.glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
2415             ctx.glDeleteShader(otherShader);
2416             ctx.glDeleteShader(computeShader);
2417             ctx.glDeleteProgram(program);
2418             if (linkStatus != GL_FALSE)
2419                 ctx.fail("Program should not have linked");
2420         }
2421         ctx.endSection();
2422     }
2423     {
2424         const char *computeShaderSource310 = "#version 310 es\n"
2425                                              "void main (void)\n"
2426                                              "{\n"
2427                                              "}\n\0";
2428         GLint linkStatus                   = -1;
2429         GLuint program                     = ctx.glCreateProgram();
2430         GLuint computeShader               = ctx.glCreateShader(GL_COMPUTE_SHADER);
2431         GLuint computeShader310            = ctx.glCreateShader(GL_FRAGMENT_SHADER);
2432 
2433         ctx.glShaderSource(computeShader, 1, &computeShaderSource, DE_NULL);
2434         ctx.glShaderSource(computeShader310, 1, &computeShaderSource310, DE_NULL);
2435         ctx.beginSection("Compute Shader should not be linked with shaders of different version.");
2436         ctx.glCompileShader(computeShader);
2437         ctx.glCompileShader(computeShader310);
2438         ctx.glAttachShader(program, computeShader);
2439         ctx.glAttachShader(program, computeShader310);
2440         ctx.glLinkProgram(program);
2441         ctx.glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
2442         ctx.glDeleteShader(computeShader310);
2443         ctx.glDeleteShader(computeShader);
2444         ctx.glDeleteProgram(program);
2445         if (linkStatus != GL_FALSE)
2446             ctx.fail("Program should not have linked");
2447         ctx.endSection();
2448     }
2449 }
2450 
compile_compute_shader_helper(NegativeTestContext & ctx,const char * const * computeShaderSource,GLint * compileStatus)2451 void compile_compute_shader_helper(NegativeTestContext &ctx, const char *const *computeShaderSource,
2452                                    GLint *compileStatus)
2453 {
2454     GLuint shader = ctx.glCreateShader(GL_COMPUTE_SHADER);
2455 
2456     *compileStatus = -1;
2457     ctx.glShaderSource(shader, 1, computeShaderSource, DE_NULL);
2458     ctx.glCompileShader(shader);
2459     ctx.glGetShaderiv(shader, GL_COMPILE_STATUS, compileStatus);
2460     ctx.glDeleteShader(shader);
2461 }
2462 
compile_compute_shader(NegativeTestContext & ctx)2463 void compile_compute_shader(NegativeTestContext &ctx)
2464 {
2465     GLint compileStatus;
2466     ctx.beginSection("Compile Computer Shader");
2467 
2468     {
2469         const char *const computeShaderSource = "#version 300 es\n"
2470                                                 "void main (void)\n"
2471                                                 "{\n"
2472                                                 "}\n";
2473 
2474         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2475         if (compileStatus != GL_FALSE)
2476             ctx.fail("Compute Shader should not have compiled with #version 300 es.");
2477     }
2478     {
2479         const char *const computeShaderSource = "#version 310 es\n"
2480                                                 "buffer SSBO { vec4 data }"
2481                                                 "void main (void)\n"
2482                                                 "{\n"
2483                                                 "}\n";
2484 
2485         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2486         if (compileStatus != GL_FALSE)
2487             ctx.fail("Compute Shader should not have compiled: incorrect SSBO syntax.");
2488     }
2489     {
2490         const char *const computeShaderSource = "#version 310 es\n"
2491                                                 "buffer SSBO { vec4 data;};"
2492                                                 "uniform mat4 data;"
2493                                                 "void main (void)\n"
2494                                                 "{\n"
2495                                                 "}\n";
2496 
2497         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2498         if (compileStatus != GL_FALSE)
2499             ctx.fail("Compute Shader should not have compiled: buffer variable redefinition.");
2500     }
2501     {
2502         const char *const computeShaderSource = "#version 310 es\n"
2503                                                 "buffer SSBO { vec4 data[]; vec4 moreData;};"
2504                                                 "void main (void)\n"
2505                                                 "{\n"
2506                                                 "}\n";
2507 
2508         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2509         if (compileStatus != GL_FALSE)
2510             ctx.fail("Compute Shader should not have compiled: unspecified length buffer member not at the end.");
2511     }
2512     {
2513         const char *const computeShaderSource = "#version 310 es\n"
2514                                                 "in vec4 data;"
2515                                                 "void main (void)\n"
2516                                                 "{\n"
2517                                                 "}\n";
2518 
2519         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2520         if (compileStatus != GL_FALSE)
2521             ctx.fail("Compute Shader should not have compiled: input qualifier used.");
2522     }
2523     {
2524         const char *const computeShaderSource = "#version 310 es\n"
2525                                                 "shared uint data = 0;";
2526 
2527         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2528         if (compileStatus != GL_FALSE)
2529             ctx.fail("Compute Shader should not have compiled: shared-qualified variable initialized.");
2530     }
2531     {
2532         const char *const computeShaderSource = "#version 310 es\n"
2533                                                 "buffer SSBO { vec4 data; vec4 moreData[];} ssbo;"
2534                                                 "void test (vec4 data[10]) {}"
2535                                                 "void main (void)\n"
2536                                                 "{\n"
2537                                                 "    test(ssbo.moreData);"
2538                                                 "}\n";
2539 
2540         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2541         if (compileStatus != GL_FALSE)
2542             ctx.fail("Compute Shader should not have compiled: unspecified length buffer member passed as argument to "
2543                      "function.");
2544     }
2545     {
2546         const char *const computeShaderSource = "#version 310 es\n"
2547                                                 "buffer SSBO { vec4 data; vec4 moreData[];} ssbo;"
2548                                                 "void main (void)\n"
2549                                                 "{\n"
2550                                                 "    vec4 var = ssbo.moreData[-1];"
2551                                                 "}\n";
2552 
2553         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2554         if (compileStatus != GL_FALSE)
2555             ctx.fail("Compute Shader should not have compiled: unspecified length buffer member indexed with negative "
2556                      "constant expression.");
2557     }
2558     {
2559         const char *const computeShaderSource = "#version 310 es\n"
2560                                                 "layout(binding=-1) buffer SSBO { vec4 data;};"
2561                                                 "void main (void)\n"
2562                                                 "{\n"
2563                                                 "}\n";
2564 
2565         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2566         if (compileStatus != GL_FALSE)
2567             ctx.fail("Compute Shader should not have compiled: binding point less than zero.");
2568     }
2569     {
2570         const char *const computeShaderSource = "#version 310 es\n"
2571                                                 "layout(binding=1) buffer;"
2572                                                 "layout(binding=2) buffer SSBO { vec4 data;};"
2573                                                 "void main (void)\n"
2574                                                 "{\n"
2575                                                 "}\n";
2576 
2577         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2578         if (compileStatus != GL_FALSE)
2579             ctx.fail("Compute Shader should not have compiled: binding point specified for global scope.");
2580     }
2581     {
2582         const char *const computeShaderSource = "#version 310 es\n"
2583                                                 "buffer SSBO {"
2584                                                 "    layout(binding=1) vec4 data;"
2585                                                 "    layout(binding=2) vec4 moreData[];"
2586                                                 "} ssbo;"
2587                                                 "void main (void)\n"
2588                                                 "{\n"
2589                                                 "}\n";
2590 
2591         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2592         if (compileStatus != GL_FALSE)
2593             ctx.fail("Compute Shader should not have compiled: binding point specified for block member declarations.");
2594     }
2595     {
2596         const char *const computeShaderSource = "#version 310 es\n"
2597                                                 "readonly buffer SSBO {vec4 data;} ssbo;"
2598                                                 "void main (void)\n"
2599                                                 "{\n"
2600                                                 "ssbo.data = vec4(1, 1, 1, 1);"
2601                                                 "}\n";
2602 
2603         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2604         if (compileStatus != GL_FALSE)
2605             ctx.fail("Compute Shader should not have compiled: writing to buffer block qualified with readonly.");
2606     }
2607     {
2608         const char *const computeShaderSource = "#version 310 es\n"
2609                                                 "writeonly buffer SSBO {vec4 data;} ssbo;"
2610                                                 "void main (void)\n"
2611                                                 "{\n"
2612                                                 "vec4 var = ssbo.data;"
2613                                                 "}\n";
2614 
2615         compile_compute_shader_helper(ctx, &computeShaderSource, &compileStatus);
2616         if (compileStatus != GL_FALSE)
2617             ctx.fail("Compute Shader should not have compiled: reading from buffer block qualified with writeonly.");
2618     }
2619 
2620     ctx.endSection();
2621 }
2622 
srgb_decode_samplerparameteri(NegativeTestContext & ctx)2623 void srgb_decode_samplerparameteri(NegativeTestContext &ctx)
2624 {
2625     if (!ctx.isExtensionSupported("GL_EXT_texture_sRGB_decode"))
2626         TCU_THROW(NotSupportedError, "GL_EXT_texture_sRGB_decode is not supported.");
2627 
2628     GLuint sampler    = 0x1234;
2629     GLint samplerMode = -1;
2630 
2631     ctx.glGenSamplers(1, &sampler);
2632 
2633     ctx.beginSection("GL_INVALID_ENUM is generated if pname is GL_TEXTURE_SRGB_DECODE_EXT and the value of param(s) is "
2634                      "not a valid value (one of DECODE_EXT, or SKIP_DECODE_EXT).");
2635     ctx.glSamplerParameteri(sampler, GL_TEXTURE_SRGB_DECODE_EXT, samplerMode);
2636     ctx.expectError(GL_INVALID_ENUM);
2637     ctx.endSection();
2638 
2639     ctx.glDeleteSamplers(1, &sampler);
2640 }
2641 
srgb_decode_samplerparameterf(NegativeTestContext & ctx)2642 void srgb_decode_samplerparameterf(NegativeTestContext &ctx)
2643 {
2644     if (!ctx.isExtensionSupported("GL_EXT_texture_sRGB_decode"))
2645         TCU_THROW(NotSupportedError, "GL_EXT_texture_sRGB_decode is not supported.");
2646 
2647     GLuint sampler      = 0x1234;
2648     GLfloat samplerMode = -1.0f;
2649 
2650     ctx.glGenSamplers(1, &sampler);
2651 
2652     ctx.beginSection("GL_INVALID_ENUM is generated if pname is GL_TEXTURE_SRGB_DECODE_EXT and the value of param(s) is "
2653                      "not a valid value (one of DECODE_EXT, or SKIP_DECODE_EXT).");
2654     ctx.glSamplerParameterf(sampler, GL_TEXTURE_SRGB_DECODE_EXT, samplerMode);
2655     ctx.expectError(GL_INVALID_ENUM);
2656     ctx.endSection();
2657 
2658     ctx.glDeleteSamplers(1, &sampler);
2659 }
2660 
srgb_decode_samplerparameteriv(NegativeTestContext & ctx)2661 void srgb_decode_samplerparameteriv(NegativeTestContext &ctx)
2662 {
2663     if (!ctx.isExtensionSupported("GL_EXT_texture_sRGB_decode"))
2664         TCU_THROW(NotSupportedError, "GL_EXT_texture_sRGB_decode is not supported.");
2665 
2666     int params[1]  = {GL_LINEAR};
2667     GLuint sampler = 0x1234;
2668 
2669     ctx.glGenSamplers(1, &sampler);
2670 
2671     ctx.beginSection("GL_INVALID_ENUM is generated if pname is GL_TEXTURE_SRGB_DECODE_EXT and the value of param(s) is "
2672                      "not a valid value (one of DECODE_EXT, or SKIP_DECODE_EXT).");
2673     params[0] = -1;
2674     ctx.glSamplerParameteriv(sampler, GL_TEXTURE_SRGB_DECODE_EXT, &params[0]);
2675     ctx.expectError(GL_INVALID_ENUM);
2676     ctx.endSection();
2677 
2678     ctx.glDeleteSamplers(1, &sampler);
2679 }
2680 
srgb_decode_samplerparameterfv(NegativeTestContext & ctx)2681 void srgb_decode_samplerparameterfv(NegativeTestContext &ctx)
2682 {
2683     if (!ctx.isExtensionSupported("GL_EXT_texture_sRGB_decode"))
2684         TCU_THROW(NotSupportedError, "GL_EXT_texture_sRGB_decode is not supported.");
2685 
2686     float params[1] = {GL_LINEAR};
2687     GLuint sampler  = 0x1234;
2688 
2689     ctx.glGenSamplers(1, &sampler);
2690 
2691     params[0] = -1.0f;
2692     ctx.beginSection("GL_INVALID_ENUM is generated if pname is GL_TEXTURE_SRGB_DECODE_EXT and the value of param(s) is "
2693                      "not a valid value (one of DECODE_EXT, or SKIP_DECODE_EXT).");
2694     ctx.glSamplerParameterfv(sampler, GL_TEXTURE_SRGB_DECODE_EXT, &params[0]);
2695     ctx.expectError(GL_INVALID_ENUM);
2696     ctx.endSection();
2697 
2698     ctx.glDeleteSamplers(1, &sampler);
2699 }
2700 
srgb_decode_samplerparameterIiv(NegativeTestContext & ctx)2701 void srgb_decode_samplerparameterIiv(NegativeTestContext &ctx)
2702 {
2703     if (!supportsES32orGL45(ctx))
2704         TCU_THROW(NotSupportedError, "glSamplerParameterIiv is not supported.");
2705 
2706     if (!ctx.isExtensionSupported("GL_EXT_texture_sRGB_decode"))
2707         TCU_THROW(NotSupportedError, "GL_EXT_texture_sRGB_decode is not supported.");
2708 
2709     GLint samplerMode[] = {GL_DEPTH_COMPONENT, GL_STENCIL_INDEX};
2710     GLuint sampler      = 0x1234;
2711 
2712     ctx.glGenSamplers(1, &sampler);
2713 
2714     ctx.beginSection("GL_INVALID_ENUM is generated if pname is GL_TEXTURE_SRGB_DECODE_EXT and the value of param(s) is "
2715                      "not a valid value (one of DECODE_EXT, or SKIP_DECODE_EXT).");
2716     samplerMode[0] = -1;
2717     samplerMode[1] = -1;
2718     ctx.glSamplerParameterIiv(sampler, GL_TEXTURE_SRGB_DECODE_EXT, samplerMode);
2719     ctx.expectError(GL_INVALID_ENUM);
2720     ctx.endSection();
2721 
2722     ctx.glDeleteSamplers(1, &sampler);
2723 }
2724 
srgb_decode_samplerparameterIuiv(NegativeTestContext & ctx)2725 void srgb_decode_samplerparameterIuiv(NegativeTestContext &ctx)
2726 {
2727     if (!supportsES32orGL45(ctx))
2728         TCU_THROW(NotSupportedError, "glSamplerParameterIuiv is not supported.");
2729 
2730     if (!ctx.isExtensionSupported("GL_EXT_texture_sRGB_decode"))
2731         TCU_THROW(NotSupportedError, "GL_EXT_texture_sRGB_decode is not supported.");
2732 
2733     GLuint samplerMode[] = {GL_DEPTH_COMPONENT, GL_STENCIL_INDEX};
2734     GLuint sampler       = 0x1234;
2735 
2736     ctx.glGenSamplers(1, &sampler);
2737 
2738     ctx.beginSection("GL_INVALID_ENUM is generated if pname is GL_TEXTURE_SRGB_DECODE_EXT and the value of param(s) is "
2739                      "not a valid value (one of DECODE_EXT, or SKIP_DECODE_EXT).");
2740     samplerMode[0] = GL_DONT_CARE;
2741     samplerMode[1] = GL_DONT_CARE;
2742     ctx.glSamplerParameterIuiv(sampler, GL_TEXTURE_SRGB_DECODE_EXT, samplerMode);
2743     ctx.expectError(GL_INVALID_ENUM);
2744     ctx.endSection();
2745 
2746     ctx.glDeleteSamplers(1, &sampler);
2747 }
2748 
getNegativeShaderApiTestFunctions()2749 std::vector<FunctionContainer> getNegativeShaderApiTestFunctions()
2750 {
2751     FunctionContainer funcs[] = {
2752         {create_shader, "create_shader", "Invalid glCreateShader() usage"},
2753         {shader_source, "shader_source", "Invalid glShaderSource() usage"},
2754         {compile_shader, "compile_shader", "Invalid glCompileShader() usage"},
2755         {delete_shader, "delete_shader", "Invalid glDeleteShader() usage"},
2756         {shader_binary, "shader_binary", "Invalid glShaderBinary() usage"},
2757         {attach_shader, "attach_shader", "Invalid glAttachShader() usage"},
2758         {detach_shader, "detach_shader", "Invalid glDetachShader() usage"},
2759         {link_program, "link_program", "Invalid glLinkProgram() usage"},
2760         {use_program, "use_program", "Invalid glUseProgram() usage"},
2761         {delete_program, "delete_program", "Invalid glDeleteProgram() usage"},
2762         {validate_program, "validate_program", "Invalid glValidateProgram() usage"},
2763         {get_program_binary, "get_program_binary", "Invalid glGetProgramBinary() usage"},
2764         {program_binary, "program_binary", "Invalid glProgramBinary() usage"},
2765         {program_parameteri, "program_parameteri", "Invalid glProgramParameteri() usage"},
2766         {gen_samplers, "gen_samplers", "Invalid glGenSamplers() usage"},
2767         {bind_sampler, "bind_sampler", "Invalid glBindSampler() usage"},
2768         {delete_samplers, "delete_samplers", "Invalid glDeleteSamplers() usage"},
2769         {get_sampler_parameteriv, "get_sampler_parameteriv", "Invalid glGetSamplerParameteriv() usage"},
2770         {get_sampler_parameterfv, "get_sampler_parameterfv", "Invalid glGetSamplerParameterfv() usage"},
2771         {get_sampler_parameterIiv, "get_sampler_parameterIiv", "Invalid glGetSamplerParameterIiv() usage"},
2772         {get_sampler_parameterIuiv, "get_sampler_parameterIuiv", "Invalid glGetSamplerParameterIuiv() usage"},
2773         {sampler_parameteri, "sampler_parameteri", "Invalid glSamplerParameteri() usage"},
2774         {sampler_parameteriv, "sampler_parameteriv", "Invalid glSamplerParameteriv() usage"},
2775         {sampler_parameterf, "sampler_parameterf", "Invalid glSamplerParameterf() usage"},
2776         {sampler_parameterfv, "sampler_parameterfv", "Invalid glSamplerParameterfv() usage"},
2777         {sampler_parameterIiv, "sampler_parameterIiv", "Invalid glSamplerParameterIiv() usage"},
2778         {sampler_parameterIuiv, "sampler_parameterIuiv", "Invalid glSamplerParameterIuiv() usage"},
2779         {get_attrib_location, "get_attrib_location", "Invalid glGetAttribLocation() usage"},
2780         {get_uniform_location, "get_uniform_location", "Invalid glGetUniformLocation() usage"},
2781         {bind_attrib_location, "bind_attrib_location", "Invalid glBindAttribLocation() usage"},
2782         {uniform_block_binding, "uniform_block_binding", "Invalid glUniformBlockBinding() usage"},
2783         {uniformf_invalid_program, "uniformf_invalid_program", "Invalid glUniform{1234}f() usage"},
2784         {uniformf_incompatible_type, "uniformf_incompatible_type", "Invalid glUniform{1234}f() usage"},
2785         {uniformf_invalid_location, "uniformf_invalid_location", "Invalid glUniform{1234}f() usage"},
2786         {uniformfv_invalid_program, "uniformfv_invalid_program", "Invalid glUniform{1234}fv() usage"},
2787         {uniformfv_incompatible_type, "uniformfv_incompatible_type", "Invalid glUniform{1234}fv() usage"},
2788         {uniformfv_invalid_location, "uniformfv_invalid_location", "Invalid glUniform{1234}fv() usage"},
2789         {uniformfv_invalid_count, "uniformfv_invalid_count", "Invalid glUniform{1234}fv() usage"},
2790         {uniformi_invalid_program, "uniformi_invalid_program", "Invalid glUniform{1234}i() usage"},
2791         {uniformi_incompatible_type, "uniformi_incompatible_type", "Invalid glUniform{1234}i() usage"},
2792         {uniformi_invalid_location, "uniformi_invalid_location", "Invalid glUniform{1234}i() usage"},
2793         {uniformiv_invalid_program, "uniformiv_invalid_program", "Invalid glUniform{1234}iv() usage"},
2794         {uniformiv_incompatible_type, "uniformiv_incompatible_type", "Invalid glUniform{1234}iv() usage"},
2795         {uniformiv_invalid_location, "uniformiv_invalid_location", "Invalid glUniform{1234}iv() usage"},
2796         {uniformiv_invalid_count, "uniformiv_invalid_count", "Invalid glUniform{1234}iv() usage"},
2797         {uniformui_invalid_program, "uniformui_invalid_program", "Invalid glUniform{234}ui() usage"},
2798         {uniformui_incompatible_type, "uniformui_incompatible_type", "Invalid glUniform{1234}ui() usage"},
2799         {uniformui_invalid_location, "uniformui_invalid_location", "Invalid glUniform{1234}ui() usage"},
2800         {uniformuiv_invalid_program, "uniformuiv_invalid_program", "Invalid glUniform{234}uiv() usage"},
2801         {uniformuiv_incompatible_type, "uniformuiv_incompatible_type", "Invalid glUniform{1234}uiv() usage"},
2802         {uniformuiv_invalid_location, "uniformuiv_invalid_location", "Invalid glUniform{1234}uiv() usage"},
2803         {uniformuiv_invalid_count, "uniformuiv_invalid_count", "Invalid glUniform{1234}uiv() usage"},
2804         {uniform_matrixfv_invalid_program, "uniform_matrixfv_invalid_program",
2805          "Invalid glUniformMatrix{234}fv() usage"},
2806         {uniform_matrixfv_incompatible_type, "uniform_matrixfv_incompatible_type",
2807          "Invalid glUniformMatrix{234}fv() usage"},
2808         {uniform_matrixfv_invalid_location, "uniform_matrixfv_invalid_location",
2809          "Invalid glUniformMatrix{234}fv() usage"},
2810         {uniform_matrixfv_invalid_count, "uniform_matrixfv_invalid_count", "Invalid glUniformMatrix{234}fv() usage"},
2811         {gen_transform_feedbacks, "gen_transform_feedbacks", "Invalid glGenTransformFeedbacks() usage"},
2812         {bind_transform_feedback, "bind_transform_feedback", "Invalid glBindTransformFeedback() usage"},
2813         {delete_transform_feedbacks, "delete_transform_feedbacks", "Invalid glDeleteTransformFeedbacks() usage"},
2814         {begin_transform_feedback, "begin_transform_feedback", "Invalid glBeginTransformFeedback() usage"},
2815         {pause_transform_feedback, "pause_transform_feedback", "Invalid glPauseTransformFeedback() usage"},
2816         {resume_transform_feedback, "resume_transform_feedback", "Invalid glResumeTransformFeedback() usage"},
2817         {end_transform_feedback, "end_transform_feedback", "Invalid glEndTransformFeedback() usage"},
2818         {get_transform_feedback_varying, "get_transform_feedback_varying",
2819          "Invalid glGetTransformFeedbackVarying() usage"},
2820         {transform_feedback_varyings, "transform_feedback_varyings", "Invalid glTransformFeedbackVaryings() usage"},
2821         {compile_compute_shader, "compile_compute_shader", "Invalid Compute Shader compilation"},
2822         {link_compute_shader, "link_compute_shader", "Invalid Compute Shader linkage"},
2823         {srgb_decode_samplerparameteri, "srgb_decode_samplerparameteri", "Invalid glSamplerParameteri() usage srgb"},
2824         {srgb_decode_samplerparameterf, "srgb_decode_samplerparameterf", "Invalid glSamplerParameterf() usage srgb"},
2825         {srgb_decode_samplerparameteriv, "srgb_decode_samplerparameteriv", "Invalid glSamplerParameteriv() usage srgb"},
2826         {srgb_decode_samplerparameterfv, "srgb_decode_samplerparameterfv", "Invalid glSamplerParameterfv() usage srgb"},
2827         {srgb_decode_samplerparameterIiv, "srgb_decode_samplerparameterIiv",
2828          "Invalid glSamplerParameterIiv() usage srgb"},
2829         {srgb_decode_samplerparameterIuiv, "srgb_decode_samplerparameterIuiv",
2830          "Invalid glSamplerParameterIiuv() usage srgb"},
2831     };
2832 
2833     return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
2834 }
2835 
2836 } // namespace NegativeTestShared
2837 } // namespace Functional
2838 } // namespace gles31
2839 } // namespace deqp
2840