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