blob: fa84091e1e22a9caf149d469d5db000fed46333e [file] [log] [blame]
Geoff Langc287ea62016-09-16 14:46:51 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// WebGLCompatibilityTest.cpp : Tests of the GL_ANGLE_webgl_compatibility extension.
8
9#include "test_utils/ANGLETest.h"
10
Geoff Lang677bb6f2017-04-05 12:40:40 -040011#include "common/mathutil.h"
Geoff Langc287ea62016-09-16 14:46:51 -040012#include "test_utils/gl_raii.h"
13
Frank Henigman146e8a12017-03-02 23:22:37 -050014namespace
15{
16
17bool ConstantColorAndAlphaBlendFunctions(GLenum first, GLenum second)
18{
19 return (first == GL_CONSTANT_COLOR || first == GL_ONE_MINUS_CONSTANT_COLOR) &&
20 (second == GL_CONSTANT_ALPHA || second == GL_ONE_MINUS_CONSTANT_ALPHA);
21}
22
23void CheckBlendFunctions(GLenum src, GLenum dst)
24{
25 if (ConstantColorAndAlphaBlendFunctions(src, dst) ||
26 ConstantColorAndAlphaBlendFunctions(dst, src))
27 {
28 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
29 }
30 else
31 {
32 ASSERT_GL_NO_ERROR();
33 }
34}
35
Geoff Lang677bb6f2017-04-05 12:40:40 -040036// Extensions that affect the ability to use floating point textures
37constexpr const char *FloatingPointTextureExtensions[] = {
38 "",
39 "GL_EXT_texture_storage",
Geoff Lang677bb6f2017-04-05 12:40:40 -040040 "GL_OES_texture_half_float",
41 "GL_OES_texture_half_float_linear",
42 "GL_EXT_color_buffer_half_float",
Geoff Lang7d4602f2017-09-13 10:45:09 -040043 "GL_OES_texture_float",
44 "GL_OES_texture_float_linear",
Geoff Lang677bb6f2017-04-05 12:40:40 -040045 "GL_EXT_color_buffer_float",
46 "GL_CHROMIUM_color_buffer_float_rgba",
47 "GL_CHROMIUM_color_buffer_float_rgb",
48};
49
Frank Henigman146e8a12017-03-02 23:22:37 -050050} // namespace
51
Geoff Langc287ea62016-09-16 14:46:51 -040052namespace angle
53{
54
55class WebGLCompatibilityTest : public ANGLETest
56{
57 protected:
58 WebGLCompatibilityTest()
59 {
60 setWindowWidth(128);
61 setWindowHeight(128);
62 setConfigRedBits(8);
63 setConfigGreenBits(8);
64 setConfigBlueBits(8);
65 setConfigAlphaBits(8);
66 setWebGLCompatibilityEnabled(true);
67 }
68
69 void SetUp() override
70 {
71 ANGLETest::SetUp();
Geoff Langc339c4e2016-11-29 10:37:36 -050072 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
73 eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040074 }
75
Geoff Lang677bb6f2017-04-05 12:40:40 -040076 template <typename T>
77 void TestFloatTextureFormat(GLenum internalFormat,
78 GLenum format,
79 GLenum type,
80 bool texturingEnabled,
81 bool linearSamplingEnabled,
82 bool renderingEnabled,
83 const T textureData[4],
84 const float floatData[4])
85 {
86 ASSERT_GL_NO_ERROR();
87
88 const std::string samplingVs =
89 "attribute vec4 position;\n"
90 "varying vec2 texcoord;\n"
91 "void main()\n"
92 "{\n"
93 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
94 " texcoord = (position.xy * 0.5) + 0.5;\n"
95 "}\n";
96
97 const std::string samplingFs =
98 "precision mediump float;\n"
99 "uniform sampler2D tex;\n"
100 "uniform vec4 subtractor;\n"
101 "varying vec2 texcoord;\n"
102 "void main()\n"
103 "{\n"
104 " vec4 color = texture2D(tex, texcoord);\n"
105 " if (abs(color.r - subtractor.r) +\n"
106 " abs(color.g - subtractor.g) +\n"
107 " abs(color.b - subtractor.b) +\n"
108 " abs(color.a - subtractor.a) < 8.0)\n"
109 " {\n"
110 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
111 " }\n"
112 " else\n"
113 " {\n"
114 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
115 " }\n"
116 "}\n";
117
118 ANGLE_GL_PROGRAM(samplingProgram, samplingVs, samplingFs);
119 glUseProgram(samplingProgram.get());
120
121 GLRenderbuffer rbo;
122 glBindRenderbuffer(GL_RENDERBUFFER, rbo.get());
123 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
124
125 GLFramebuffer fbo;
126 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
127 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo.get());
128
129 GLTexture texture;
130 glBindTexture(GL_TEXTURE_2D, texture.get());
131
132 if (internalFormat == format)
133 {
134 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, textureData);
135 }
136 else
137 {
138 if (getClientMajorVersion() >= 3)
139 {
140 glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
141 }
142 else
143 {
144 ASSERT_TRUE(extensionEnabled("GL_EXT_texture_storage"));
145 glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
146 }
147 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, format, type, textureData);
148 }
149
150 if (!texturingEnabled)
151 {
152 // Depending on the entry point and client version, different errors may be generated
153 ASSERT_GLENUM_NE(GL_NO_ERROR, glGetError());
154
155 // Two errors may be generated in the glTexStorage + glTexSubImage case, clear the
156 // second error
157 glGetError();
158
159 return;
160 }
161 ASSERT_GL_NO_ERROR();
162
163 glUniform1i(glGetUniformLocation(samplingProgram.get(), "tex"), 0);
164 glUniform4fv(glGetUniformLocation(samplingProgram.get(), "subtractor"), 1, floatData);
165
166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
168 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
169 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
170
171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
172 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
173
174 if (linearSamplingEnabled)
175 {
176 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
177 }
178 else
179 {
180 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
181 }
182
183 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(),
184 0);
185 glBindTexture(GL_TEXTURE_2D, 0);
186 if (!renderingEnabled)
187 {
188 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
189 glCheckFramebufferStatus(GL_FRAMEBUFFER));
190 return;
191 }
192 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
193
194 const std::string renderingVs =
195 "attribute vec4 position;\n"
196 "void main()\n"
197 "{\n"
198 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
199 "}\n";
200
201 const std::string renderingFs =
202 "precision mediump float;\n"
203 "uniform vec4 writeValue;\n"
204 "void main()\n"
205 "{\n"
206 " gl_FragColor = writeValue;\n"
207 "}\n";
208
209 ANGLE_GL_PROGRAM(renderingProgram, renderingVs, renderingFs);
210 glUseProgram(renderingProgram.get());
211
212 glUniform4fv(glGetUniformLocation(renderingProgram.get(), "writeValue"), 1, floatData);
213
214 drawQuad(renderingProgram.get(), "position", 0.5f, 1.0f, true);
215
216 EXPECT_PIXEL_COLOR32F_NEAR(
217 0, 0, GLColor32F(floatData[0], floatData[1], floatData[2], floatData[3]), 1.0f);
218 }
219
Jamie Madillcad97ee2017-02-02 18:52:44 -0500220 // Called from RenderingFeedbackLoopWithDrawBuffersEXT.
221 void drawBuffersEXTFeedbackLoop(GLuint program,
222 const std::array<GLenum, 2> &drawBuffers,
223 GLenum expectedError);
224
Jamie Madill07be8bf2017-02-02 19:59:57 -0500225 // Called from RenderingFeedbackLoopWithDrawBuffers.
226 void drawBuffersFeedbackLoop(GLuint program,
227 const std::array<GLenum, 2> &drawBuffers,
228 GLenum expectedError);
229
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -0700230 // Called from InvalidTextureFormat
231 void validateTexImageExtensionFormat(GLenum format, const std::string &extName);
232
Geoff Langc339c4e2016-11-29 10:37:36 -0500233 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
Geoff Langc287ea62016-09-16 14:46:51 -0400234};
235
Corentin Wallezfd456442016-12-21 17:57:00 -0500236class WebGL2CompatibilityTest : public WebGLCompatibilityTest
237{
238};
239
Geoff Langc287ea62016-09-16 14:46:51 -0400240// Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so
241// the GL extension should always be present
242TEST_P(WebGLCompatibilityTest, ExtensionStringExposed)
243{
244 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
245}
246
247// Verify that all extension entry points are available
248TEST_P(WebGLCompatibilityTest, EntryPoints)
249{
Geoff Langc339c4e2016-11-29 10:37:36 -0500250 if (extensionEnabled("GL_ANGLE_request_extension"))
Geoff Langc287ea62016-09-16 14:46:51 -0400251 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500252 EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -0400253 }
254}
255
256// WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable,
257// even in ES2 contexts.
258TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint)
259{
260 GLRenderbuffer renderbuffer;
261 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
262 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
263
264 GLFramebuffer framebuffer;
265 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
266 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
267 renderbuffer.get());
268
269 EXPECT_GL_NO_ERROR();
270}
271
272// Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION
273TEST_P(WebGLCompatibilityTest, EnableExtensionValidation)
274{
Geoff Langc339c4e2016-11-29 10:37:36 -0500275 glRequestExtensionANGLE("invalid_extension_string");
Geoff Langc287ea62016-09-16 14:46:51 -0400276 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
277}
278
279// Test enabling the GL_OES_element_index_uint extension
280TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices)
281{
282 if (getClientMajorVersion() != 2)
283 {
284 // This test only works on ES2 where uint indices are not available by default
285 return;
286 }
287
288 EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint"));
289
290 GLBuffer indexBuffer;
291 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
292
293 GLuint data[] = {0, 1, 2, 1, 3, 2};
294 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
295
296 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
297 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
298 glUseProgram(program.get());
299
Jamie Madille7b96342017-06-23 15:06:08 -0400300 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400301 EXPECT_GL_ERROR(GL_INVALID_ENUM);
302
Geoff Langc339c4e2016-11-29 10:37:36 -0500303 if (extensionRequestable("GL_OES_element_index_uint"))
Geoff Langc287ea62016-09-16 14:46:51 -0400304 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500305 glRequestExtensionANGLE("GL_OES_element_index_uint");
Geoff Langc287ea62016-09-16 14:46:51 -0400306 EXPECT_GL_NO_ERROR();
307 EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint"));
308
Jamie Madille7b96342017-06-23 15:06:08 -0400309 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400310 EXPECT_GL_NO_ERROR();
311 }
312}
313
Geoff Langff5c63e2017-04-12 15:26:54 -0400314// Test enabling the GL_OES_standard_derivatives extension
315TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives)
316{
317 EXPECT_FALSE(extensionEnabled("GL_OES_standard_derivatives"));
318
319 const std::string source =
320 "#extension GL_OES_standard_derivatives : require\n"
321 "void main() { gl_FragColor = vec4(dFdx(vec2(1.0, 1.0)).x, 1, 0, 1); }\n";
322 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
323
324 if (extensionRequestable("GL_OES_standard_derivatives"))
325 {
326 glRequestExtensionANGLE("GL_OES_standard_derivatives");
327 EXPECT_GL_NO_ERROR();
328 EXPECT_TRUE(extensionEnabled("GL_OES_standard_derivatives"));
329
330 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
331 ASSERT_NE(0u, shader);
332 glDeleteShader(shader);
333 }
334}
335
336// Test enabling the GL_EXT_shader_texture_lod extension
337TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD)
338{
339 EXPECT_FALSE(extensionEnabled("GL_EXT_shader_texture_lod"));
340
341 const std::string source =
342 "#extension GL_EXT_shader_texture_lod : require\n"
343 "uniform sampler2D u_texture;\n"
344 "void main() {\n"
345 " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, "
346 "0.0));\n"
347 "}\n";
348 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
349
350 if (extensionRequestable("GL_EXT_shader_texture_lod"))
351 {
352 glRequestExtensionANGLE("GL_EXT_shader_texture_lod");
353 EXPECT_GL_NO_ERROR();
354 EXPECT_TRUE(extensionEnabled("GL_EXT_shader_texture_lod"));
355
356 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
357 ASSERT_NE(0u, shader);
358 glDeleteShader(shader);
359 }
360}
361
362// Test enabling the GL_EXT_frag_depth extension
363TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth)
364{
365 EXPECT_FALSE(extensionEnabled("GL_EXT_frag_depth"));
366
367 const std::string source =
368 "#extension GL_EXT_frag_depth : require\n"
369 "void main() {\n"
370 " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
371 " gl_FragDepthEXT = 1.0;\n"
372 "}\n";
373 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
374
375 if (extensionRequestable("GL_EXT_frag_depth"))
376 {
377 glRequestExtensionANGLE("GL_EXT_frag_depth");
378 EXPECT_GL_NO_ERROR();
379 EXPECT_TRUE(extensionEnabled("GL_EXT_frag_depth"));
380
381 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
382 ASSERT_NE(0u, shader);
383 glDeleteShader(shader);
384 }
385}
386
Geoff Langd7d526a2017-02-21 16:48:43 -0500387// Test enabling the GL_EXT_texture_filter_anisotropic extension
388TEST_P(WebGLCompatibilityTest, EnableExtensionTextureFilterAnisotropic)
389{
390 EXPECT_FALSE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
391
392 GLfloat maxAnisotropy = 0.0f;
393 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
394 EXPECT_GL_ERROR(GL_INVALID_ENUM);
395
396 GLTexture texture;
397 glBindTexture(GL_TEXTURE_2D, texture.get());
398 ASSERT_GL_NO_ERROR();
399
400 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
401 EXPECT_GL_ERROR(GL_INVALID_ENUM);
402
403 GLfloat currentAnisotropy = 0.0f;
404 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
405 EXPECT_GL_ERROR(GL_INVALID_ENUM);
406
407 if (extensionRequestable("GL_EXT_texture_filter_anisotropic"))
408 {
409 glRequestExtensionANGLE("GL_EXT_texture_filter_anisotropic");
410 EXPECT_GL_NO_ERROR();
411 EXPECT_TRUE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
412
413 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
414 ASSERT_GL_NO_ERROR();
415 EXPECT_GE(maxAnisotropy, 2.0f);
416
417 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
418 ASSERT_GL_NO_ERROR();
419 EXPECT_EQ(1.0f, currentAnisotropy);
420
421 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
422 ASSERT_GL_NO_ERROR();
423 }
424}
425
Bryan Bernhart87c182e2016-11-02 11:23:22 -0700426// Verify that shaders are of a compatible spec when the extension is enabled.
427TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec)
428{
429 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
430
431 // Use of reserved _webgl prefix should fail when the shader specification is for WebGL.
432 const std::string &vert =
433 "struct Foo {\n"
434 " int _webgl_bar;\n"
435 "};\n"
436 "void main()\n"
437 "{\n"
438 " Foo foo = Foo(1);\n"
439 "}";
440
441 // Default fragement shader.
442 const std::string &frag =
443 "void main()\n"
444 "{\n"
445 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
446 "}";
447
448 GLuint program = CompileProgram(vert, frag);
449 EXPECT_EQ(0u, program);
450 glDeleteProgram(program);
451}
452
Geoff Lang3fab7632017-09-26 15:45:54 -0400453// Test enabling the GL_NV_pixel_buffer_object extension
454TEST_P(WebGLCompatibilityTest, EnablePixelBufferObjectExtensions)
455{
456 EXPECT_FALSE(extensionEnabled("GL_NV_pixel_buffer_object"));
457 EXPECT_FALSE(extensionEnabled("GL_OES_mapbuffer"));
458 EXPECT_FALSE(extensionEnabled("GL_EXT_map_buffer_range"));
459
460 // These extensions become core in in ES3/WebGL2.
461 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
462
463 GLBuffer buffer;
464 glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
465 EXPECT_GL_ERROR(GL_INVALID_ENUM);
466
467 if (extensionRequestable("GL_NV_pixel_buffer_object"))
468 {
469 glRequestExtensionANGLE("GL_NV_pixel_buffer_object");
470 EXPECT_GL_NO_ERROR();
471
472 glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
473 EXPECT_GL_NO_ERROR();
474
475 glBufferData(GL_PIXEL_PACK_BUFFER, 4, nullptr, GL_STATIC_DRAW);
476 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
477 EXPECT_GL_NO_ERROR();
478 }
479}
480
481// Test enabling the GL_OES_mapbuffer and GL_EXT_map_buffer_range extensions
482TEST_P(WebGLCompatibilityTest, EnableMapBufferExtensions)
483{
484 EXPECT_FALSE(extensionEnabled("GL_OES_mapbuffer"));
485 EXPECT_FALSE(extensionEnabled("GL_EXT_map_buffer_range"));
486
487 // These extensions become core in in ES3/WebGL2.
488 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
489
490 GLBuffer buffer;
491 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
492 glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4, nullptr, GL_STATIC_DRAW);
493
494 glMapBufferOES(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
495 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
496
497 glMapBufferRangeEXT(GL_ELEMENT_ARRAY_BUFFER, 0, 4, GL_MAP_WRITE_BIT);
498 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
499
500 GLint access = 0;
501 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
502 EXPECT_GL_ERROR(GL_INVALID_ENUM);
503
504 if (extensionRequestable("GL_OES_mapbuffer"))
505 {
506 glRequestExtensionANGLE("GL_OES_mapbuffer");
507 EXPECT_GL_NO_ERROR();
508
509 glMapBufferOES(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
510 glUnmapBufferOES(GL_ELEMENT_ARRAY_BUFFER);
511 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
512 EXPECT_GL_NO_ERROR();
513 }
514
515 if (extensionRequestable("GL_EXT_map_buffer_range"))
516 {
517 glRequestExtensionANGLE("GL_EXT_map_buffer_range");
518 EXPECT_GL_NO_ERROR();
519
520 glMapBufferRangeEXT(GL_ELEMENT_ARRAY_BUFFER, 0, 4, GL_MAP_WRITE_BIT);
521 glUnmapBufferOES(GL_ELEMENT_ARRAY_BUFFER);
522 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
523 EXPECT_GL_NO_ERROR();
524 }
525}
526
Geoff Lang8c7133c2017-09-26 17:31:10 -0400527// Test enabling the GL_OES_fbo_render_mipmap extension
528TEST_P(WebGLCompatibilityTest, EnableRenderMipmapExtension)
529{
530 EXPECT_FALSE(extensionEnabled("GL_OES_fbo_render_mipmap"));
531
532 // This extensions become core in in ES3/WebGL2.
533 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
534
535 GLTexture texture;
536 glBindTexture(GL_TEXTURE_2D, texture);
537 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
538 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
539
540 GLFramebuffer fbo;
541 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
542 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
543 EXPECT_GL_NO_ERROR();
544
545 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
546 EXPECT_GL_ERROR(GL_INVALID_VALUE);
547
548 if (extensionRequestable("GL_OES_fbo_render_mipmap"))
549 {
550 glRequestExtensionANGLE("GL_OES_fbo_render_mipmap");
551 EXPECT_GL_NO_ERROR();
552
553 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
554 EXPECT_GL_NO_ERROR();
555 }
556}
557
Geoff Lang50cac572017-09-26 17:37:43 -0400558// Test enabling the GL_EXT_blend_minmax extension
559TEST_P(WebGLCompatibilityTest, EnableBlendMinMaxExtension)
560{
561 EXPECT_FALSE(extensionEnabled("GL_EXT_blend_minmax"));
562
563 // This extensions become core in in ES3/WebGL2.
564 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
565
566 glBlendEquation(GL_MIN);
567 EXPECT_GL_ERROR(GL_INVALID_ENUM);
568
569 glBlendEquation(GL_MAX);
570 EXPECT_GL_ERROR(GL_INVALID_ENUM);
571
572 if (extensionRequestable("GL_EXT_blend_minmax"))
573 {
574 glRequestExtensionANGLE("GL_EXT_blend_minmax");
575 EXPECT_GL_NO_ERROR();
576
577 glBlendEquation(GL_MIN);
578 glBlendEquation(GL_MAX);
579 EXPECT_GL_NO_ERROR();
580 }
581}
582
Geoff Lang8c5b31c2017-09-26 18:07:44 -0400583// Test enabling the query extensions
584TEST_P(WebGLCompatibilityTest, EnableQueryExtensions)
585{
586 EXPECT_FALSE(extensionEnabled("GL_EXT_occlusion_query_boolean"));
587 EXPECT_FALSE(extensionEnabled("GL_EXT_disjoint_timer_query"));
588 EXPECT_FALSE(extensionEnabled("GL_CHROMIUM_sync_query"));
589
590 // This extensions become core in in ES3/WebGL2.
591 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
592
593 GLQueryEXT badQuery;
594
595 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, badQuery);
596 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
597
598 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, badQuery);
599 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
600
601 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, badQuery);
602 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
603
604 glQueryCounterEXT(GL_TIMESTAMP_EXT, badQuery);
605 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
606
607 glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, badQuery);
608 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
609
610 if (extensionRequestable("GL_EXT_occlusion_query_boolean"))
611 {
612 glRequestExtensionANGLE("GL_EXT_occlusion_query_boolean");
613 EXPECT_GL_NO_ERROR();
614
615 GLQueryEXT query;
616 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query);
617 glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
618 EXPECT_GL_NO_ERROR();
619 }
620
621 if (extensionRequestable("GL_EXT_disjoint_timer_query"))
622 {
623 glRequestExtensionANGLE("GL_EXT_disjoint_timer_query");
624 EXPECT_GL_NO_ERROR();
625
626 GLQueryEXT query1;
627 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query1);
628 glEndQueryEXT(GL_TIME_ELAPSED_EXT);
629 EXPECT_GL_NO_ERROR();
630
631 GLQueryEXT query2;
632 glQueryCounterEXT(query2, GL_TIMESTAMP_EXT);
633 EXPECT_GL_NO_ERROR();
634 }
635
636 if (extensionRequestable("GL_CHROMIUM_sync_query"))
637 {
638 glRequestExtensionANGLE("GL_CHROMIUM_sync_query");
639 EXPECT_GL_NO_ERROR();
640
641 GLQueryEXT query;
642 glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query);
643 glEndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
644 EXPECT_GL_NO_ERROR();
645 }
646}
647
Geoff Lang488130e2017-09-27 13:53:11 -0400648// Test enabling the GL_ANGLE_framebuffer_multisample extension
649TEST_P(WebGLCompatibilityTest, EnableFramebufferMultisampleExtension)
650{
651 EXPECT_FALSE(extensionEnabled("GL_ANGLE_framebuffer_multisample"));
652
653 // This extensions become core in in ES3/WebGL2.
654 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
655
656 GLint maxSamples = 0;
657 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
658 EXPECT_GL_ERROR(GL_INVALID_ENUM);
659
660 GLRenderbuffer renderbuffer;
661 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
662 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_RGBA4, 1, 1);
663 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
664
665 if (extensionRequestable("GL_ANGLE_framebuffer_multisample"))
666 {
667 glRequestExtensionANGLE("GL_ANGLE_framebuffer_multisample");
668 EXPECT_GL_NO_ERROR();
669
670 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
671 EXPECT_GL_NO_ERROR();
672
673 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, maxSamples, GL_RGBA4, 1, 1);
674 EXPECT_GL_NO_ERROR();
675 }
676}
677
Geoff Lang63c5a592017-09-27 14:08:16 -0400678// Test enabling the GL_ANGLE_instanced_arrays extension
679TEST_P(WebGLCompatibilityTest, EnableInstancedArraysExtension)
680{
681 EXPECT_FALSE(extensionEnabled("GL_ANGLE_instanced_arrays"));
682
683 // This extensions become core in in ES3/WebGL2.
684 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
685
686 GLint divisor = 0;
687 glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &divisor);
688 EXPECT_GL_ERROR(GL_INVALID_ENUM);
689
690 glVertexAttribDivisorANGLE(0, 1);
691 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
692
693 if (extensionRequestable("GL_ANGLE_instanced_arrays"))
694 {
695 glRequestExtensionANGLE("GL_ANGLE_instanced_arrays");
696 EXPECT_GL_NO_ERROR();
697
698 glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &divisor);
699 glVertexAttribDivisorANGLE(0, 1);
700 EXPECT_GL_NO_ERROR();
701 }
702}
703
Geoff Lang000dab82017-09-27 14:27:07 -0400704// Test enabling the GL_ANGLE_pack_reverse_row_order extension
705TEST_P(WebGLCompatibilityTest, EnablePackReverseRowOrderExtension)
706{
707 EXPECT_FALSE(extensionEnabled("GL_ANGLE_pack_reverse_row_order"));
708
709 GLint result = 0;
710 glGetIntegerv(GL_PACK_REVERSE_ROW_ORDER_ANGLE, &result);
711 EXPECT_GL_ERROR(GL_INVALID_ENUM);
712
713 glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE);
714 EXPECT_GL_ERROR(GL_INVALID_ENUM);
715
716 if (extensionRequestable("GL_ANGLE_pack_reverse_row_order"))
717 {
718 glRequestExtensionANGLE("GL_ANGLE_pack_reverse_row_order");
719 EXPECT_GL_NO_ERROR();
720
721 glGetIntegerv(GL_PACK_REVERSE_ROW_ORDER_ANGLE, &result);
722 glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE);
723 EXPECT_GL_NO_ERROR();
724 }
725}
726
727// Test enabling the GL_EXT_unpack_subimage extension
728TEST_P(WebGLCompatibilityTest, EnablePackUnpackSubImageExtension)
729{
730 EXPECT_FALSE(extensionEnabled("GL_EXT_unpack_subimage"));
731
732 // This extensions become core in in ES3/WebGL2.
733 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
734
735 constexpr GLenum parameters[] = {
736 GL_UNPACK_ROW_LENGTH_EXT, GL_UNPACK_SKIP_ROWS_EXT, GL_UNPACK_SKIP_PIXELS_EXT,
737 };
738
739 for (GLenum param : parameters)
740 {
741 GLint resultI = 0;
742 glGetIntegerv(param, &resultI);
743 EXPECT_GL_ERROR(GL_INVALID_ENUM);
744
745 GLfloat resultF = 0.0f;
746 glGetFloatv(param, &resultF);
747 EXPECT_GL_ERROR(GL_INVALID_ENUM);
748
749 glPixelStorei(param, 0);
750 EXPECT_GL_ERROR(GL_INVALID_ENUM);
751 }
752
753 if (extensionRequestable("GL_EXT_unpack_subimage"))
754 {
755 glRequestExtensionANGLE("GL_EXT_unpack_subimage");
756 EXPECT_GL_NO_ERROR();
757
758 for (GLenum param : parameters)
759 {
760 GLint resultI = 0;
761 glGetIntegerv(param, &resultI);
762
763 GLfloat resultF = 0.0f;
764 glGetFloatv(param, &resultF);
765
766 glPixelStorei(param, 0);
767
768 EXPECT_GL_NO_ERROR();
769 }
770 }
771}
772
773// Test enabling the GL_NV_pack_subimage extension
774TEST_P(WebGLCompatibilityTest, EnablePackPackSubImageExtension)
775{
776 EXPECT_FALSE(extensionEnabled("GL_NV_pack_subimage"));
777
778 // This extensions become core in in ES3/WebGL2.
779 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
780
781 constexpr GLenum parameters[] = {
782 GL_PACK_ROW_LENGTH, GL_PACK_SKIP_ROWS, GL_PACK_SKIP_PIXELS,
783 };
784
785 for (GLenum param : parameters)
786 {
787 GLint resultI = 0;
788 glGetIntegerv(param, &resultI);
789 EXPECT_GL_ERROR(GL_INVALID_ENUM);
790
791 GLfloat resultF = 0.0f;
792 glGetFloatv(param, &resultF);
793 EXPECT_GL_ERROR(GL_INVALID_ENUM);
794
795 glPixelStorei(param, 0);
796 EXPECT_GL_ERROR(GL_INVALID_ENUM);
797 }
798
799 if (extensionRequestable("GL_NV_pack_subimage"))
800 {
801 glRequestExtensionANGLE("GL_NV_pack_subimage");
802 EXPECT_GL_NO_ERROR();
803
804 for (GLenum param : parameters)
805 {
806 GLint resultI = 0;
807 glGetIntegerv(param, &resultI);
808
809 GLfloat resultF = 0.0f;
810 glGetFloatv(param, &resultF);
811
812 glPixelStorei(param, 0);
813
814 EXPECT_GL_NO_ERROR();
815 }
816 }
817}
818
Geoff Langa0e0aeb2017-04-12 15:06:29 -0400819// Verify that the context generates the correct error when the framebuffer attachments are
820// different sizes
Corentin Wallezc3bc9842017-10-11 15:15:59 -0400821TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMismatch)
Geoff Langa0e0aeb2017-04-12 15:06:29 -0400822{
823 GLFramebuffer fbo;
824 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
825
826 GLTexture textures[2];
827 glBindTexture(GL_TEXTURE_2D, textures[0]);
828 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
829 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
830
831 ASSERT_GL_NO_ERROR();
832 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
833
834 GLRenderbuffer renderbuffer;
835 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
836 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3);
837 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
838
839 ASSERT_GL_NO_ERROR();
840 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
841 glCheckFramebufferStatus(GL_FRAMEBUFFER));
842
843 if (extensionRequestable("GL_EXT_draw_buffers"))
844 {
845 glRequestExtensionANGLE("GL_EXT_draw_buffers");
846 EXPECT_GL_NO_ERROR();
847 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
848
849 glBindTexture(GL_TEXTURE_2D, textures[1]);
850 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
851 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
852 ASSERT_GL_NO_ERROR();
853
854 ASSERT_GL_NO_ERROR();
855 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
856 glCheckFramebufferStatus(GL_FRAMEBUFFER));
857
858 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
859
860 ASSERT_GL_NO_ERROR();
861 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
862
863 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
864
865 ASSERT_GL_NO_ERROR();
866 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
867 glCheckFramebufferStatus(GL_FRAMEBUFFER));
868 }
869}
870
Corentin Wallez327411e2016-12-09 11:09:17 -0500871// Test that client-side array buffers are forbidden in WebGL mode
872TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
873{
874 const std::string &vert =
875 "attribute vec3 a_pos;\n"
876 "void main()\n"
877 "{\n"
878 " gl_Position = vec4(a_pos, 1.0);\n"
879 "}\n";
880
881 const std::string &frag =
882 "precision highp float;\n"
883 "void main()\n"
884 "{\n"
885 " gl_FragColor = vec4(1.0);\n"
886 "}\n";
887
888 ANGLE_GL_PROGRAM(program, vert, frag);
889
890 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
891 ASSERT_NE(-1, posLocation);
892 glUseProgram(program.get());
893
894 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -0500895 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -0500896 glEnableVertexAttribArray(posLocation);
897
898 ASSERT_GL_NO_ERROR();
899 glDrawArrays(GL_TRIANGLES, 0, 6);
900 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
901}
902
903// Test that client-side element array buffers are forbidden in WebGL mode
904TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
905{
906 const std::string &vert =
907 "attribute vec3 a_pos;\n"
908 "void main()\n"
909 "{\n"
910 " gl_Position = vec4(a_pos, 1.0);\n"
911 "}\n";
912
913 const std::string &frag =
914 "precision highp float;\n"
915 "void main()\n"
916 "{\n"
917 " gl_FragColor = vec4(1.0);\n"
918 "}\n";
919
920 ANGLE_GL_PROGRAM(program, vert, frag);
921
922 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
923 ASSERT_NE(-1, posLocation);
924 glUseProgram(program.get());
925
926 const auto &vertices = GetQuadVertices();
927
928 GLBuffer vertexBuffer;
929 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
930 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
931 GL_STATIC_DRAW);
932
933 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
934 glEnableVertexAttribArray(posLocation);
935
Corentin Wallez327411e2016-12-09 11:09:17 -0500936 ASSERT_GL_NO_ERROR();
Corentin Wallezded1b5a2017-03-09 18:58:48 -0500937
938 // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also
939 // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate
940 // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check.
941 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1)));
Corentin Wallez327411e2016-12-09 11:09:17 -0500942 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
943}
944
Corentin Wallez672f7f32017-06-15 17:42:17 -0400945// Test that client-side array buffers are forbidden even if the program doesn't use the attribute
946TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes)
947{
948 const std::string &vert =
949 "void main()\n"
950 "{\n"
951 " gl_Position = vec4(1.0);\n"
952 "}\n";
953
954 const std::string &frag =
955 "precision highp float;\n"
956 "void main()\n"
957 "{\n"
958 " gl_FragColor = vec4(1.0);\n"
959 "}\n";
960
961 ANGLE_GL_PROGRAM(program, vert, frag);
962
963 glUseProgram(program.get());
964
965 const auto &vertices = GetQuadVertices();
966 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
967 glEnableVertexAttribArray(0);
968
969 ASSERT_GL_NO_ERROR();
970 glDrawArrays(GL_TRIANGLES, 0, 6);
971 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
972}
973
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500974// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
975TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
976{
977 // Run the test in an FBO to make sure we have some stencil bits.
978 GLRenderbuffer renderbuffer;
979 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
980 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
981
982 GLFramebuffer framebuffer;
983 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
984 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
985 renderbuffer.get());
986
987 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
988 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
989 glUseProgram(program.get());
990 ASSERT_GL_NO_ERROR();
991
992 // Having ref and mask the same for front and back is valid.
993 glStencilMask(255);
994 glStencilFunc(GL_ALWAYS, 0, 255);
995 glDrawArrays(GL_TRIANGLES, 0, 6);
996 ASSERT_GL_NO_ERROR();
997
998 // Having a different front - back write mask generates an error.
999 glStencilMaskSeparate(GL_FRONT, 1);
1000 glDrawArrays(GL_TRIANGLES, 0, 6);
1001 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1002
1003 // Setting both write masks separately to the same value is valid.
1004 glStencilMaskSeparate(GL_BACK, 1);
1005 glDrawArrays(GL_TRIANGLES, 0, 6);
1006 ASSERT_GL_NO_ERROR();
1007
1008 // Having a different stencil front - back mask generates an error
1009 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
1010 glDrawArrays(GL_TRIANGLES, 0, 6);
1011 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1012
1013 // Setting both masks separately to the same value is valid.
1014 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
1015 glDrawArrays(GL_TRIANGLES, 0, 6);
1016 ASSERT_GL_NO_ERROR();
1017
1018 // Having a different stencil front - back reference generates an error
1019 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
1020 glDrawArrays(GL_TRIANGLES, 0, 6);
1021 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1022
1023 // Setting both references separately to the same value is valid.
1024 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
1025 glDrawArrays(GL_TRIANGLES, 0, 6);
1026 ASSERT_GL_NO_ERROR();
1027
1028 // Using different stencil funcs, everything being equal is valid.
1029 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
1030 glDrawArrays(GL_TRIANGLES, 0, 6);
1031 ASSERT_GL_NO_ERROR();
1032}
1033
Corentin Wallez506fc9c2016-12-21 16:53:33 -05001034// Test that GL_FIXED is forbidden
1035TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
1036{
1037 GLBuffer buffer;
1038 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1039 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1040
1041 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
1042 ASSERT_GL_NO_ERROR();
1043
1044 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
1045 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1046}
1047
1048// Test the WebGL limit of 255 for the attribute stride
1049TEST_P(WebGLCompatibilityTest, MaxStride)
1050{
1051 GLBuffer buffer;
1052 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1053 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
1054
1055 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
1056 ASSERT_GL_NO_ERROR();
1057
1058 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
1059 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1060}
1061
Corentin Wallezfd456442016-12-21 17:57:00 -05001062// Test the checks for OOB reads in the vertex buffers, non-instanced version
1063TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
1064{
1065 const std::string &vert =
1066 "attribute float a_pos;\n"
1067 "void main()\n"
1068 "{\n"
1069 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1070 "}\n";
1071
1072 const std::string &frag =
1073 "precision highp float;\n"
1074 "void main()\n"
1075 "{\n"
1076 " gl_FragColor = vec4(1.0);\n"
1077 "}\n";
1078
1079 ANGLE_GL_PROGRAM(program, vert, frag);
Corentin Wallezfd456442016-12-21 17:57:00 -05001080 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1081 ASSERT_NE(-1, posLocation);
1082 glUseProgram(program.get());
1083
1084 GLBuffer buffer;
1085 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1086 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1087
1088 glEnableVertexAttribArray(posLocation);
1089
1090 const uint8_t* zeroOffset = nullptr;
1091
1092 // Test touching the last element is valid.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001093 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
Corentin Wallezfd456442016-12-21 17:57:00 -05001094 glDrawArrays(GL_POINTS, 0, 4);
1095 ASSERT_GL_NO_ERROR();
1096
1097 // Test touching the last element + 1 is invalid.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001098 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
Corentin Wallezfd456442016-12-21 17:57:00 -05001099 glDrawArrays(GL_POINTS, 0, 4);
1100 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1101
1102 // Test touching the last element is valid, using a stride.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001103 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
Corentin Wallezfd456442016-12-21 17:57:00 -05001104 glDrawArrays(GL_POINTS, 0, 4);
1105 ASSERT_GL_NO_ERROR();
1106
1107 // Test touching the last element + 1 is invalid, using a stride.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001108 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
Corentin Wallezfd456442016-12-21 17:57:00 -05001109 glDrawArrays(GL_POINTS, 0, 4);
1110 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1111
1112 // Test any offset is valid if no vertices are drawn.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001113 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
Corentin Wallezfd456442016-12-21 17:57:00 -05001114 glDrawArrays(GL_POINTS, 0, 0);
1115 ASSERT_GL_NO_ERROR();
Corentin Wallez91c8de82017-10-12 16:32:44 -04001116
1117 // Test a case of overflow that could give a max vertex that's negative
1118 constexpr GLint kIntMax = std::numeric_limits<GLint>::max();
1119 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 0);
1120 glDrawArrays(GL_POINTS, kIntMax, kIntMax);
1121 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1122}
1123
1124// Test the checks for OOB reads in the vertex buffers, instanced version
1125TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
1126{
1127 const std::string &vert =
1128 "attribute float a_pos;\n"
1129 "attribute float a_w;\n"
1130 "void main()\n"
1131 "{\n"
1132 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1133 "}\n";
1134
1135 const std::string &frag =
1136 "precision highp float;\n"
1137 "void main()\n"
1138 "{\n"
1139 " gl_FragColor = vec4(1.0);\n"
1140 "}\n";
1141
1142 ANGLE_GL_PROGRAM(program, vert, frag);
1143 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1144 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1145 ASSERT_NE(-1, posLocation);
1146 ASSERT_NE(-1, wLocation);
1147 glUseProgram(program.get());
1148
1149 GLBuffer buffer;
1150 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1151 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1152
1153 glEnableVertexAttribArray(posLocation);
1154 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1155 glVertexAttribDivisor(posLocation, 0);
1156
1157 glEnableVertexAttribArray(wLocation);
1158 glVertexAttribDivisor(wLocation, 1);
1159
1160 const uint8_t* zeroOffset = nullptr;
1161
1162 // Test touching the last element is valid.
1163 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1164 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1165 ASSERT_GL_NO_ERROR();
1166
1167 // Test touching the last element + 1 is invalid.
1168 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1169 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1170 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1171
1172 // Test touching the last element is valid, using a stride.
1173 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1174 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1175 ASSERT_GL_NO_ERROR();
1176
1177 // Test touching the last element + 1 is invalid, using a stride.
1178 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1179 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1180 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1181
1182 // Test any offset is valid if no vertices are drawn.
1183 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1184 glDrawArraysInstanced(GL_POINTS, 0, 0, 1);
1185 ASSERT_GL_NO_ERROR();
1186
1187 // Test any offset is valid if no primitives are drawn.
1188 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1189 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1190 ASSERT_GL_NO_ERROR();
1191}
1192
1193// Test the checks for OOB reads in the vertex buffers, ANGLE_instanced_arrays version
1194TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsInstancedANGLE)
1195{
1196 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_ANGLE_instanced_arrays"));
1197 glRequestExtensionANGLE("GL_ANGLE_instanced_arrays");
1198 EXPECT_GL_NO_ERROR();
1199
1200 const std::string &vert =
1201 "attribute float a_pos;\n"
1202 "attribute float a_w;\n"
1203 "void main()\n"
1204 "{\n"
1205 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1206 "}\n";
1207
1208 const std::string &frag =
1209 "precision highp float;\n"
1210 "void main()\n"
1211 "{\n"
1212 " gl_FragColor = vec4(1.0);\n"
1213 "}\n";
1214
1215 ANGLE_GL_PROGRAM(program, vert, frag);
1216 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1217 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1218 ASSERT_NE(-1, posLocation);
1219 ASSERT_NE(-1, wLocation);
1220 glUseProgram(program.get());
1221
1222 GLBuffer buffer;
1223 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1224 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1225
1226 glEnableVertexAttribArray(posLocation);
1227 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1228 glVertexAttribDivisorANGLE(posLocation, 0);
1229
1230 glEnableVertexAttribArray(wLocation);
1231 glVertexAttribDivisorANGLE(wLocation, 1);
1232
1233 const uint8_t* zeroOffset = nullptr;
1234
1235 // Test touching the last element is valid.
1236 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1237 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1238 ASSERT_GL_NO_ERROR();
1239
1240 // Test touching the last element + 1 is invalid.
1241 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1242 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1243 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1244
1245 // Test touching the last element is valid, using a stride.
1246 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1247 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1248 ASSERT_GL_NO_ERROR();
1249
1250 // Test touching the last element + 1 is invalid, using a stride.
1251 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1252 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1253 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1254
1255 // Test any offset is valid if no vertices are drawn.
1256 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1257 glDrawArraysInstancedANGLE(GL_POINTS, 0, 0, 1);
1258 ASSERT_GL_NO_ERROR();
1259
1260 // Test any offset is valid if no primitives are drawn.
1261 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1262 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 0);
1263 ASSERT_GL_NO_ERROR();
Corentin Wallezfd456442016-12-21 17:57:00 -05001264}
1265
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001266// Test the checks for OOB reads in the index buffer
1267TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -05001268{
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001269 const std::string &vert =
1270 "attribute float a_pos;\n"
1271 "void main()\n"
1272 "{\n"
1273 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1274 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -05001275
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001276 const std::string &frag =
1277 "precision highp float;\n"
1278 "void main()\n"
1279 "{\n"
1280 " gl_FragColor = vec4(1.0);\n"
1281 "}\n";
1282
1283 ANGLE_GL_PROGRAM(program, vert, frag);
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001284 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1285 ASSERT_NE(-1, posLocation);
1286 glUseProgram(program.get());
1287
1288 GLBuffer vertexBuffer;
1289 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1290 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1291
1292 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001293 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001294
1295 const uint8_t *zeroOffset = nullptr;
1296 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
1297
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001298 GLBuffer indexBuffer;
1299 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1300 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -05001301 ASSERT_GL_NO_ERROR();
1302
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001303 // Test touching the last index is valid
1304 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1305 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -05001306
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001307 // Test touching the last + 1 element is invalid
1308 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
1309 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -05001310
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001311 // Test any offset if valid if count is zero
1312 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
1313 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -05001314
1315 // Test touching the first index is valid
1316 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1317 ASSERT_GL_NO_ERROR();
1318
1319 // Test touching the first - 1 index is invalid
1320 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
1321 // the historic behavior of WebGL implementations
1322 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
1323 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -05001324}
1325
Corentin Wallez91c8de82017-10-12 16:32:44 -04001326// Test the checks for OOB in vertex buffers caused by indices, non-instanced version
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001327TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInVertexBuffer)
1328{
1329 const std::string &vert =
1330 "attribute float a_pos;\n"
1331 "void main()\n"
1332 "{\n"
1333 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1334 "}\n";
1335
1336 const std::string &frag =
1337 "precision highp float;\n"
1338 "void main()\n"
1339 "{\n"
1340 " gl_FragColor = vec4(1.0);\n"
1341 "}\n";
1342
1343 ANGLE_GL_PROGRAM(program, vert, frag);
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001344 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1345 ASSERT_NE(-1, posLocation);
1346 glUseProgram(program.get());
1347
1348 GLBuffer vertexBuffer;
1349 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1350 glBufferData(GL_ARRAY_BUFFER, 8, nullptr, GL_STATIC_DRAW);
1351
1352 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001353 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001354
1355 const uint8_t *zeroOffset = nullptr;
1356 const uint8_t testIndices[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 255};
1357
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001358 GLBuffer indexBuffer;
1359 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1360 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(testIndices), testIndices, GL_STATIC_DRAW);
1361 ASSERT_GL_NO_ERROR();
1362
1363 // Test touching the end of the vertex buffer is valid
1364 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 7);
1365 ASSERT_GL_NO_ERROR();
1366
1367 // Test touching just after the end of the vertex buffer is invalid
1368 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 8);
1369 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1370
1371 // Test touching the whole vertex buffer is valid
1372 glDrawElements(GL_POINTS, 8, GL_UNSIGNED_BYTE, zeroOffset + 0);
1373 ASSERT_GL_NO_ERROR();
1374
1375 // Test an index that would be negative
1376 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 9);
1377 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1378}
1379
Frank Henigman6137ddc2017-02-10 18:55:07 -05001380// Test depth range with 'near' more or less than 'far.'
1381TEST_P(WebGLCompatibilityTest, DepthRange)
1382{
1383 glDepthRangef(0, 1);
1384 ASSERT_GL_NO_ERROR();
1385
1386 glDepthRangef(.5, .5);
1387 ASSERT_GL_NO_ERROR();
1388
1389 glDepthRangef(1, 0);
1390 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1391}
1392
Frank Henigman146e8a12017-03-02 23:22:37 -05001393// Test all blend function combinations.
1394// In WebGL it is invalid to combine constant color with constant alpha.
1395TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
1396{
1397 constexpr GLenum srcFunc[] = {
1398 GL_ZERO,
1399 GL_ONE,
1400 GL_SRC_COLOR,
1401 GL_ONE_MINUS_SRC_COLOR,
1402 GL_DST_COLOR,
1403 GL_ONE_MINUS_DST_COLOR,
1404 GL_SRC_ALPHA,
1405 GL_ONE_MINUS_SRC_ALPHA,
1406 GL_DST_ALPHA,
1407 GL_ONE_MINUS_DST_ALPHA,
1408 GL_CONSTANT_COLOR,
1409 GL_ONE_MINUS_CONSTANT_COLOR,
1410 GL_CONSTANT_ALPHA,
1411 GL_ONE_MINUS_CONSTANT_ALPHA,
1412 GL_SRC_ALPHA_SATURATE,
1413 };
1414
1415 constexpr GLenum dstFunc[] = {
1416 GL_ZERO, GL_ONE,
1417 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1418 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1419 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1420 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
1421 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
1422 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
1423 };
1424
1425 for (GLenum src : srcFunc)
1426 {
1427 for (GLenum dst : dstFunc)
1428 {
1429 glBlendFunc(src, dst);
1430 CheckBlendFunctions(src, dst);
1431 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
1432 CheckBlendFunctions(src, dst);
1433 }
1434 }
1435}
1436
Geoff Langfc32e8b2017-05-31 14:16:59 -04001437// Test that binding/querying uniforms and attributes with invalid names generates errors
1438TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
1439{
1440 const std::string validAttribName =
1441 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
1442 const std::string validUniformName =
1443 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
Geoff Langa71a98e2017-06-19 15:15:00 -04001444 std::vector<char> invalidSet = {'"', '$', '`', '@', '\''};
1445 if (getClientMajorVersion() < 3)
1446 {
1447 invalidSet.push_back('\\');
1448 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04001449
1450 std::string vert = "attribute float ";
1451 vert += validAttribName;
1452 vert +=
1453 ";\n"
1454 "void main()\n"
1455 "{\n"
1456 " gl_Position = vec4(1.0);\n"
1457 "}\n";
1458
1459 std::string frag =
1460 "precision highp float;\n"
1461 "uniform vec4 ";
1462 frag += validUniformName;
Geoff Langcab92ee2017-07-19 17:32:07 -04001463 // Insert illegal characters into comments
Geoff Langfc32e8b2017-05-31 14:16:59 -04001464 frag +=
1465 ";\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001466 " // $ \" @ /*\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001467 "void main()\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001468 "{/*\n"
1469 " ` @ $\n"
1470 " */gl_FragColor = vec4(1.0);\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001471 "}\n";
1472
1473 ANGLE_GL_PROGRAM(program, vert, frag);
1474 EXPECT_GL_NO_ERROR();
1475
1476 for (char invalidChar : invalidSet)
1477 {
1478 std::string invalidName = validAttribName + invalidChar;
1479 glGetAttribLocation(program, invalidName.c_str());
1480 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1481 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1482
1483 glBindAttribLocation(program, 0, invalidName.c_str());
1484 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1485 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1486 }
1487
1488 for (char invalidChar : invalidSet)
1489 {
1490 std::string invalidName = validUniformName + invalidChar;
1491 glGetUniformLocation(program, invalidName.c_str());
1492 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1493 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1494 }
1495
1496 for (char invalidChar : invalidSet)
1497 {
1498 std::string invalidAttribName = validAttribName + invalidChar;
1499 const char *invalidVert[] = {
1500 "attribute float ",
1501 invalidAttribName.c_str(),
1502 ";\n",
1503 "void main()\n",
1504 "{\n",
1505 " gl_Position = vec4(1.0);\n",
1506 "}\n",
1507 };
1508
1509 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1510 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
1511 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1512 glDeleteShader(shader);
1513 }
1514}
1515
Geoff Langcab92ee2017-07-19 17:32:07 -04001516// Test that line continuation is handled correctly when valdiating shader source
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -07001517TEST_P(WebGLCompatibilityTest, ShaderSourceLineContinuation)
1518{
1519 // Verify that a line continuation character (i.e. backslash) cannot be used
1520 // within a preprocessor directive in a ES2 context.
1521 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
1522
1523 const char *validVert =
1524 "#define foo this is a test\n"
1525 "precision mediump float;\n"
1526 "void main()\n"
1527 "{\n"
1528 " gl_Position = vec4(1.0);\n"
1529 "}\n";
1530
1531 const char *invalidVert =
1532 "#define foo this \\n"
1533 " is a test\n"
1534 "precision mediump float;\n"
1535 "void main()\n"
1536 "{\n"
1537 " gl_Position = vec4(1.0);\n"
1538 "}\n";
1539
1540 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1541 glShaderSource(shader, 1, &validVert, nullptr);
1542 EXPECT_GL_NO_ERROR();
1543
1544 glShaderSource(shader, 1, &invalidVert, nullptr);
1545 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1546 glDeleteShader(shader);
1547}
1548
1549// Test that line continuation is handled correctly when valdiating shader source
Geoff Langcab92ee2017-07-19 17:32:07 -04001550TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
1551{
1552 const char *validVert =
1553 "#version 300 es\n"
1554 "precision mediump float;\n"
1555 "\n"
1556 "void main ()\n"
1557 "{\n"
1558 " float f\\\n"
1559 "oo = 1.0;\n"
1560 " gl_Position = vec4(foo);\n"
1561 "}\n";
1562
1563 const char *invalidVert =
1564 "#version 300 es\n"
1565 "precision mediump float;\n"
1566 "\n"
1567 "void main ()\n"
1568 "{\n"
1569 " float f\\$\n"
1570 "oo = 1.0;\n"
1571 " gl_Position = vec4(foo);\n"
1572 "}\n";
1573
1574 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1575 glShaderSource(shader, 1, &validVert, nullptr);
1576 EXPECT_GL_NO_ERROR();
1577 glShaderSource(shader, 1, &invalidVert, nullptr);
1578 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1579 glDeleteShader(shader);
1580}
1581
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001582// Tests bindAttribLocations for reserved prefixes and length limits
1583TEST_P(WebGLCompatibilityTest, BindAttribLocationLimitation)
1584{
1585 constexpr int maxLocStringLength = 256;
1586 const std::string tooLongString(maxLocStringLength + 1, '_');
1587
1588 glBindAttribLocation(0, 0, "_webgl_var");
1589
1590 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1591
1592 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
1593
1594 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1595}
1596
Corentin Wallez0dc97812017-06-22 14:38:44 -04001597// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001598TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1599{
1600 const std::string &vert =
1601 "attribute float a_pos;\n"
1602 "void main()\n"
1603 "{\n"
1604 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1605 "}\n";
1606
1607 const std::string &frag =
1608 "precision highp float;\n"
1609 "void main()\n"
1610 "{\n"
1611 " gl_FragColor = vec4(1.0);\n"
1612 "}\n";
1613
1614 ANGLE_GL_PROGRAM(program, vert, frag);
1615
1616 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1617 ASSERT_NE(-1, posLocation);
1618
1619 glUseProgram(program.get());
1620
1621 GLBuffer buffer;
1622 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1623 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1624
1625 glEnableVertexAttribArray(posLocation);
1626 glVertexAttribDivisor(posLocation, 1);
1627
Geoff Lang407d4e72017-04-12 14:54:11 -04001628 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1629 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04001630 ASSERT_GL_NO_ERROR();
1631}
1632
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001633// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1634TEST_P(WebGLCompatibilityTest, NPOT)
1635{
1636 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1637
1638 // Create a texture and set an NPOT mip 0, should always be acceptable.
1639 GLTexture texture;
1640 glBindTexture(GL_TEXTURE_2D, texture.get());
1641 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1642 ASSERT_GL_NO_ERROR();
1643
1644 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1645 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1646 if (getClientMajorVersion() < 3)
1647 {
1648 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1649 }
1650 else
1651 {
1652 ASSERT_GL_NO_ERROR();
1653 }
1654
1655 if (extensionRequestable("GL_OES_texture_npot"))
1656 {
1657 glRequestExtensionANGLE("GL_OES_texture_npot");
1658 ASSERT_GL_NO_ERROR();
1659
1660 // Try again to set NPOT mip 1
1661 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1662 ASSERT_GL_NO_ERROR();
1663 }
1664}
1665
Jamie Madillcad97ee2017-02-02 18:52:44 -05001666template <typename T>
1667void FillTexture2D(GLuint texture,
1668 GLsizei width,
1669 GLsizei height,
1670 const T &onePixelData,
1671 GLint level,
1672 GLint internalFormat,
1673 GLenum format,
1674 GLenum type)
1675{
1676 std::vector<T> allPixelsData(width * height, onePixelData);
1677
1678 glBindTexture(GL_TEXTURE_2D, texture);
1679 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
1680 allPixelsData.data());
1681 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1682 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1683 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1684 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1685}
1686
Frank Henigman875bbba2017-02-08 16:38:17 -05001687// Test that unset gl_Position defaults to (0,0,0,0).
1688TEST_P(WebGLCompatibilityTest, DefaultPosition)
1689{
1690 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
1691 // and green otherwise. The center of each quadrant will be red if and only if all
1692 // four corners are red.
1693 const std::string vertexShader =
1694 "attribute vec3 pos;\n"
1695 "varying vec4 color;\n"
1696 "void main() {\n"
1697 " if (gl_Position == vec4(0,0,0,0)) {\n"
1698 " color = vec4(1,0,0,1);\n"
1699 " } else {\n"
1700 " color = vec4(0,1,0,1);\n"
1701 " }\n"
1702 " gl_Position = vec4(pos,1);\n"
1703 "}\n";
1704
1705 const std::string fragmentShader =
1706 "precision mediump float;\n"
1707 "varying vec4 color;\n"
1708 "void main() {\n"
1709 " gl_FragColor = color;\n"
1710 "}\n";
1711
1712 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1713 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
1714 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1715 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1716 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1717 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1718}
1719
Jamie Madilla4595b82017-01-11 17:36:34 -05001720// Tests that a rendering feedback loop triggers a GL error under WebGL.
1721// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
1722TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
1723{
1724 const std::string vertexShader =
1725 "attribute vec4 a_position;\n"
1726 "varying vec2 v_texCoord;\n"
1727 "void main() {\n"
1728 " gl_Position = a_position;\n"
1729 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
1730 "}\n";
1731
1732 const std::string fragmentShader =
1733 "precision mediump float;\n"
1734 "varying vec2 v_texCoord;\n"
1735 "uniform sampler2D u_texture;\n"
1736 "void main() {\n"
1737 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
1738 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
1739 "}\n";
1740
1741 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001742 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001743
1744 ASSERT_GL_NO_ERROR();
1745
1746 GLFramebuffer framebuffer;
1747 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1748 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1749
1750 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1751
1752 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1753
1754 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
1755 ASSERT_NE(-1, uniformLoc);
1756
1757 glUseProgram(program.get());
1758 glUniform1i(uniformLoc, 0);
1759 glDisable(GL_BLEND);
1760 glDisable(GL_DEPTH_TEST);
1761 ASSERT_GL_NO_ERROR();
1762
1763 // Drawing with a texture that is also bound to the current framebuffer should fail
1764 glBindTexture(GL_TEXTURE_2D, texture.get());
1765 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1766 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1767
1768 // Ensure that the texture contents did not change after the previous render
1769 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1770 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1771 ASSERT_GL_NO_ERROR();
1772 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1773
1774 // Drawing when texture is bound to an inactive uniform should succeed
1775 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001776 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001777
1778 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1779 glActiveTexture(GL_TEXTURE1);
1780 glBindTexture(GL_TEXTURE_2D, texture.get());
1781 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1782 ASSERT_GL_NO_ERROR();
1783 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1784}
1785
Bryan Bernhart58806562017-01-05 13:09:31 -08001786// Test for the max draw buffers and color attachments.
1787TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
1788{
1789 // This test only applies to ES2.
1790 if (getClientMajorVersion() != 2)
1791 {
1792 return;
1793 }
1794
1795 GLFramebuffer fbo[2];
1796 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
1797
1798 // Test that is valid when we bind with a single attachment point.
1799 GLTexture texture;
1800 glBindTexture(GL_TEXTURE_2D, texture.get());
1801 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1802 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1803 ASSERT_GL_NO_ERROR();
1804
1805 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
1806 // attachment point.
1807 if (extensionRequestable("GL_EXT_draw_buffers"))
1808 {
1809 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1810 EXPECT_GL_NO_ERROR();
1811 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1812
1813 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
1814
1815 GLTexture texture2;
1816 glBindTexture(GL_TEXTURE_2D, texture2.get());
1817 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1818 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
1819 0);
1820 ASSERT_GL_NO_ERROR();
1821 }
1822}
1823
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001824// Test that the offset in the index buffer is forced to be a multiple of the element size
1825TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
1826{
1827 const std::string &vert =
1828 "attribute vec3 a_pos;\n"
1829 "void main()\n"
1830 "{\n"
1831 " gl_Position = vec4(a_pos, 1.0);\n"
1832 "}\n";
1833
1834 const std::string &frag =
1835 "precision highp float;\n"
1836 "void main()\n"
1837 "{\n"
1838 " gl_FragColor = vec4(1.0);\n"
1839 "}\n";
1840
1841 ANGLE_GL_PROGRAM(program, vert, frag);
1842
1843 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1844 ASSERT_NE(-1, posLocation);
1845 glUseProgram(program.get());
1846
1847 const auto &vertices = GetQuadVertices();
1848
1849 GLBuffer vertexBuffer;
1850 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1851 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1852 GL_STATIC_DRAW);
1853
1854 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1855 glEnableVertexAttribArray(posLocation);
1856
1857 GLBuffer indexBuffer;
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001858 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001859 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1860 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1861
1862 ASSERT_GL_NO_ERROR();
1863
1864 const char *zeroIndices = nullptr;
1865
1866 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1867 ASSERT_GL_NO_ERROR();
1868
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001869 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001870 ASSERT_GL_NO_ERROR();
1871
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001872 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices + 1);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001873 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1874}
1875
1876// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1877// size
1878TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1879{
1880 const char *zeroOffset = nullptr;
1881
1882 // Base case, vector of two floats
1883 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1884 ASSERT_GL_NO_ERROR();
1885
1886 // Test setting a non-multiple offset
1887 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1888 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1889 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1890 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1891 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1892 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1893
1894 // Test setting a non-multiple stride
1895 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1896 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1897 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1898 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1899 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1900 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1901}
1902
Jamie Madillcad97ee2017-02-02 18:52:44 -05001903void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1904 const std::array<GLenum, 2> &drawBuffers,
1905 GLenum expectedError)
1906{
1907 glDrawBuffersEXT(2, drawBuffers.data());
1908
1909 // Make sure framebuffer is complete before feedback loop detection
1910 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1911
1912 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1913
1914 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1915 // it should be NO_ERROR"
1916 EXPECT_GL_ERROR(expectedError);
1917}
1918
1919// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1920// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1921TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1922{
1923 const std::string vertexShader =
1924 "attribute vec4 aPosition;\n"
1925 "varying vec2 texCoord;\n"
1926 "void main() {\n"
1927 " gl_Position = aPosition;\n"
1928 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1929 "}\n";
1930
1931 const std::string fragmentShader =
1932 "#extension GL_EXT_draw_buffers : require\n"
1933 "precision mediump float;\n"
1934 "uniform sampler2D tex;\n"
1935 "varying vec2 texCoord;\n"
1936 "void main() {\n"
1937 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1938 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1939 "}\n";
1940
1941 GLsizei width = 8;
1942 GLsizei height = 8;
1943
1944 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1945 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1946 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1947 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1948 {
1949 // No WEBGL_draw_buffers support -- this is legal.
1950 return;
1951 }
1952
1953 GLint maxDrawBuffers = 0;
1954 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1955
1956 if (maxDrawBuffers < 2)
1957 {
1958 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1959 return;
1960 }
1961
1962 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1963 glUseProgram(program.get());
1964 glViewport(0, 0, width, height);
1965
1966 GLTexture tex0;
1967 GLTexture tex1;
1968 GLFramebuffer fbo;
1969 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1970 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1971 ASSERT_GL_NO_ERROR();
1972
1973 glBindTexture(GL_TEXTURE_2D, tex1.get());
1974 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1975 ASSERT_NE(-1, texLoc);
1976 glUniform1i(texLoc, 0);
1977 ASSERT_GL_NO_ERROR();
1978
1979 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1980 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1981 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1982 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1983
1984 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1985 GL_INVALID_OPERATION);
1986 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1987 GL_INVALID_OPERATION);
1988 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1989}
1990
Jamie Madill07be8bf2017-02-02 19:59:57 -05001991// Test tests that texture copying feedback loops are properly rejected in WebGL.
1992// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1993TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1994{
1995 GLTexture texture;
1996 glBindTexture(GL_TEXTURE_2D, texture.get());
1997 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1999 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2000 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2001 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2002
2003 GLTexture texture2;
2004 glBindTexture(GL_TEXTURE_2D, texture2.get());
2005 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2006 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2007 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2008 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2009 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2010
2011 GLFramebuffer framebuffer;
2012 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2013 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2014
2015 // framebuffer should be FRAMEBUFFER_COMPLETE.
2016 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2017 ASSERT_GL_NO_ERROR();
2018
2019 // testing copyTexImage2D
2020
2021 // copyTexImage2D to same texture but different level
2022 glBindTexture(GL_TEXTURE_2D, texture.get());
2023 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
2024 EXPECT_GL_NO_ERROR();
2025
2026 // copyTexImage2D to same texture same level, invalid feedback loop
2027 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2028 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2029
2030 // copyTexImage2D to different texture
2031 glBindTexture(GL_TEXTURE_2D, texture2.get());
2032 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2033 EXPECT_GL_NO_ERROR();
2034
2035 // testing copyTexSubImage2D
2036
2037 // copyTexSubImage2D to same texture but different level
2038 glBindTexture(GL_TEXTURE_2D, texture.get());
2039 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
2040 EXPECT_GL_NO_ERROR();
2041
2042 // copyTexSubImage2D to same texture same level, invalid feedback loop
2043 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2044 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2045
2046 // copyTexSubImage2D to different texture
2047 glBindTexture(GL_TEXTURE_2D, texture2.get());
2048 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2049 EXPECT_GL_NO_ERROR();
2050}
2051
2052void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
2053 const std::array<GLenum, 2> &drawBuffers,
2054 GLenum expectedError)
2055{
2056 glDrawBuffers(2, drawBuffers.data());
2057
2058 // Make sure framebuffer is complete before feedback loop detection
2059 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2060
2061 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
2062
2063 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
2064 // it should be NO_ERROR"
2065 EXPECT_GL_ERROR(expectedError);
2066}
2067
Yuly Novikov817232e2017-02-22 18:36:10 -05002068// Tests invariance matching rules between built in varyings.
2069// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
2070TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
2071{
2072 const std::string vertexShaderVariant =
2073 "varying vec4 v_varying;\n"
2074 "void main()\n"
2075 "{\n"
2076 " gl_PointSize = 1.0;\n"
2077 " gl_Position = v_varying;\n"
2078 "}";
2079 const std::string fragmentShaderInvariantGlFragCoord =
2080 "invariant gl_FragCoord;\n"
2081 "void main()\n"
2082 "{\n"
2083 " gl_FragColor = gl_FragCoord;\n"
2084 "}";
2085 const std::string fragmentShaderInvariantGlPointCoord =
2086 "invariant gl_PointCoord;\n"
2087 "void main()\n"
2088 "{\n"
2089 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
2090 "}";
2091
2092 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
2093 EXPECT_EQ(0u, program);
2094
2095 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
2096 EXPECT_EQ(0u, program);
2097}
2098
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04002099// Tests global namespace conflicts between uniforms and attributes.
2100// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
2101TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
2102{
2103 const std::string vertexShader =
2104 "attribute vec4 foo;\n"
2105 "void main()\n"
2106 "{\n"
2107 " gl_Position = foo;\n"
2108 "}";
2109 const std::string fragmentShader =
2110 "precision mediump float;\n"
2111 "uniform vec4 foo;\n"
2112 "void main()\n"
2113 "{\n"
2114 " gl_FragColor = foo;\n"
2115 "}";
2116
2117 GLuint program = CompileProgram(vertexShader, fragmentShader);
2118 EXPECT_EQ(0u, program);
2119}
2120
Geoff Lang966c9402017-04-18 12:38:27 -04002121// Test dimension and image size validation of compressed textures
2122TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
2123{
2124 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
2125 {
2126 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
2127 }
2128
2129 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
2130 {
2131 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
2132 << std::endl;
2133 return;
2134 }
2135
2136 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
2137
2138 GLTexture texture;
2139 glBindTexture(GL_TEXTURE_2D, texture);
2140
2141 // Regular case, verify that it works
2142 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2143 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2144 ASSERT_GL_NO_ERROR();
2145
2146 // Test various dimensions that are not valid
2147 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
2148 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2149 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2150
2151 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
2152 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2153 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2154
2155 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2156 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2157 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2158
2159 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2160 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2161 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2162
2163 // Test various image sizes that are not valid
2164 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2165 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
2166 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2167
2168 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2169 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
2170 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2171
2172 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
2173 CompressedImageDXT1);
2174 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2175
2176 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
2177 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2178 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2179
2180 // Fill a full mip chain and verify that it works
2181 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2182 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2183 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2184 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2185 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2186 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2187 ASSERT_GL_NO_ERROR();
2188
2189 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2190 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2191 ASSERT_GL_NO_ERROR();
2192
2193 // Test that non-block size sub-uploads are not valid for the 0 mip
2194 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2195 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2196 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2197
2198 // Test that non-block size sub-uploads are valid for if they fill the whole mip
2199 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2200 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2201 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2202 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2203 ASSERT_GL_NO_ERROR();
2204
2205 // Test that if the format miss-matches the texture, an error is generated
2206 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2207 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2208 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2209}
2210
Geoff Lang677bb6f2017-04-05 12:40:40 -04002211TEST_P(WebGLCompatibilityTest, L32FTextures)
2212{
2213 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
2214 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
2215
2216 for (auto extension : FloatingPointTextureExtensions)
2217 {
2218 if (strlen(extension) > 0 && extensionRequestable(extension))
2219 {
2220 glRequestExtensionANGLE(extension);
2221 ASSERT_GL_NO_ERROR();
2222 }
2223
2224 // Unsized L 32F
2225 {
2226 bool texture = extensionEnabled("GL_OES_texture_float");
2227 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2228 bool render = false;
2229 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
2230 textureData, readPixelData);
2231 }
2232
2233 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2234 {
2235 // Sized L 32F
2236 bool texture = extensionEnabled("GL_OES_texture_float") &&
2237 extensionEnabled("GL_EXT_texture_storage");
2238 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2239 bool render = false;
2240 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
2241 render, textureData, readPixelData);
2242 }
2243 }
2244}
2245
2246TEST_P(WebGLCompatibilityTest, A32FTextures)
2247{
2248 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
2249 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
2250
2251 for (auto extension : FloatingPointTextureExtensions)
2252 {
2253 if (strlen(extension) > 0 && extensionRequestable(extension))
2254 {
2255 glRequestExtensionANGLE(extension);
2256 ASSERT_GL_NO_ERROR();
2257 }
2258
2259 // Unsized A 32F
2260 {
2261 bool texture = extensionEnabled("GL_OES_texture_float");
2262 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2263 bool render = false;
2264 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
2265 textureData, readPixelData);
2266 }
2267
2268 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2269 {
2270 // Sized A 32F
2271 bool texture = extensionEnabled("GL_OES_texture_float") &&
2272 extensionEnabled("GL_EXT_texture_storage");
2273 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2274 bool render = false;
2275 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
2276 textureData, readPixelData);
2277 }
2278 }
2279}
2280
2281TEST_P(WebGLCompatibilityTest, LA32FTextures)
2282{
2283 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
2284 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
2285 textureData[1]};
2286
2287 for (auto extension : FloatingPointTextureExtensions)
2288 {
2289 if (strlen(extension) > 0 && extensionRequestable(extension))
2290 {
2291 glRequestExtensionANGLE(extension);
2292 ASSERT_GL_NO_ERROR();
2293 }
2294
2295 // Unsized LA 32F
2296 {
2297 bool texture = extensionEnabled("GL_OES_texture_float");
2298 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2299 bool render = false;
2300 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2301 filter, render, textureData, readPixelData);
2302 }
2303
2304 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2305 {
2306 // Sized LA 32F
2307 bool texture = extensionEnabled("GL_OES_texture_float") &&
2308 extensionEnabled("GL_EXT_texture_storage");
2309 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2310 bool render = false;
2311 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2312 filter, render, textureData, readPixelData);
2313 }
2314 }
2315}
2316
2317TEST_P(WebGLCompatibilityTest, R32FTextures)
2318{
2319 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
2320
2321 for (auto extension : FloatingPointTextureExtensions)
2322 {
2323 if (strlen(extension) > 0 && extensionRequestable(extension))
2324 {
2325 glRequestExtensionANGLE(extension);
2326 ASSERT_GL_NO_ERROR();
2327 }
2328
2329 // Unsized R 32F
2330 {
2331 bool texture =
2332 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
2333 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2334 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2335 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2336 }
2337
2338 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2339 {
2340 // Sized R 32F
2341 bool texture =
2342 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2343 extensionEnabled("GL_EXT_texture_rg") &&
2344 extensionEnabled("GL_EXT_texture_storage"));
2345 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2346 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2347 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2348 }
2349 }
2350}
2351
2352TEST_P(WebGLCompatibilityTest, RG32FTextures)
2353{
2354 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
2355
2356 for (auto extension : FloatingPointTextureExtensions)
2357 {
2358 if (strlen(extension) > 0 && extensionRequestable(extension))
2359 {
2360 glRequestExtensionANGLE(extension);
2361 ASSERT_GL_NO_ERROR();
2362 }
2363
2364 // Unsized RG 32F
2365 {
2366 bool texture =
2367 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
2368 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2369 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2370 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2371 }
2372
2373 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2374 {
2375 // Sized RG 32F
2376 bool texture =
2377 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2378 extensionEnabled("GL_EXT_texture_rg") &&
2379 extensionEnabled("GL_EXT_texture_storage"));
2380 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2381 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2382 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2383 }
2384 }
2385}
2386
2387TEST_P(WebGLCompatibilityTest, RGB32FTextures)
2388{
Geoff Lang40762ef2017-05-08 13:47:03 -04002389 if (IsLinux() && IsIntel())
2390 {
2391 std::cout << "Test skipped on Linux Intel." << std::endl;
2392 return;
2393 }
2394
Geoff Lang677bb6f2017-04-05 12:40:40 -04002395 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
2396
2397 for (auto extension : FloatingPointTextureExtensions)
2398 {
2399 if (strlen(extension) > 0 && extensionRequestable(extension))
2400 {
2401 glRequestExtensionANGLE(extension);
2402 ASSERT_GL_NO_ERROR();
2403 }
2404
2405 // Unsized RGB 32F
2406 {
2407 bool texture = extensionEnabled("GL_OES_texture_float");
2408 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2409 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2410 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
2411 }
2412
2413 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2414 {
2415 // Sized RGBA 32F
2416 bool texture =
2417 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2418 extensionEnabled("GL_EXT_texture_storage"));
2419 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2420 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2421 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
2422 data);
2423 }
2424 }
2425}
2426
2427TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
2428{
2429 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2430
2431 for (auto extension : FloatingPointTextureExtensions)
2432 {
2433 if (strlen(extension) > 0 && extensionRequestable(extension))
2434 {
2435 glRequestExtensionANGLE(extension);
2436 ASSERT_GL_NO_ERROR();
2437 }
2438
2439 // Unsized RGBA 32F
2440 {
2441 bool texture = extensionEnabled("GL_OES_texture_float");
2442 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2443 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2444 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2445 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
2446 }
2447
2448 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2449 {
2450 // Sized RGBA 32F
2451 bool texture =
2452 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2453 extensionEnabled("GL_EXT_texture_storage"));
2454 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2455 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2456 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2457 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
2458 data);
2459 }
2460 }
2461}
2462
2463TEST_P(WebGLCompatibilityTest, R16FTextures)
2464{
2465 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
2466 const GLushort textureData[] = {
2467 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2468 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2469
2470 for (auto extension : FloatingPointTextureExtensions)
2471 {
2472 if (strlen(extension) > 0 && extensionRequestable(extension))
2473 {
2474 glRequestExtensionANGLE(extension);
2475 ASSERT_GL_NO_ERROR();
2476 }
2477
2478 // Unsized R 16F (OES)
2479 {
2480 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2481 extensionEnabled("GL_EXT_texture_rg");
2482 bool filter = getClientMajorVersion() >= 3 ||
2483 extensionEnabled("GL_OES_texture_half_float_linear");
2484 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2485 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2486 textureData, readPixelsData);
2487 }
2488
2489 // Unsized R 16F
2490 {
2491 bool texture = false;
2492 bool filter = false;
2493 bool render = false;
2494 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2495 textureData, readPixelsData);
2496 }
2497
2498 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2499 {
2500 // Sized R 16F
2501 bool texture = getClientMajorVersion() >= 3;
2502 bool filter = getClientMajorVersion() >= 3 ||
2503 extensionEnabled("GL_OES_texture_half_float_linear");
2504 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2505 extensionEnabled("GL_EXT_color_buffer_float");
2506 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2507 textureData, readPixelsData);
2508 }
2509 }
2510}
2511
2512TEST_P(WebGLCompatibilityTest, RG16FTextures)
2513{
2514 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
2515 const GLushort textureData[] = {
2516 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2517 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2518
2519 for (auto extension : FloatingPointTextureExtensions)
2520 {
2521 if (strlen(extension) > 0 && extensionRequestable(extension))
2522 {
2523 glRequestExtensionANGLE(extension);
2524 ASSERT_GL_NO_ERROR();
2525 }
2526
2527 // Unsized RG 16F (OES)
2528 {
2529 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2530 extensionEnabled("GL_EXT_texture_rg");
2531 bool filter = getClientMajorVersion() >= 3 ||
2532 extensionEnabled("GL_OES_texture_half_float_linear");
2533 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
2534 extensionEnabled("GL_EXT_texture_rg");
2535 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2536 textureData, readPixelsData);
2537 }
2538
2539 // Unsized RG 16F
2540 {
2541 bool texture = false;
2542 bool filter = false;
2543 bool render = false;
2544 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2545 textureData, readPixelsData);
2546 }
2547
2548 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2549 {
2550 // Sized RG 16F
2551 bool texture = getClientMajorVersion() >= 3;
2552 bool filter = getClientMajorVersion() >= 3 ||
2553 extensionEnabled("GL_OES_texture_half_float_linear");
2554 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2555 extensionEnabled("GL_EXT_color_buffer_float");
2556 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2557 textureData, readPixelsData);
2558 }
2559 }
2560}
2561
2562TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2563{
Geoff Lang40762ef2017-05-08 13:47:03 -04002564 if (IsOzone() && IsIntel())
2565 {
2566 std::cout << "Test skipped on Intel Ozone." << std::endl;
2567 return;
2568 }
2569
Geoff Lang677bb6f2017-04-05 12:40:40 -04002570 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2571 const GLushort textureData[] = {
2572 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2573 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2574
2575 for (auto extension : FloatingPointTextureExtensions)
2576 {
2577 if (strlen(extension) > 0 && extensionRequestable(extension))
2578 {
2579 glRequestExtensionANGLE(extension);
2580 ASSERT_GL_NO_ERROR();
2581 }
2582
2583 // Unsized RGB 16F (OES)
2584 {
2585 bool texture = extensionEnabled("GL_OES_texture_half_float");
2586 bool filter = getClientMajorVersion() >= 3 ||
2587 extensionEnabled("GL_OES_texture_half_float_linear");
2588 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2589 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2590 textureData, readPixelsData);
2591 }
2592
2593 // Unsized RGB 16F
2594 {
2595 bool texture = false;
2596 bool filter = false;
2597 bool render = false;
2598 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2599 textureData, readPixelsData);
2600 }
2601
2602 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2603 {
2604 // Sized RGB 16F
2605 bool texture = getClientMajorVersion() >= 3;
2606 bool filter = getClientMajorVersion() >= 3 ||
2607 extensionEnabled("GL_OES_texture_half_float_linear");
2608 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2609 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2610 textureData, readPixelsData);
2611 }
2612 }
2613}
2614
2615TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2616{
Geoff Lang40762ef2017-05-08 13:47:03 -04002617 if (IsOzone() && IsIntel())
2618 {
2619 std::cout << "Test skipped on Intel Ozone." << std::endl;
2620 return;
2621 }
2622
Geoff Lang677bb6f2017-04-05 12:40:40 -04002623 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2624 const GLushort textureData[] = {
2625 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2626 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2627
2628 for (auto extension : FloatingPointTextureExtensions)
2629 {
2630 if (strlen(extension) > 0 && extensionRequestable(extension))
2631 {
2632 glRequestExtensionANGLE(extension);
2633 ASSERT_GL_NO_ERROR();
2634 }
2635
2636 // Unsized RGBA 16F (OES)
2637 {
2638 bool texture = extensionEnabled("GL_OES_texture_half_float");
2639 bool filter = getClientMajorVersion() >= 3 ||
2640 extensionEnabled("GL_OES_texture_half_float_linear");
2641 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2642 extensionEnabled("GL_EXT_color_buffer_float");
2643 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2644 textureData, readPixelsData);
2645 }
2646
2647 // Unsized RGBA 16F
2648 {
2649 bool texture = false;
2650 bool filter = false;
2651 bool render = false;
2652 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2653 textureData, readPixelsData);
2654 }
2655
2656 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2657 {
2658 // Sized RGBA 16F
2659 bool texture = getClientMajorVersion() >= 3;
2660 bool filter = getClientMajorVersion() >= 3 ||
2661 extensionEnabled("GL_OES_texture_half_float_linear");
2662 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2663 extensionEnabled("GL_EXT_color_buffer_float");
2664 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2665 textureData, readPixelsData);
2666 }
2667 }
2668}
2669
Geoff Lang6e898aa2017-06-02 11:17:26 -04002670// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2671// accepted by glTexImage2D
2672TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2673{
2674 if (getClientMajorVersion() != 2)
2675 {
2676 std::cout << "Test skipped because it is only valid for WebGL1 contexts." << std::endl;
2677 return;
2678 }
2679
2680 if (!extensionRequestable("GL_OES_texture_float"))
2681 {
2682 std::cout << "Test skipped because GL_OES_texture_float is not requestable." << std::endl;
2683 return;
2684 }
2685 glRequestExtensionANGLE("GL_OES_texture_float");
2686 ASSERT_GL_NO_ERROR();
2687
2688 GLTexture texture;
2689 glBindTexture(GL_TEXTURE_2D, texture);
2690
2691 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2692 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2693
2694 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2695 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2696
2697 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2698 {
2699 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2700 ASSERT_GL_NO_ERROR();
2701
2702 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2703 EXPECT_GL_NO_ERROR();
2704 }
2705
2706 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2707 {
2708 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2709 ASSERT_GL_NO_ERROR();
2710
2711 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2712 EXPECT_GL_NO_ERROR();
2713 }
2714}
2715
Jamie Madill07be8bf2017-02-02 19:59:57 -05002716// This tests that rendering feedback loops works as expected with WebGL 2.
2717// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2718TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2719{
2720 const std::string vertexShader =
2721 "#version 300 es\n"
2722 "in vec4 aPosition;\n"
2723 "out vec2 texCoord;\n"
2724 "void main() {\n"
2725 " gl_Position = aPosition;\n"
2726 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2727 "}\n";
2728
2729 const std::string fragmentShader =
2730 "#version 300 es\n"
2731 "precision mediump float;\n"
2732 "uniform sampler2D tex;\n"
2733 "in vec2 texCoord;\n"
2734 "out vec4 oColor;\n"
2735 "void main() {\n"
2736 " oColor = texture(tex, texCoord);\n"
2737 "}\n";
2738
2739 GLsizei width = 8;
2740 GLsizei height = 8;
2741
2742 GLint maxDrawBuffers = 0;
2743 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2744 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2745 ASSERT_GE(maxDrawBuffers, 2);
2746
2747 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2748 glUseProgram(program.get());
2749 glViewport(0, 0, width, height);
2750
2751 GLTexture tex0;
2752 GLTexture tex1;
2753 GLFramebuffer fbo;
2754 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2755 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2756 ASSERT_GL_NO_ERROR();
2757
2758 glBindTexture(GL_TEXTURE_2D, tex1.get());
2759 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2760 ASSERT_NE(-1, texLoc);
2761 glUniform1i(texLoc, 0);
2762
2763 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2764 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2765 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2766 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2767 ASSERT_GL_NO_ERROR();
2768
2769 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2770 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2771 GL_INVALID_OPERATION);
2772 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2773}
2774
Jamie Madill1d37bc52017-02-02 19:59:58 -05002775// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2776// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2777TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2778{
2779 const std::string vertexShader =
2780 "#version 300 es\n"
2781 "in vec4 aPosition;\n"
2782 "out vec2 texCoord;\n"
2783 "void main() {\n"
2784 " gl_Position = aPosition;\n"
2785 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2786 "}\n";
2787
2788 const std::string fragmentShader =
2789 "#version 300 es\n"
2790 "precision mediump float;\n"
2791 "uniform sampler2D tex;\n"
2792 "in vec2 texCoord;\n"
2793 "out vec4 oColor;\n"
2794 "void main() {\n"
2795 " oColor = texture(tex, texCoord);\n"
2796 "}\n";
2797
2798 GLsizei width = 8;
2799 GLsizei height = 8;
2800
2801 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2802 glUseProgram(program.get());
2803
2804 glViewport(0, 0, width, height);
2805
2806 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2807 glUniform1i(texLoc, 0);
2808
2809 // Create textures and allocate storage
2810 GLTexture tex0;
2811 GLTexture tex1;
2812 GLRenderbuffer rb;
2813 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2814 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2815 GL_UNSIGNED_INT);
2816 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2817 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2818 ASSERT_GL_NO_ERROR();
2819
2820 GLFramebuffer fbo;
2821 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2822 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2823
2824 // Test rendering and sampling feedback loop for depth buffer
2825 glBindTexture(GL_TEXTURE_2D, tex1.get());
2826 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2827 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2828
2829 // The same image is used as depth buffer during rendering.
2830 glEnable(GL_DEPTH_TEST);
2831 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2832 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2833
2834 // The same image is used as depth buffer. But depth mask is false.
2835 glDepthMask(GL_FALSE);
2836 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2837 EXPECT_GL_NO_ERROR();
2838
2839 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2840 glDepthMask(GL_TRUE);
2841 glDisable(GL_DEPTH_TEST);
2842 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2843 EXPECT_GL_NO_ERROR();
2844
2845 // Test rendering and sampling feedback loop for stencil buffer
2846 glBindTexture(GL_RENDERBUFFER, rb.get());
2847 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2848 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2849 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2850 constexpr GLint stencilClearValue = 0x40;
2851 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2852
2853 // The same image is used as stencil buffer during rendering.
2854 glEnable(GL_STENCIL_TEST);
2855 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2856 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2857
2858 // The same image is used as stencil buffer. But stencil mask is zero.
2859 glStencilMask(0x0);
2860 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2861 EXPECT_GL_NO_ERROR();
2862
2863 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2864 glStencilMask(0xffff);
2865 glDisable(GL_STENCIL_TEST);
2866 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2867 EXPECT_GL_NO_ERROR();
2868}
2869
Jamie Madillfd3dd432017-02-02 19:59:59 -05002870// The source and the target for CopyTexSubImage3D are the same 3D texture.
2871// But the level of the 3D texture != the level of the read attachment.
2872TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2873{
2874 GLTexture texture;
2875 GLFramebuffer framebuffer;
2876
2877 glBindTexture(GL_TEXTURE_3D, texture.get());
2878 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2879
2880 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2881 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2882 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2883 ASSERT_GL_NO_ERROR();
2884
2885 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2886 EXPECT_GL_NO_ERROR();
2887}
2888
2889// The source and the target for CopyTexSubImage3D are the same 3D texture.
2890// But the zoffset of the 3D texture != the layer of the read attachment.
2891TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2892{
2893 GLTexture texture;
2894 GLFramebuffer framebuffer;
2895
2896 glBindTexture(GL_TEXTURE_3D, texture.get());
2897 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2898
2899 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2900 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2901 ASSERT_GL_NO_ERROR();
2902
2903 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2904 EXPECT_GL_NO_ERROR();
2905}
2906
2907// The source and the target for CopyTexSubImage3D are the same 3D texture.
2908// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2909TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2910{
2911 GLTexture texture;
2912 GLFramebuffer framebuffer;
2913
2914 glBindTexture(GL_TEXTURE_3D, texture.get());
2915 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2916
2917 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2918 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2919 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2920 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2921 ASSERT_GL_NO_ERROR();
2922
2923 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2924 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2925}
2926
Corentin Wallez59c41592017-07-11 13:19:54 -04002927// Verify that errors are generated when there isn't a defined conversion between the clear type and
2928// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04002929TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2930{
2931 if (IsD3D11())
2932 {
2933 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2934 return;
2935 }
2936
2937 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2938 constexpr int clearInt[] = {0, 0, 0, 0};
2939 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2940
2941 GLTexture texture;
2942 GLFramebuffer framebuffer;
2943
2944 glBindTexture(GL_TEXTURE_2D, texture.get());
2945 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2946
2947 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2948 ASSERT_GL_NO_ERROR();
2949
2950 // Unsigned integer buffer
2951 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2952 ASSERT_GL_NO_ERROR();
2953
2954 glClearBufferfv(GL_COLOR, 0, clearFloat);
2955 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2956
2957 glClearBufferiv(GL_COLOR, 0, clearInt);
2958 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2959
2960 glClearBufferuiv(GL_COLOR, 0, clearUint);
2961 EXPECT_GL_NO_ERROR();
2962
2963 glClear(GL_COLOR_BUFFER_BIT);
2964 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2965
2966 // Integer buffer
2967 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2968 ASSERT_GL_NO_ERROR();
2969
2970 glClearBufferfv(GL_COLOR, 0, clearFloat);
2971 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2972
2973 glClearBufferiv(GL_COLOR, 0, clearInt);
2974 EXPECT_GL_NO_ERROR();
2975
2976 glClearBufferuiv(GL_COLOR, 0, clearUint);
2977 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2978
2979 glClear(GL_COLOR_BUFFER_BIT);
2980 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2981
2982 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002983 if (extensionRequestable("GL_EXT_color_buffer_float"))
2984 {
2985 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2986 }
Geoff Lang76e65652017-03-27 14:58:02 -04002987
Geoff Lang677bb6f2017-04-05 12:40:40 -04002988 if (extensionEnabled("GL_EXT_color_buffer_float"))
2989 {
2990 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2991 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002992
Geoff Lang677bb6f2017-04-05 12:40:40 -04002993 glClearBufferfv(GL_COLOR, 0, clearFloat);
2994 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002995
Geoff Lang677bb6f2017-04-05 12:40:40 -04002996 glClearBufferiv(GL_COLOR, 0, clearInt);
2997 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002998
Geoff Lang677bb6f2017-04-05 12:40:40 -04002999 glClearBufferuiv(GL_COLOR, 0, clearUint);
3000 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3001
3002 glClear(GL_COLOR_BUFFER_BIT);
3003 EXPECT_GL_NO_ERROR();
3004 }
Geoff Lang76e65652017-03-27 14:58:02 -04003005
3006 // Normalized uint buffer
3007 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3008 ASSERT_GL_NO_ERROR();
3009
3010 glClearBufferfv(GL_COLOR, 0, clearFloat);
3011 EXPECT_GL_NO_ERROR();
3012
3013 glClearBufferiv(GL_COLOR, 0, clearInt);
3014 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3015
3016 glClearBufferuiv(GL_COLOR, 0, clearUint);
3017 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3018
3019 glClear(GL_COLOR_BUFFER_BIT);
3020 EXPECT_GL_NO_ERROR();
3021}
3022
Corentin Wallez59c41592017-07-11 13:19:54 -04003023// Test the interaction of WebGL compatibility clears with default framebuffers
3024TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
3025{
3026 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3027 constexpr int clearInt[] = {0, 0, 0, 0};
3028 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3029
3030 // glClear works as usual, this is also a regression test for a bug where we
3031 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
3032 glClear(GL_COLOR_BUFFER_BIT);
3033 EXPECT_GL_NO_ERROR();
3034
3035 // Default framebuffers are normalized uints, so only glClearBufferfv works.
3036 glClearBufferfv(GL_COLOR, 0, clearFloat);
3037 EXPECT_GL_NO_ERROR();
3038
3039 glClearBufferiv(GL_COLOR, 0, clearInt);
3040 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3041
3042 glClearBufferuiv(GL_COLOR, 0, clearUint);
3043 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3044}
3045
Geoff Lange4915782017-04-12 15:19:07 -04003046// Verify that errors are generate when trying to blit from an image to itself
3047TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
3048{
3049 GLTexture textures[2];
3050 glBindTexture(GL_TEXTURE_2D, textures[0]);
3051 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3052 glBindTexture(GL_TEXTURE_2D, textures[1]);
3053 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3054
3055 GLRenderbuffer renderbuffers[2];
3056 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
3057 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3058 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
3059 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3060
3061 GLFramebuffer framebuffers[2];
3062 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
3063 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
3064
3065 ASSERT_GL_NO_ERROR();
3066
3067 // Same texture
3068 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3069 0);
3070 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3071 0);
3072 ASSERT_GL_NO_ERROR();
3073 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3074 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3075
3076 // Same textures but different renderbuffers
3077 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3078 renderbuffers[0]);
3079 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3080 renderbuffers[1]);
3081 ASSERT_GL_NO_ERROR();
3082 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3083 ASSERT_GL_NO_ERROR();
3084 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3085 GL_NEAREST);
3086 ASSERT_GL_NO_ERROR();
3087 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3088 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3089 GL_NEAREST);
3090 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3091
3092 // Same renderbuffers but different textures
3093 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3094 0);
3095 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
3096 0);
3097 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3098 renderbuffers[0]);
3099 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3100 renderbuffers[0]);
3101 ASSERT_GL_NO_ERROR();
3102 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3103 ASSERT_GL_NO_ERROR();
3104 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3105 GL_NEAREST);
3106 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3107 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3108 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3109 GL_NEAREST);
3110 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3111}
3112
Geoff Lange0cff192017-05-30 13:04:56 -04003113// Verify that errors are generated when the fragment shader output doesn't match the bound color
3114// buffer types
3115TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
3116{
3117 const std::string vertexShader =
3118 "#version 300 es\n"
3119 "void main() {\n"
3120 " gl_Position = vec4(0, 0, 0, 1);\n"
3121 "}\n";
3122
3123 const std::string fragmentShader =
3124 "#version 300 es\n"
3125 "precision mediump float;\n"
3126 "layout(location = 0) out vec4 floatOutput;\n"
3127 "layout(location = 1) out uvec4 uintOutput;\n"
3128 "layout(location = 2) out ivec4 intOutput;\n"
3129 "void main() {\n"
3130 " floatOutput = vec4(0, 0, 0, 1);\n"
3131 " uintOutput = uvec4(0, 0, 0, 1);\n"
3132 " intOutput = ivec4(0, 0, 0, 1);\n"
3133 "}\n";
3134
3135 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3136 glUseProgram(program.get());
3137
3138 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
3139 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
3140 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
3141
3142 GLFramebuffer fbo;
3143 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3144
3145 GLRenderbuffer floatRenderbuffer;
3146 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
3147 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
3148 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3149 floatRenderbuffer);
3150
3151 GLRenderbuffer uintRenderbuffer;
3152 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
3153 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
3154 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3155 uintRenderbuffer);
3156
3157 GLRenderbuffer intRenderbuffer;
3158 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
3159 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
3160 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3161 intRenderbuffer);
3162
3163 ASSERT_GL_NO_ERROR();
3164
3165 GLint maxDrawBuffers = 0;
3166 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3167 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
3168 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
3169 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
3170 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
3171
3172 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
3173
3174 // Check that the correct case generates no errors
3175 glDrawArrays(GL_TRIANGLES, 0, 6);
3176 EXPECT_GL_NO_ERROR();
3177
3178 // Unbind some buffers and verify that there are still no errors
3179 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3180 0);
3181 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3182 0);
3183 glDrawArrays(GL_TRIANGLES, 0, 6);
3184 EXPECT_GL_NO_ERROR();
3185
3186 // Swap the int and uint buffers to and verify that an error is generated
3187 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3188 intRenderbuffer);
3189 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3190 uintRenderbuffer);
3191 glDrawArrays(GL_TRIANGLES, 0, 6);
3192 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3193
3194 // Swap the float and uint buffers to and verify that an error is generated
3195 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3196 floatRenderbuffer);
3197 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3198 uintRenderbuffer);
3199 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3200 intRenderbuffer);
3201 glDrawArrays(GL_TRIANGLES, 0, 6);
3202 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3203}
3204
Geoff Lang9ab5b822017-05-30 16:19:23 -04003205// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
3206// types
Corentin Wallezc3bc9842017-10-11 15:15:59 -04003207TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch)
Geoff Lang9ab5b822017-05-30 16:19:23 -04003208{
3209 const std::string vertexShader =
3210 "#version 300 es\n"
3211 "in vec4 floatInput;\n"
3212 "in uvec4 uintInput;\n"
3213 "in ivec4 intInput;\n"
3214 "void main() {\n"
3215 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
3216 "}\n";
3217
3218 const std::string fragmentShader =
3219 "#version 300 es\n"
3220 "precision mediump float;\n"
3221 "out vec4 outputColor;\n"
3222 "void main() {\n"
3223 " outputColor = vec4(0, 0, 0, 1);"
3224 "}\n";
3225
3226 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3227 glUseProgram(program.get());
3228
3229 GLint floatLocation = glGetAttribLocation(program, "floatInput");
3230 GLint uintLocation = glGetAttribLocation(program, "uintInput");
3231 GLint intLocation = glGetAttribLocation(program, "intInput");
3232
3233 // Default attributes are of float types
3234 glDrawArrays(GL_TRIANGLES, 0, 6);
3235 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3236
3237 // Set the default attributes to the correct types, should succeed
3238 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
3239 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
3240 glDrawArrays(GL_TRIANGLES, 0, 6);
3241 EXPECT_GL_NO_ERROR();
3242
3243 // Change the default float attribute to an integer, should fail
3244 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
3245 glDrawArrays(GL_TRIANGLES, 0, 6);
3246 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3247
3248 // Use a buffer for some attributes
3249 GLBuffer buffer;
3250 glBindBuffer(GL_ARRAY_BUFFER, buffer);
3251 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
3252 glEnableVertexAttribArray(floatLocation);
3253 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3254 glDrawArrays(GL_TRIANGLES, 0, 6);
3255 EXPECT_GL_NO_ERROR();
3256
3257 // Use a float pointer attrib for a uint input
3258 glEnableVertexAttribArray(uintLocation);
3259 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3260 glDrawArrays(GL_TRIANGLES, 0, 6);
3261 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3262
3263 // Use a uint pointer for the uint input
3264 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
3265 glDrawArrays(GL_TRIANGLES, 0, 6);
3266 EXPECT_GL_NO_ERROR();
3267}
3268
Corentin Walleze7557742017-06-01 13:09:57 -04003269// Tests the WebGL removal of undefined behavior when attachments aren't written to.
3270TEST_P(WebGLCompatibilityTest, DrawBuffers)
3271{
Corentin Walleze7557742017-06-01 13:09:57 -04003272 // Make sure we can use at least 4 attachments for the tests.
3273 bool useEXT = false;
3274 if (getClientMajorVersion() < 3)
3275 {
3276 if (!extensionRequestable("GL_EXT_draw_buffers"))
3277 {
3278 std::cout << "Test skipped because draw buffers are not available" << std::endl;
3279 return;
3280 }
3281
3282 glRequestExtensionANGLE("GL_EXT_draw_buffers");
3283 useEXT = true;
3284 EXPECT_GL_NO_ERROR();
3285 }
3286
3287 GLint maxDrawBuffers = 0;
3288 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3289 if (maxDrawBuffers < 4)
3290 {
3291 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
3292 return;
3293 }
3294
3295 // Clears all the renderbuffers to red.
3296 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
3297 GLFramebuffer clearFBO;
3298 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
3299
3300 glClearColor(1, 0, 0, 1);
3301 for (int i = 0; i < 4; ++i)
3302 {
3303 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3304 renderbuffers[i]);
3305 glClear(GL_COLOR_BUFFER_BIT);
3306 }
3307 ASSERT_GL_NO_ERROR();
3308 };
3309
3310 // Checks that the renderbuffers specified by mask have the correct color
3311 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
3312 GLFramebuffer readFBO;
3313 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
3314
3315 for (int i = 0; i < 4; ++i)
3316 {
3317 if (mask & (1 << i))
3318 {
3319 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
3320 GL_RENDERBUFFER, renderbuffers[i]);
3321 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
3322 }
3323 }
3324 ASSERT_GL_NO_ERROR();
3325 };
3326
3327 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
3328 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
3329 if (useEXT)
3330 {
3331 glDrawBuffersEXT(numBuffers, buffers);
3332 }
3333 else
3334 {
3335 glDrawBuffers(numBuffers, buffers);
3336 }
3337 };
3338
3339 // Initialized the test framebuffer
3340 GLFramebuffer drawFBO;
3341 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3342
3343 GLRenderbuffer renderbuffers[4];
3344 for (int i = 0; i < 4; ++i)
3345 {
3346 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
3347 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
3348 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
3349 renderbuffers[i]);
3350 }
3351
3352 ASSERT_GL_NO_ERROR();
3353
3354 const char *vertESSL1 =
3355 "attribute vec4 a_pos;\n"
3356 "void main()\n"
3357 "{\n"
3358 " gl_Position = a_pos;\n"
3359 "}\n";
3360 const char *vertESSL3 =
3361 "#version 300 es\n"
3362 "in vec4 a_pos;\n"
3363 "void main()\n"
3364 "{\n"
3365 " gl_Position = a_pos;\n"
3366 "}\n";
3367
3368 GLenum allDrawBuffers[] = {
3369 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3370 };
3371
3372 GLenum halfDrawBuffers[] = {
3373 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3374 };
3375
3376 // Test that when using gl_FragColor, only the first attachment is written to.
3377 const char *fragESSL1 =
3378 "precision highp float;\n"
3379 "void main()\n"
3380 "{\n"
3381 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3382 "}\n";
3383 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
3384
3385 {
3386 ClearEverythingToRed(renderbuffers);
3387
3388 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3389 DrawBuffers(useEXT, 4, allDrawBuffers);
3390 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
3391 ASSERT_GL_NO_ERROR();
3392
3393 CheckColors(renderbuffers, 0b0001, GLColor::green);
3394 CheckColors(renderbuffers, 0b1110, GLColor::red);
3395 }
3396
3397 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
3398 // written to.
3399 {
3400 ClearEverythingToRed(renderbuffers);
3401
3402 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3403 DrawBuffers(useEXT, 4, halfDrawBuffers);
3404 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
3405 ASSERT_GL_NO_ERROR();
3406
3407 CheckColors(renderbuffers, 0b1111, GLColor::red);
3408 }
3409
3410 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
3411 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
3412 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
3413 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
3414 // attachments not declared in the shader should not be written to.
3415 const char *writeOddOutputsVert;
3416 const char *writeOddOutputsFrag;
3417 GLColor unwrittenColor;
3418 if (useEXT)
3419 {
3420 // In the extension, when an attachment isn't written to, it should get 0's
3421 unwrittenColor = GLColor(0, 0, 0, 0);
3422 writeOddOutputsVert = vertESSL1;
3423 writeOddOutputsFrag =
3424 "#extension GL_EXT_draw_buffers : require\n"
3425 "precision highp float;\n"
3426 "void main()\n"
3427 "{\n"
3428 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3429 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3430 "}\n";
3431 }
3432 else
3433 {
3434 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
3435 // because of the preceding clears.
3436 unwrittenColor = GLColor::red;
3437 writeOddOutputsVert = vertESSL3;
3438 writeOddOutputsFrag =
3439 "#version 300 es\n"
3440 "precision highp float;\n"
3441 "layout(location = 1) out vec4 output1;"
3442 "layout(location = 3) out vec4 output2;"
3443 "void main()\n"
3444 "{\n"
3445 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3446 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3447 "}\n";
3448 }
3449 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
3450
3451 // Test that attachments not written to get the "unwritten" color
3452 {
3453 ClearEverythingToRed(renderbuffers);
3454
3455 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3456 DrawBuffers(useEXT, 4, allDrawBuffers);
3457 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
3458 ASSERT_GL_NO_ERROR();
3459
3460 CheckColors(renderbuffers, 0b1010, GLColor::green);
3461 CheckColors(renderbuffers, 0b0101, unwrittenColor);
3462 }
3463
3464 // Test that attachments not written to get the "unwritten" color but that even when the
3465 // extension is used, disabled attachments are not written at all and stay red.
3466 {
3467 ClearEverythingToRed(renderbuffers);
3468
3469 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3470 DrawBuffers(useEXT, 4, halfDrawBuffers);
3471 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
3472 ASSERT_GL_NO_ERROR();
3473
3474 CheckColors(renderbuffers, 0b1000, GLColor::green);
3475 CheckColors(renderbuffers, 0b0100, unwrittenColor);
3476 CheckColors(renderbuffers, 0b0011, GLColor::red);
3477 }
3478}
3479
Geoff Lang536eca12017-09-13 11:23:35 -04003480// Test that it's possible to generate mipmaps on unsized floating point textures once the
3481// extensions have been enabled
3482TEST_P(WebGLCompatibilityTest, GenerateMipmapUnsizedFloatingPointTexture)
3483{
3484 if (extensionRequestable("GL_OES_texture_float"))
3485 {
3486 glRequestExtensionANGLE("GL_OES_texture_float");
3487 }
3488 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3489
3490 GLTexture texture;
3491 glBindTexture(GL_TEXTURE_2D, texture);
3492
3493 constexpr GLColor32F data[4] = {
3494 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3495 };
3496 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_FLOAT, data);
3497 ASSERT_GL_NO_ERROR();
3498
3499 glGenerateMipmap(GL_TEXTURE_2D);
3500 EXPECT_GL_NO_ERROR();
3501}
3502// Test that it's possible to generate mipmaps on unsized floating point textures once the
3503// extensions have been enabled
3504TEST_P(WebGLCompatibilityTest, GenerateMipmapSizedFloatingPointTexture)
3505{
3506 if (extensionRequestable("GL_OES_texture_float"))
3507 {
3508 glRequestExtensionANGLE("GL_OES_texture_float");
3509 }
3510 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3511
3512 if (extensionRequestable("GL_EXT_texture_storage"))
3513 {
3514 glRequestExtensionANGLE("GL_EXT_texture_storage");
3515 }
3516 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage"));
3517
3518 GLTexture texture;
3519 glBindTexture(GL_TEXTURE_2D, texture);
3520
3521 constexpr GLColor32F data[4] = {
3522 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3523 };
3524 glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA32F, 2, 2);
3525 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_FLOAT, data);
3526 ASSERT_GL_NO_ERROR();
3527
3528 glGenerateMipmap(GL_TEXTURE_2D);
3529 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3530
3531 if (extensionRequestable("GL_EXT_color_buffer_float"))
3532 {
3533 // Format is renderable but not filterable
3534 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3535 glGenerateMipmap(GL_TEXTURE_2D);
3536 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3537 }
3538
3539 if (extensionRequestable("GL_EXT_color_buffer_float_linear"))
3540 {
3541 // Format is renderable but not filterable
3542 glRequestExtensionANGLE("GL_EXT_color_buffer_float_linear");
3543
3544 if (extensionEnabled("GL_EXT_color_buffer_float"))
3545 {
3546 // Format is filterable and renderable
3547 glGenerateMipmap(GL_TEXTURE_2D);
3548 EXPECT_GL_NO_ERROR();
3549 }
3550 else
3551 {
3552 // Format is filterable but not renderable
3553 glGenerateMipmap(GL_TEXTURE_2D);
3554 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3555 }
3556 }
3557}
3558
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003559// Verify that a texture format is only allowed with extension enabled.
3560void WebGLCompatibilityTest::validateTexImageExtensionFormat(GLenum format,
3561 const std::string &extName)
3562{
3563 // Verify texture format fails by default.
3564 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3565 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3566
3567 if (extensionRequestable(extName))
3568 {
3569 // Verify texture format is allowed once extension is enabled.
3570 glRequestExtensionANGLE(extName.c_str());
3571 EXPECT_TRUE(extensionEnabled(extName));
3572
3573 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3574 ASSERT_GL_NO_ERROR();
3575 }
3576}
3577
3578// Verify that only valid texture formats are allowed.
3579TEST_P(WebGLCompatibilityTest, InvalidTextureFormat)
3580{
3581 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
3582
3583 GLTexture texture;
3584 glBindTexture(GL_TEXTURE_2D, texture.get());
3585
3586 // Verify valid format is allowed.
3587 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3588 ASSERT_GL_NO_ERROR();
3589
3590 // Verify invalid format fails.
3591 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA32F, GL_UNSIGNED_BYTE, nullptr);
3592 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3593
3594 // Verify formats from enableable extensions.
3595 if (!IsAndroid())
3596 {
3597 validateTexImageExtensionFormat(GL_RED_EXT, "GL_EXT_texture_rg");
3598 }
3599
3600 validateTexImageExtensionFormat(GL_SRGB_EXT, "GL_EXT_texture_sRGB");
3601 validateTexImageExtensionFormat(GL_BGRA_EXT, "GL_EXT_texture_format_BGRA8888");
3602}
3603
Frank Henigmanfccbac22017-05-28 17:29:26 -04003604// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
3605// qualifiers.
3606TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
3607{
3608 const std::string vertexShader =
3609 "#version 300 es\n"
3610 "uniform Block { mediump vec4 val; };\n"
3611 "void main() { gl_Position = val; }\n";
3612 const std::string fragmentShader =
3613 "#version 300 es\n"
3614 "uniform Block { highp vec4 val; };\n"
3615 "out highp vec4 out_FragColor;\n"
3616 "void main() { out_FragColor = val; }\n";
3617
3618 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
3619 ASSERT_NE(0u, vs);
3620 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
3621 ASSERT_NE(0u, fs);
3622
3623 GLuint program = glCreateProgram();
3624
3625 glAttachShader(program, vs);
3626 glDeleteShader(vs);
3627 glAttachShader(program, fs);
3628 glDeleteShader(fs);
3629
3630 glLinkProgram(program);
3631 GLint linkStatus;
3632 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
3633 ASSERT_EQ(0, linkStatus);
3634
3635 glDeleteProgram(program);
3636}
3637
Geoff Lang69df2422017-07-05 12:42:31 -04003638// Test no attribute vertex shaders
3639TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
3640{
3641 const std::string vertexShader =
3642 "#version 300 es\n"
3643 "void main()\n"
3644 "{\n"
3645 "\n"
3646 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
3647 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
3648 "}";
3649 const std::string fragmentShader =
3650 "#version 300 es\n"
3651 "precision mediump float;\n"
3652 "out vec4 result;\n"
3653 "void main()\n"
3654 "{\n"
3655 " result = vec4(0, 1, 0, 1);\n"
3656 "}";
3657
3658 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3659 glUseProgram(program);
3660
3661 glDrawArrays(GL_TRIANGLES, 0, 6);
3662 ASSERT_GL_NO_ERROR();
3663 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3664}
3665
Brandon Jonesed5b46f2017-07-21 08:39:17 -07003666// Tests bindAttribLocations for length limit
3667TEST_P(WebGL2CompatibilityTest, BindAttribLocationLimitation)
3668{
3669 constexpr int maxLocStringLength = 1024;
3670 const std::string tooLongString(maxLocStringLength + 1, '_');
3671
3672 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
3673
3674 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3675}
3676
Geoff Langc287ea62016-09-16 14:46:51 -04003677// Use this to select which configurations (e.g. which renderer, which GLES major version) these
3678// tests should be run against.
3679ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
3680 ES2_D3D9(),
3681 ES2_D3D11(),
3682 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04003683 ES2_OPENGL(),
3684 ES3_OPENGL(),
3685 ES2_OPENGLES(),
3686 ES3_OPENGLES());
3687
Jamie Madill07be8bf2017-02-02 19:59:57 -05003688ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04003689} // namespace