1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES 2.0 Module
3 * -------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Negative Buffer API tests.
22 *//*--------------------------------------------------------------------*/
24 #include "es2fNegativeBufferApiTests.hpp"
25 #include "es2fApiCase.hpp"
26 #include "gluContextInfo.hpp"
28 #include "glwEnums.hpp"
29 #include "glwDefs.hpp"
31 using namespace glw; // GL types
42 NegativeBufferApiTests::NegativeBufferApiTests (Context& context)
43 : TestCaseGroup(context, "buffer", "Negative Buffer API Cases")
47 NegativeBufferApiTests::~NegativeBufferApiTests (void)
51 void NegativeBufferApiTests::init (void)
53 ES2F_ADD_API_CASE(bind_buffer, "Invalid glBindBuffer() usage",
55 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not one of the allowable values.");
57 expectError(GL_INVALID_ENUM);
58 m_log << TestLog::EndSection;
60 ES2F_ADD_API_CASE(delete_buffers, "Invalid glDeleteBuffers() usage",
62 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
63 glDeleteBuffers(-1, 0);
64 expectError(GL_INVALID_VALUE);
65 m_log << TestLog::EndSection;
67 ES2F_ADD_API_CASE(gen_buffers, "Invalid glGenBuffers() usage",
69 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
71 expectError(GL_INVALID_VALUE);
72 m_log << TestLog::EndSection;
74 ES2F_ADD_API_CASE(buffer_data, "Invalid glBufferData() usage",
77 glGenBuffers(1, &buffer);
78 glBindBuffer(GL_ARRAY_BUFFER, buffer);
80 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.");
81 glBufferData(-1, 0, NULL, GL_STREAM_DRAW);
82 expectError(GL_INVALID_ENUM);
83 m_log << TestLog::EndSection;
85 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if usage is not GL_STREAM_DRAW, GL_STATIC_DRAW, or GL_DYNAMIC_DRAW.");
86 glBufferData(GL_ARRAY_BUFFER, 0, NULL, -1);
87 expectError(GL_INVALID_ENUM);
88 m_log << TestLog::EndSection;
90 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if size is negative.");
91 glBufferData(GL_ARRAY_BUFFER, -1, NULL, GL_STREAM_DRAW);
92 expectError(GL_INVALID_VALUE);
93 m_log << TestLog::EndSection;
95 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the reserved buffer object name 0 is bound to target.");
96 glBindBuffer(GL_ARRAY_BUFFER, 0);
97 glBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_STREAM_DRAW);
98 expectError(GL_INVALID_OPERATION);
99 m_log << TestLog::EndSection;
101 glDeleteBuffers(1, &buffer);
103 ES2F_ADD_API_CASE(buffer_sub_data, "Invalid glBufferSubData() usage",
106 glGenBuffers(1, &buffer);
107 glBindBuffer(GL_ARRAY_BUFFER, buffer);
108 glBufferData(GL_ARRAY_BUFFER, 10, 0, GL_STREAM_DRAW);
110 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_ARRAY_BUFFER or GL_ELEMENT_ARRAY_BUFFER.");
111 glBufferSubData(-1, 1, 1, 0);
112 expectError(GL_INVALID_ENUM);
113 m_log << TestLog::EndSection;
115 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the reserved buffer object name 0 is bound to target.");
116 glBindBuffer(GL_ARRAY_BUFFER, 0);
117 glBufferSubData(GL_ARRAY_BUFFER, 1, 1, 0);
118 expectError(GL_INVALID_OPERATION);
119 m_log << TestLog::EndSection;
121 glDeleteBuffers(1, &buffer);
123 ES2F_ADD_API_CASE(buffer_sub_data_size_offset, "Invalid glBufferSubData() usage",
126 glGenBuffers(1, &buffer);
127 glBindBuffer(GL_ARRAY_BUFFER, buffer);
128 glBufferData(GL_ARRAY_BUFFER, 10, 0, GL_STREAM_DRAW);
130 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if offset or size is negative, or if together they define a region of memory that extends beyond the buffer object's allocated data store.");
131 glBufferSubData(GL_ARRAY_BUFFER, -1, 1, 0);
132 expectError(GL_INVALID_VALUE);
133 glBufferSubData(GL_ARRAY_BUFFER, -1, -1, 0);
134 expectError(GL_INVALID_VALUE);
135 glBufferSubData(GL_ARRAY_BUFFER, 1, -1, 0);
136 expectError(GL_INVALID_VALUE);
137 glBufferSubData(GL_ARRAY_BUFFER, 15, 1, 0);
138 expectError(GL_INVALID_VALUE);
139 glBufferSubData(GL_ARRAY_BUFFER, 1, 15, 0);
140 expectError(GL_INVALID_VALUE);
141 glBufferSubData(GL_ARRAY_BUFFER, 8, 8, 0);
142 expectError(GL_INVALID_VALUE);
143 m_log << TestLog::EndSection;
145 glDeleteBuffers(1, &buffer);
147 ES2F_ADD_API_CASE(clear, "Invalid glClear() usage",
149 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if any bit other than the three defined bits is set in mask.");
150 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
151 expectError(GL_NO_ERROR);
153 expectError(GL_INVALID_VALUE);
155 expectError(GL_INVALID_VALUE);
157 expectError(GL_INVALID_VALUE);
158 m_log << TestLog::EndSection;
160 ES2F_ADD_API_CASE(read_pixels, "Invalid glReadPixels() usage",
162 std::vector<GLubyte> ubyteData(4);
164 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the combination of format and type is unsupported.");
165 glReadPixels(0, 0, 1, 1, GL_LUMINANCE_ALPHA, GL_UNSIGNED_SHORT_4_4_4_4, &ubyteData[0]);
166 expectError(GL_INVALID_OPERATION);
167 m_log << TestLog::EndSection;
169 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if either width or height is negative.");
170 glReadPixels(0, 0, -1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
171 expectError(GL_INVALID_VALUE);
172 glReadPixels(0, 0, 1, -1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
173 expectError(GL_INVALID_VALUE);
174 glReadPixels(0, 0, -1, -1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
175 expectError(GL_INVALID_VALUE);
176 m_log << TestLog::EndSection;
178 m_log << TestLog::Section("", "GL_INVALID_FRAMEBUFFER_OPERATION is generated if the currently bound framebuffer is not framebuffer complete.");
180 glGenFramebuffers(1, &fbo);
181 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
182 glCheckFramebufferStatus(GL_FRAMEBUFFER);
183 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
184 expectError(GL_INVALID_FRAMEBUFFER_OPERATION);
185 m_log << TestLog::EndSection;
187 ES2F_ADD_API_CASE(read_pixels_format_mismatch, "Invalid glReadPixels() usage",
189 std::vector<GLubyte> ubyteData(4);
190 std::vector<GLushort> ushortData(4);
192 m_log << TestLog::Section("", "Unsupported combinations of format and type will generate an INVALID_OPERATION error.");
193 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_SHORT_5_6_5, &ushortData[0]);
194 expectError(GL_INVALID_OPERATION);
195 glReadPixels(0, 0, 1, 1, GL_ALPHA, GL_UNSIGNED_SHORT_5_6_5, &ushortData[0]);
196 expectError(GL_INVALID_OPERATION);
197 glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_4_4_4_4, &ushortData[0]);
198 expectError(GL_INVALID_OPERATION);
199 glReadPixels(0, 0, 1, 1, GL_ALPHA, GL_UNSIGNED_SHORT_4_4_4_4, &ushortData[0]);
200 expectError(GL_INVALID_OPERATION);
201 glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, &ushortData[0]);
202 expectError(GL_INVALID_OPERATION);
203 glReadPixels(0, 0, 1, 1, GL_ALPHA, GL_UNSIGNED_SHORT_5_5_5_1, &ushortData[0]);
204 expectError(GL_INVALID_OPERATION);
205 m_log << TestLog::EndSection;
207 m_log << TestLog::Section("", "GL_RGBA/GL_UNSIGNED_BYTE is always accepted and the other acceptable pair can be discovered by querying GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE.");
208 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &ubyteData[0]);
209 expectError(GL_NO_ERROR);
212 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &readFormat);
213 glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &readType);
214 glReadPixels(0, 0, 1, 1, readFormat, readType, &ubyteData[0]);
215 expectError(GL_NO_ERROR);
216 m_log << TestLog::EndSection;
219 // Framebuffer Objects
221 ES2F_ADD_API_CASE(bind_framebuffer, "Invalid glBindFramebuffer() usage",
223 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
224 glBindFramebuffer(-1, 0);
225 expectError(GL_INVALID_ENUM);
226 glBindFramebuffer(GL_RENDERBUFFER, 0);
227 expectError(GL_INVALID_ENUM);
228 m_log << TestLog::EndSection;
230 ES2F_ADD_API_CASE(bind_renderbuffer, "Invalid glBindRenderbuffer() usage",
232 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_RENDERBUFFER.");
233 glBindRenderbuffer(-1, 0);
234 expectError(GL_INVALID_ENUM);
235 glBindRenderbuffer(GL_FRAMEBUFFER, 0);
236 expectError(GL_INVALID_ENUM);
237 m_log << TestLog::EndSection;
239 ES2F_ADD_API_CASE(check_framebuffer_status, "Invalid glCheckFramebufferStatus() usage",
241 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
242 glCheckFramebufferStatus(-1);
243 expectError(GL_INVALID_ENUM);
244 glCheckFramebufferStatus(GL_RENDERBUFFER);
245 expectError(GL_INVALID_ENUM);
246 m_log << TestLog::EndSection;
248 ES2F_ADD_API_CASE(gen_framebuffers, "Invalid glGenFramebuffers() usage",
250 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
251 glGenFramebuffers(-1, 0);
252 expectError(GL_INVALID_VALUE);
253 m_log << TestLog::EndSection;
255 ES2F_ADD_API_CASE(gen_renderbuffers, "Invalid glGenRenderbuffers() usage",
257 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
258 glGenRenderbuffers(-1, 0);
259 expectError(GL_INVALID_VALUE);
260 m_log << TestLog::EndSection;
262 ES2F_ADD_API_CASE(delete_framebuffers, "Invalid glDeleteFramebuffers() usage",
264 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
265 glDeleteFramebuffers(-1, 0);
266 expectError(GL_INVALID_VALUE);
267 m_log << TestLog::EndSection;
269 ES2F_ADD_API_CASE(delete_renderbuffers, "Invalid glDeleteRenderbuffers() usage",
271 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if n is negative.");
272 glDeleteRenderbuffers(-1, 0);
273 expectError(GL_INVALID_VALUE);
274 m_log << TestLog::EndSection;
276 ES2F_ADD_API_CASE(framebuffer_renderbuffer, "Invalid glFramebufferRenderbuffer() usage",
280 glGenFramebuffers(1, &fbo);
281 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
282 glGenRenderbuffers(1, &rbo);
284 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
285 glFramebufferRenderbuffer(-1, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
286 expectError(GL_INVALID_ENUM);
287 m_log << TestLog::EndSection;
289 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if attachment is not an accepted attachment point.");
290 glFramebufferRenderbuffer(GL_FRAMEBUFFER, -1, GL_RENDERBUFFER, 0);
291 expectError(GL_INVALID_ENUM);
292 m_log << TestLog::EndSection;
294 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if renderbuffertarget is not GL_RENDERBUFFER.");
295 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
296 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, -1, rbo);
297 expectError(GL_INVALID_ENUM);
298 glBindRenderbuffer(GL_RENDERBUFFER, 0);
299 m_log << TestLog::EndSection;
301 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if renderbuffer is neither 0 nor the name of an existing renderbuffer object.");
302 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, -1);
303 expectError(GL_INVALID_OPERATION);
304 m_log << TestLog::EndSection;
306 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the default framebuffer object name 0 is bound.");
307 glBindFramebuffer(GL_FRAMEBUFFER, 0);
308 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
309 expectError(GL_INVALID_OPERATION);
310 m_log << TestLog::EndSection;
312 glDeleteRenderbuffers(1, &rbo);
313 glDeleteFramebuffers(1, &fbo);
315 ES2F_ADD_API_CASE(framebuffer_texture2d, "Invalid glFramebufferTexture2D() usage",
320 glGenFramebuffers(1, &fbo);
321 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
322 glGenTextures(1, &tex2D);
323 glBindTexture(GL_TEXTURE_2D, tex2D);
324 glGenTextures(1, &texCube);
325 glBindTexture(GL_TEXTURE_CUBE_MAP, texCube);
326 expectError(GL_NO_ERROR);
328 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_FRAMEBUFFER.");
329 glFramebufferTexture2D(-1, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
330 expectError(GL_INVALID_ENUM);
331 m_log << TestLog::EndSection;
333 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if textarget is not an accepted texture target.");
334 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, -1, tex2D, 0);
335 expectError(GL_INVALID_ENUM);
336 m_log << TestLog::EndSection;
338 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if attachment is not an accepted attachment point.");
339 glFramebufferTexture2D(GL_FRAMEBUFFER, -1, GL_TEXTURE_2D, 0, 0);
340 expectError(GL_INVALID_ENUM);
341 m_log << TestLog::EndSection;
343 // Detect compatible GLES context by querying GL_MAJOR_VERSION.
344 // This query does not exist on GLES2 so succeeding query implies GLES3+ context.
345 bool isES3Compatible = false;
346 glw::GLint majorVersion = 0;
347 glGetIntegerv(GL_MAJOR_VERSION, &majorVersion);
348 if (glGetError() == GL_NO_ERROR)
349 isES3Compatible = true;
351 if (!(m_context.getContextInfo().isExtensionSupported("GL_OES_fbo_render_mipmap") || isES3Compatible))
353 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if level is not 0.");
354 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex2D, 3);
355 expectError(GL_INVALID_VALUE);
356 m_log << TestLog::EndSection;
359 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if texture is neither 0 nor the name of an existing texture object.");
360 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, -1, 0);
361 expectError(GL_INVALID_OPERATION);
362 m_log << TestLog::EndSection;
364 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if texture is the name of an existing two-dimensional texture object but textarget is not GL_TEXTURE_2D.");
366 expectError(GL_NO_ERROR);
367 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, tex2D, 0);
368 expectError(GL_INVALID_OPERATION);
369 glDeleteTextures(1, &tex2D);
370 m_log << TestLog::EndSection;
372 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if texture is the name of an existing cube map texture object but textarget is GL_TEXTURE_2D.");
373 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texCube, 0);
374 expectError(GL_INVALID_OPERATION);
375 glDeleteTextures(1, &texCube);
376 m_log << TestLog::EndSection;
378 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the default framebuffer object name 0 is bound.");
379 glBindFramebuffer(GL_FRAMEBUFFER, 0);
380 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
381 expectError(GL_INVALID_OPERATION);
382 m_log << TestLog::EndSection;
384 glDeleteFramebuffers(1, &fbo);
386 ES2F_ADD_API_CASE(renderbuffer_storage, "Invalid glRenderbufferStorage() usage",
389 glGenRenderbuffers(1, &rbo);
390 glBindRenderbuffer(GL_RENDERBUFFER, rbo);
392 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if target is not GL_RENDERBUFFER.");
393 glRenderbufferStorage(-1, GL_RGBA4, 1, 1);
394 expectError(GL_INVALID_ENUM);
395 glRenderbufferStorage(GL_FRAMEBUFFER, GL_RGBA4, 1, 1);
396 expectError(GL_INVALID_ENUM);
397 m_log << TestLog::EndSection;
399 m_log << TestLog::Section("", "GL_INVALID_ENUM is generated if internalformat is not an accepted format.");
400 glRenderbufferStorage(GL_RENDERBUFFER, -1, 1, 1);
401 expectError(GL_INVALID_ENUM);
402 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 1, 1);
403 expectError(GL_INVALID_ENUM);
404 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1, 1);
405 expectError(GL_INVALID_ENUM);
406 m_log << TestLog::EndSection;
408 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if width or height is less than zero.");
409 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, -1, 1);
410 expectError(GL_INVALID_VALUE);
411 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, -1);
412 expectError(GL_INVALID_VALUE);
413 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, -1, -1);
414 expectError(GL_INVALID_VALUE);
415 m_log << TestLog::EndSection;
417 m_log << TestLog::Section("", "GL_INVALID_VALUE is generated if width or height is greater than GL_MAX_RENDERBUFFER_SIZE.");
419 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &maxSize);
420 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, maxSize+1);
421 expectError(GL_INVALID_VALUE);
422 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, maxSize+1, 1);
423 expectError(GL_INVALID_VALUE);
424 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, maxSize+1, maxSize+1);
425 expectError(GL_INVALID_VALUE);
426 m_log << TestLog::EndSection;
428 m_log << TestLog::Section("", "GL_INVALID_OPERATION is generated if the reserved renderbuffer object name 0 is bound.");
429 glBindRenderbuffer(GL_RENDERBUFFER, 0);
430 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
431 expectError(GL_INVALID_OPERATION);
432 m_log << TestLog::EndSection;
434 glDeleteRenderbuffers(1, &rbo);