blob: 1cde5d74f7fddb0e86cda5df76ed10e9cc9658ad [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
Geoff Langd84a00b2017-10-27 17:27:26 -0400121 // Need RGBA8 renderbuffers for enough precision on the readback
122 if (extensionRequestable("GL_OES_rgb8_rgba8"))
123 {
124 glRequestExtensionANGLE("GL_OES_rgb8_rgba8");
125 }
126 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_rgb8_rgba8") && getClientMajorVersion() < 3);
127 ASSERT_GL_NO_ERROR();
128
Geoff Lang677bb6f2017-04-05 12:40:40 -0400129 GLRenderbuffer rbo;
130 glBindRenderbuffer(GL_RENDERBUFFER, rbo.get());
131 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
132
133 GLFramebuffer fbo;
134 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
135 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo.get());
136
137 GLTexture texture;
138 glBindTexture(GL_TEXTURE_2D, texture.get());
139
140 if (internalFormat == format)
141 {
142 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, textureData);
143 }
144 else
145 {
146 if (getClientMajorVersion() >= 3)
147 {
148 glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
149 }
150 else
151 {
152 ASSERT_TRUE(extensionEnabled("GL_EXT_texture_storage"));
153 glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
154 }
155 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, format, type, textureData);
156 }
157
158 if (!texturingEnabled)
159 {
160 // Depending on the entry point and client version, different errors may be generated
161 ASSERT_GLENUM_NE(GL_NO_ERROR, glGetError());
162
163 // Two errors may be generated in the glTexStorage + glTexSubImage case, clear the
164 // second error
165 glGetError();
166
167 return;
168 }
169 ASSERT_GL_NO_ERROR();
170
171 glUniform1i(glGetUniformLocation(samplingProgram.get(), "tex"), 0);
172 glUniform4fv(glGetUniformLocation(samplingProgram.get(), "subtractor"), 1, floatData);
173
174 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
175 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
176 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
177 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
178
179 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
180 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
181
182 if (linearSamplingEnabled)
183 {
184 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
185 }
186 else
187 {
188 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
189 }
190
191 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(),
192 0);
193 glBindTexture(GL_TEXTURE_2D, 0);
194 if (!renderingEnabled)
195 {
196 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
197 glCheckFramebufferStatus(GL_FRAMEBUFFER));
198 return;
199 }
Ken Russellb9f92502018-01-27 19:00:26 -0800200
Geoff Lang677bb6f2017-04-05 12:40:40 -0400201 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
202
Olli Etuaho5804dc82018-04-13 14:11:46 +0300203 ANGLE_GL_PROGRAM(renderingProgram, essl1_shaders::vs::Simple(),
204 essl1_shaders::fs::UniformColor());
Geoff Lang677bb6f2017-04-05 12:40:40 -0400205 glUseProgram(renderingProgram.get());
206
Olli Etuaho5804dc82018-04-13 14:11:46 +0300207 glUniform4fv(glGetUniformLocation(renderingProgram.get(), essl1_shaders::ColorUniform()), 1,
208 floatData);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400209
Olli Etuaho5804dc82018-04-13 14:11:46 +0300210 drawQuad(renderingProgram.get(), essl1_shaders::PositionAttrib(), 0.5f, 1.0f, true);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400211
212 EXPECT_PIXEL_COLOR32F_NEAR(
213 0, 0, GLColor32F(floatData[0], floatData[1], floatData[2], floatData[3]), 1.0f);
214 }
215
Ken Russellb9f92502018-01-27 19:00:26 -0800216 void TestDifferentStencilMaskAndRef(GLenum errIfMismatch);
217
Jamie Madillcad97ee2017-02-02 18:52:44 -0500218 // Called from RenderingFeedbackLoopWithDrawBuffersEXT.
219 void drawBuffersEXTFeedbackLoop(GLuint program,
220 const std::array<GLenum, 2> &drawBuffers,
221 GLenum expectedError);
222
Jamie Madill07be8bf2017-02-02 19:59:57 -0500223 // Called from RenderingFeedbackLoopWithDrawBuffers.
224 void drawBuffersFeedbackLoop(GLuint program,
225 const std::array<GLenum, 2> &drawBuffers,
226 GLenum expectedError);
227
Geoff Lang86f81162017-10-30 15:10:45 -0400228 // Called from Enable[Compressed]TextureFormatExtensions
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -0700229 void validateTexImageExtensionFormat(GLenum format, const std::string &extName);
Geoff Lang86f81162017-10-30 15:10:45 -0400230 void validateCompressedTexImageExtensionFormat(GLenum format,
231 GLsizei width,
232 GLsizei height,
233 GLsizei blockSize,
234 const std::string &extName,
235 bool subImageAllowed);
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -0700236
Geoff Langc339c4e2016-11-29 10:37:36 -0500237 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
Geoff Langc287ea62016-09-16 14:46:51 -0400238};
239
Corentin Wallezfd456442016-12-21 17:57:00 -0500240class WebGL2CompatibilityTest : public WebGLCompatibilityTest
241{
242};
243
Geoff Langc287ea62016-09-16 14:46:51 -0400244// Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so
245// the GL extension should always be present
246TEST_P(WebGLCompatibilityTest, ExtensionStringExposed)
247{
248 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
249}
250
251// Verify that all extension entry points are available
252TEST_P(WebGLCompatibilityTest, EntryPoints)
253{
Geoff Langc339c4e2016-11-29 10:37:36 -0500254 if (extensionEnabled("GL_ANGLE_request_extension"))
Geoff Langc287ea62016-09-16 14:46:51 -0400255 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500256 EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -0400257 }
258}
259
260// WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable,
261// even in ES2 contexts.
262TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint)
263{
264 GLRenderbuffer renderbuffer;
265 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
266 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
267
268 GLFramebuffer framebuffer;
269 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
270 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
271 renderbuffer.get());
272
273 EXPECT_GL_NO_ERROR();
274}
275
276// Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION
277TEST_P(WebGLCompatibilityTest, EnableExtensionValidation)
278{
Geoff Langc339c4e2016-11-29 10:37:36 -0500279 glRequestExtensionANGLE("invalid_extension_string");
Geoff Langc287ea62016-09-16 14:46:51 -0400280 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
281}
282
283// Test enabling the GL_OES_element_index_uint extension
284TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices)
285{
286 if (getClientMajorVersion() != 2)
287 {
288 // This test only works on ES2 where uint indices are not available by default
289 return;
290 }
291
292 EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint"));
293
294 GLBuffer indexBuffer;
295 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
296
297 GLuint data[] = {0, 1, 2, 1, 3, 2};
298 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
299
300 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
301 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
302 glUseProgram(program.get());
303
Jamie Madille7b96342017-06-23 15:06:08 -0400304 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400305 EXPECT_GL_ERROR(GL_INVALID_ENUM);
306
Geoff Langc339c4e2016-11-29 10:37:36 -0500307 if (extensionRequestable("GL_OES_element_index_uint"))
Geoff Langc287ea62016-09-16 14:46:51 -0400308 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500309 glRequestExtensionANGLE("GL_OES_element_index_uint");
Geoff Langc287ea62016-09-16 14:46:51 -0400310 EXPECT_GL_NO_ERROR();
311 EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint"));
312
Jamie Madille7b96342017-06-23 15:06:08 -0400313 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400314 EXPECT_GL_NO_ERROR();
315 }
316}
317
Geoff Langff5c63e2017-04-12 15:26:54 -0400318// Test enabling the GL_OES_standard_derivatives extension
319TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives)
320{
321 EXPECT_FALSE(extensionEnabled("GL_OES_standard_derivatives"));
322
323 const std::string source =
324 "#extension GL_OES_standard_derivatives : require\n"
325 "void main() { gl_FragColor = vec4(dFdx(vec2(1.0, 1.0)).x, 1, 0, 1); }\n";
326 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
327
328 if (extensionRequestable("GL_OES_standard_derivatives"))
329 {
330 glRequestExtensionANGLE("GL_OES_standard_derivatives");
331 EXPECT_GL_NO_ERROR();
332 EXPECT_TRUE(extensionEnabled("GL_OES_standard_derivatives"));
333
334 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
335 ASSERT_NE(0u, shader);
336 glDeleteShader(shader);
337 }
338}
339
340// Test enabling the GL_EXT_shader_texture_lod extension
341TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD)
342{
343 EXPECT_FALSE(extensionEnabled("GL_EXT_shader_texture_lod"));
344
345 const std::string source =
346 "#extension GL_EXT_shader_texture_lod : require\n"
347 "uniform sampler2D u_texture;\n"
348 "void main() {\n"
349 " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, "
350 "0.0));\n"
351 "}\n";
352 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
353
354 if (extensionRequestable("GL_EXT_shader_texture_lod"))
355 {
356 glRequestExtensionANGLE("GL_EXT_shader_texture_lod");
357 EXPECT_GL_NO_ERROR();
358 EXPECT_TRUE(extensionEnabled("GL_EXT_shader_texture_lod"));
359
360 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
361 ASSERT_NE(0u, shader);
362 glDeleteShader(shader);
363 }
364}
365
366// Test enabling the GL_EXT_frag_depth extension
367TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth)
368{
369 EXPECT_FALSE(extensionEnabled("GL_EXT_frag_depth"));
370
371 const std::string source =
372 "#extension GL_EXT_frag_depth : require\n"
373 "void main() {\n"
374 " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
375 " gl_FragDepthEXT = 1.0;\n"
376 "}\n";
377 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
378
379 if (extensionRequestable("GL_EXT_frag_depth"))
380 {
381 glRequestExtensionANGLE("GL_EXT_frag_depth");
382 EXPECT_GL_NO_ERROR();
383 EXPECT_TRUE(extensionEnabled("GL_EXT_frag_depth"));
384
385 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
386 ASSERT_NE(0u, shader);
387 glDeleteShader(shader);
388 }
389}
390
Geoff Langd7d526a2017-02-21 16:48:43 -0500391// Test enabling the GL_EXT_texture_filter_anisotropic extension
392TEST_P(WebGLCompatibilityTest, EnableExtensionTextureFilterAnisotropic)
393{
394 EXPECT_FALSE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
395
396 GLfloat maxAnisotropy = 0.0f;
397 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
398 EXPECT_GL_ERROR(GL_INVALID_ENUM);
399
400 GLTexture texture;
401 glBindTexture(GL_TEXTURE_2D, texture.get());
402 ASSERT_GL_NO_ERROR();
403
404 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
405 EXPECT_GL_ERROR(GL_INVALID_ENUM);
406
407 GLfloat currentAnisotropy = 0.0f;
408 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
409 EXPECT_GL_ERROR(GL_INVALID_ENUM);
410
411 if (extensionRequestable("GL_EXT_texture_filter_anisotropic"))
412 {
413 glRequestExtensionANGLE("GL_EXT_texture_filter_anisotropic");
414 EXPECT_GL_NO_ERROR();
415 EXPECT_TRUE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
416
417 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
418 ASSERT_GL_NO_ERROR();
419 EXPECT_GE(maxAnisotropy, 2.0f);
420
421 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
422 ASSERT_GL_NO_ERROR();
423 EXPECT_EQ(1.0f, currentAnisotropy);
424
425 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
426 ASSERT_GL_NO_ERROR();
427 }
428}
429
Geoff Lang025aafd2017-10-30 15:16:37 -0400430// Test enabling the EGL image extensions
431TEST_P(WebGLCompatibilityTest, EnableExtensionEGLImage)
432{
433 EXPECT_FALSE(extensionEnabled("GL_OES_EGL_image"));
434 EXPECT_FALSE(extensionEnabled("GL_OES_EGL_image_external"));
435 EXPECT_FALSE(extensionEnabled("GL_OES_EGL_image_external_essl3"));
436 EXPECT_FALSE(extensionEnabled("NV_EGL_stream_consumer_external"));
437
438 const std::string &fragES2 =
439 "#extension GL_OES_EGL_image_external : require\n"
440 "precision highp float;\n"
441 "uniform samplerExternalOES sampler;\n"
442 "void main()\n"
443 "{\n"
444 " gl_FragColor = texture2D(sampler, vec2(0, 0));\n"
445 "}";
446 EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, fragES2));
447
448 const std::string &fragES3 =
449 "#version 300 es\n"
450 "#extension GL_OES_EGL_image_external : require\n"
451 "precision highp float;\n"
452 "uniform samplerExternalOES sampler;\n"
453 "void main()\n"
454 "{\n"
455 " gl_FragColor = texture(sampler, vec2(0, 0));\n"
456 "}";
457 if (getClientMajorVersion() > 3)
458 {
459 EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, fragES3));
460 }
461
462 glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
463 EXPECT_GL_ERROR(GL_INVALID_ENUM);
464
465 GLint result;
466 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &result);
467 EXPECT_GL_ERROR(GL_INVALID_ENUM);
468
469 if (extensionRequestable("GL_OES_EGL_image_external"))
470 {
471 glRequestExtensionANGLE("GL_OES_EGL_image_external");
472 EXPECT_GL_NO_ERROR();
473 EXPECT_TRUE(extensionEnabled("GL_OES_EGL_image_external"));
474
475 EXPECT_NE(0u, CompileShader(GL_FRAGMENT_SHADER, fragES2));
476
477 glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
478 EXPECT_GL_NO_ERROR();
479
480 glGetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, &result);
481 EXPECT_GL_NO_ERROR();
482
483 if (getClientMajorVersion() > 3 && extensionRequestable("GL_OES_EGL_image_external_essl3"))
484 {
485 glRequestExtensionANGLE("GL_OES_EGL_image_external_essl3");
486 EXPECT_GL_NO_ERROR();
487 EXPECT_TRUE(extensionEnabled("GL_OES_EGL_image_external_essl3"));
488
489 EXPECT_NE(0u, CompileShader(GL_FRAGMENT_SHADER, fragES3));
490 }
491 else
492 {
493 EXPECT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, fragES3));
494 }
495 }
496}
497
Bryan Bernhart87c182e2016-11-02 11:23:22 -0700498// Verify that shaders are of a compatible spec when the extension is enabled.
499TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec)
500{
501 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
502
503 // Use of reserved _webgl prefix should fail when the shader specification is for WebGL.
504 const std::string &vert =
505 "struct Foo {\n"
506 " int _webgl_bar;\n"
507 "};\n"
508 "void main()\n"
509 "{\n"
510 " Foo foo = Foo(1);\n"
511 "}";
512
513 // Default fragement shader.
514 const std::string &frag =
515 "void main()\n"
516 "{\n"
517 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
518 "}";
519
520 GLuint program = CompileProgram(vert, frag);
521 EXPECT_EQ(0u, program);
522 glDeleteProgram(program);
523}
524
Geoff Lang3fab7632017-09-26 15:45:54 -0400525// Test enabling the GL_NV_pixel_buffer_object extension
526TEST_P(WebGLCompatibilityTest, EnablePixelBufferObjectExtensions)
527{
528 EXPECT_FALSE(extensionEnabled("GL_NV_pixel_buffer_object"));
529 EXPECT_FALSE(extensionEnabled("GL_OES_mapbuffer"));
530 EXPECT_FALSE(extensionEnabled("GL_EXT_map_buffer_range"));
531
532 // These extensions become core in in ES3/WebGL2.
533 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
534
535 GLBuffer buffer;
536 glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
537 EXPECT_GL_ERROR(GL_INVALID_ENUM);
538
539 if (extensionRequestable("GL_NV_pixel_buffer_object"))
540 {
541 glRequestExtensionANGLE("GL_NV_pixel_buffer_object");
542 EXPECT_GL_NO_ERROR();
543
544 glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
545 EXPECT_GL_NO_ERROR();
546
547 glBufferData(GL_PIXEL_PACK_BUFFER, 4, nullptr, GL_STATIC_DRAW);
548 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
549 EXPECT_GL_NO_ERROR();
550 }
551}
552
Geoff Langd54d3042017-11-07 14:56:07 -0500553// Test enabling the GL_EXT_texture_storage extension
554TEST_P(WebGLCompatibilityTest, EnableTextureStorage)
555{
556 EXPECT_FALSE(extensionEnabled("GL_EXT_texture_storage"));
557
558 GLTexture texture;
559 glBindTexture(GL_TEXTURE_2D, texture);
560
561 GLint result;
562 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT, &result);
563 if (getClientMajorVersion() >= 3)
564 {
565 EXPECT_GL_NO_ERROR();
566 }
567 else
568 {
569 EXPECT_GL_ERROR(GL_INVALID_ENUM);
570 }
571
572 if (extensionRequestable("GL_EXT_texture_storage"))
573 {
574 glRequestExtensionANGLE("GL_EXT_texture_storage");
575 EXPECT_GL_NO_ERROR();
576 EXPECT_TRUE(extensionEnabled("GL_EXT_texture_storage"));
577
578 glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_IMMUTABLE_FORMAT, &result);
579 EXPECT_GL_NO_ERROR();
580
581 const GLenum alwaysAcceptableFormats[] = {
582 GL_ALPHA8_EXT, GL_LUMINANCE8_EXT, GL_LUMINANCE8_ALPHA8_EXT,
583 };
584 for (const auto &acceptableFormat : alwaysAcceptableFormats)
585 {
586 GLTexture localTexture;
587 glBindTexture(GL_TEXTURE_2D, localTexture);
588 glTexStorage2DEXT(GL_TEXTURE_2D, 1, acceptableFormat, 1, 1);
589 EXPECT_GL_NO_ERROR();
590 }
591 }
592}
593
Geoff Lang3fab7632017-09-26 15:45:54 -0400594// Test enabling the GL_OES_mapbuffer and GL_EXT_map_buffer_range extensions
595TEST_P(WebGLCompatibilityTest, EnableMapBufferExtensions)
596{
597 EXPECT_FALSE(extensionEnabled("GL_OES_mapbuffer"));
598 EXPECT_FALSE(extensionEnabled("GL_EXT_map_buffer_range"));
599
600 // These extensions become core in in ES3/WebGL2.
601 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
602
603 GLBuffer buffer;
604 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
605 glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4, nullptr, GL_STATIC_DRAW);
606
607 glMapBufferOES(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
608 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
609
610 glMapBufferRangeEXT(GL_ELEMENT_ARRAY_BUFFER, 0, 4, GL_MAP_WRITE_BIT);
611 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
612
613 GLint access = 0;
614 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
615 EXPECT_GL_ERROR(GL_INVALID_ENUM);
616
617 if (extensionRequestable("GL_OES_mapbuffer"))
618 {
619 glRequestExtensionANGLE("GL_OES_mapbuffer");
620 EXPECT_GL_NO_ERROR();
621
622 glMapBufferOES(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
623 glUnmapBufferOES(GL_ELEMENT_ARRAY_BUFFER);
624 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
625 EXPECT_GL_NO_ERROR();
626 }
627
628 if (extensionRequestable("GL_EXT_map_buffer_range"))
629 {
630 glRequestExtensionANGLE("GL_EXT_map_buffer_range");
631 EXPECT_GL_NO_ERROR();
632
633 glMapBufferRangeEXT(GL_ELEMENT_ARRAY_BUFFER, 0, 4, GL_MAP_WRITE_BIT);
634 glUnmapBufferOES(GL_ELEMENT_ARRAY_BUFFER);
635 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
636 EXPECT_GL_NO_ERROR();
637 }
638}
639
Geoff Lang8c7133c2017-09-26 17:31:10 -0400640// Test enabling the GL_OES_fbo_render_mipmap extension
641TEST_P(WebGLCompatibilityTest, EnableRenderMipmapExtension)
642{
643 EXPECT_FALSE(extensionEnabled("GL_OES_fbo_render_mipmap"));
644
645 // This extensions become core in in ES3/WebGL2.
646 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
647
648 GLTexture texture;
649 glBindTexture(GL_TEXTURE_2D, texture);
650 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
651 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
652
653 GLFramebuffer fbo;
654 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
655 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
656 EXPECT_GL_NO_ERROR();
657
658 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
659 EXPECT_GL_ERROR(GL_INVALID_VALUE);
660
661 if (extensionRequestable("GL_OES_fbo_render_mipmap"))
662 {
663 glRequestExtensionANGLE("GL_OES_fbo_render_mipmap");
664 EXPECT_GL_NO_ERROR();
665
666 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
667 EXPECT_GL_NO_ERROR();
668 }
669}
670
Geoff Lang50cac572017-09-26 17:37:43 -0400671// Test enabling the GL_EXT_blend_minmax extension
672TEST_P(WebGLCompatibilityTest, EnableBlendMinMaxExtension)
673{
674 EXPECT_FALSE(extensionEnabled("GL_EXT_blend_minmax"));
675
676 // This extensions become core in in ES3/WebGL2.
677 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
678
679 glBlendEquation(GL_MIN);
680 EXPECT_GL_ERROR(GL_INVALID_ENUM);
681
682 glBlendEquation(GL_MAX);
683 EXPECT_GL_ERROR(GL_INVALID_ENUM);
684
685 if (extensionRequestable("GL_EXT_blend_minmax"))
686 {
687 glRequestExtensionANGLE("GL_EXT_blend_minmax");
688 EXPECT_GL_NO_ERROR();
689
690 glBlendEquation(GL_MIN);
691 glBlendEquation(GL_MAX);
692 EXPECT_GL_NO_ERROR();
693 }
694}
695
Geoff Lang8c5b31c2017-09-26 18:07:44 -0400696// Test enabling the query extensions
697TEST_P(WebGLCompatibilityTest, EnableQueryExtensions)
698{
Jamie Madill8b92c532018-03-22 01:05:02 -0400699 // Seems to be causing a device lost. http://anglebug.com/2423
700 ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsOpenGL());
701
Geoff Lang8c5b31c2017-09-26 18:07:44 -0400702 EXPECT_FALSE(extensionEnabled("GL_EXT_occlusion_query_boolean"));
703 EXPECT_FALSE(extensionEnabled("GL_EXT_disjoint_timer_query"));
704 EXPECT_FALSE(extensionEnabled("GL_CHROMIUM_sync_query"));
705
706 // This extensions become core in in ES3/WebGL2.
707 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
708
709 GLQueryEXT badQuery;
710
711 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, badQuery);
712 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
713
714 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, badQuery);
715 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
716
717 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, badQuery);
718 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
719
720 glQueryCounterEXT(GL_TIMESTAMP_EXT, badQuery);
721 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
722
723 glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, badQuery);
724 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
725
726 if (extensionRequestable("GL_EXT_occlusion_query_boolean"))
727 {
728 glRequestExtensionANGLE("GL_EXT_occlusion_query_boolean");
729 EXPECT_GL_NO_ERROR();
730
731 GLQueryEXT query;
732 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query);
733 glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
734 EXPECT_GL_NO_ERROR();
735 }
736
737 if (extensionRequestable("GL_EXT_disjoint_timer_query"))
738 {
739 glRequestExtensionANGLE("GL_EXT_disjoint_timer_query");
740 EXPECT_GL_NO_ERROR();
741
742 GLQueryEXT query1;
743 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query1);
744 glEndQueryEXT(GL_TIME_ELAPSED_EXT);
745 EXPECT_GL_NO_ERROR();
746
747 GLQueryEXT query2;
748 glQueryCounterEXT(query2, GL_TIMESTAMP_EXT);
749 EXPECT_GL_NO_ERROR();
750 }
751
752 if (extensionRequestable("GL_CHROMIUM_sync_query"))
753 {
754 glRequestExtensionANGLE("GL_CHROMIUM_sync_query");
755 EXPECT_GL_NO_ERROR();
756
757 GLQueryEXT query;
758 glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query);
759 glEndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
760 EXPECT_GL_NO_ERROR();
761 }
762}
763
Geoff Lang488130e2017-09-27 13:53:11 -0400764// Test enabling the GL_ANGLE_framebuffer_multisample extension
765TEST_P(WebGLCompatibilityTest, EnableFramebufferMultisampleExtension)
766{
767 EXPECT_FALSE(extensionEnabled("GL_ANGLE_framebuffer_multisample"));
768
769 // This extensions become core in in ES3/WebGL2.
770 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
771
772 GLint maxSamples = 0;
773 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
774 EXPECT_GL_ERROR(GL_INVALID_ENUM);
775
776 GLRenderbuffer renderbuffer;
777 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
778 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_RGBA4, 1, 1);
779 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
780
781 if (extensionRequestable("GL_ANGLE_framebuffer_multisample"))
782 {
783 glRequestExtensionANGLE("GL_ANGLE_framebuffer_multisample");
784 EXPECT_GL_NO_ERROR();
785
786 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
787 EXPECT_GL_NO_ERROR();
788
789 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, maxSamples, GL_RGBA4, 1, 1);
790 EXPECT_GL_NO_ERROR();
791 }
792}
793
Geoff Lang63c5a592017-09-27 14:08:16 -0400794// Test enabling the GL_ANGLE_instanced_arrays extension
795TEST_P(WebGLCompatibilityTest, EnableInstancedArraysExtension)
796{
797 EXPECT_FALSE(extensionEnabled("GL_ANGLE_instanced_arrays"));
798
799 // This extensions become core in in ES3/WebGL2.
800 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
801
802 GLint divisor = 0;
803 glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &divisor);
804 EXPECT_GL_ERROR(GL_INVALID_ENUM);
805
806 glVertexAttribDivisorANGLE(0, 1);
807 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
808
809 if (extensionRequestable("GL_ANGLE_instanced_arrays"))
810 {
811 glRequestExtensionANGLE("GL_ANGLE_instanced_arrays");
812 EXPECT_GL_NO_ERROR();
813
814 glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &divisor);
815 glVertexAttribDivisorANGLE(0, 1);
816 EXPECT_GL_NO_ERROR();
817 }
818}
819
Geoff Lang000dab82017-09-27 14:27:07 -0400820// Test enabling the GL_ANGLE_pack_reverse_row_order extension
821TEST_P(WebGLCompatibilityTest, EnablePackReverseRowOrderExtension)
822{
823 EXPECT_FALSE(extensionEnabled("GL_ANGLE_pack_reverse_row_order"));
824
825 GLint result = 0;
826 glGetIntegerv(GL_PACK_REVERSE_ROW_ORDER_ANGLE, &result);
827 EXPECT_GL_ERROR(GL_INVALID_ENUM);
828
829 glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE);
830 EXPECT_GL_ERROR(GL_INVALID_ENUM);
831
832 if (extensionRequestable("GL_ANGLE_pack_reverse_row_order"))
833 {
834 glRequestExtensionANGLE("GL_ANGLE_pack_reverse_row_order");
835 EXPECT_GL_NO_ERROR();
836
837 glGetIntegerv(GL_PACK_REVERSE_ROW_ORDER_ANGLE, &result);
838 glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE);
839 EXPECT_GL_NO_ERROR();
840 }
841}
842
843// Test enabling the GL_EXT_unpack_subimage extension
844TEST_P(WebGLCompatibilityTest, EnablePackUnpackSubImageExtension)
845{
846 EXPECT_FALSE(extensionEnabled("GL_EXT_unpack_subimage"));
847
848 // This extensions become core in in ES3/WebGL2.
849 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
850
851 constexpr GLenum parameters[] = {
852 GL_UNPACK_ROW_LENGTH_EXT, GL_UNPACK_SKIP_ROWS_EXT, GL_UNPACK_SKIP_PIXELS_EXT,
853 };
854
855 for (GLenum param : parameters)
856 {
857 GLint resultI = 0;
858 glGetIntegerv(param, &resultI);
859 EXPECT_GL_ERROR(GL_INVALID_ENUM);
860
861 GLfloat resultF = 0.0f;
862 glGetFloatv(param, &resultF);
863 EXPECT_GL_ERROR(GL_INVALID_ENUM);
864
865 glPixelStorei(param, 0);
866 EXPECT_GL_ERROR(GL_INVALID_ENUM);
867 }
868
869 if (extensionRequestable("GL_EXT_unpack_subimage"))
870 {
871 glRequestExtensionANGLE("GL_EXT_unpack_subimage");
872 EXPECT_GL_NO_ERROR();
873
874 for (GLenum param : parameters)
875 {
876 GLint resultI = 0;
877 glGetIntegerv(param, &resultI);
878
879 GLfloat resultF = 0.0f;
880 glGetFloatv(param, &resultF);
881
882 glPixelStorei(param, 0);
883
884 EXPECT_GL_NO_ERROR();
885 }
886 }
887}
888
Geoff Lang4751aab2017-10-30 15:14:52 -0400889TEST_P(WebGLCompatibilityTest, EnableTextureRectangle)
890{
891 EXPECT_FALSE(extensionEnabled("GL_ANGLE_texture_rectangle"));
892
893 GLTexture texture;
894 glBindTexture(GL_TEXTURE_RECTANGLE_ANGLE, texture);
895 EXPECT_GL_ERROR(GL_INVALID_ENUM);
896
897 GLint minFilter = 0;
898 glGetTexParameteriv(GL_TEXTURE_RECTANGLE_ANGLE, GL_TEXTURE_MIN_FILTER, &minFilter);
899 EXPECT_GL_ERROR(GL_INVALID_ENUM);
900
901 if (extensionRequestable("GL_ANGLE_texture_rectangle"))
902 {
903 glRequestExtensionANGLE("GL_ANGLE_texture_rectangle");
904 EXPECT_GL_NO_ERROR();
905
906 EXPECT_TRUE(extensionEnabled("GL_ANGLE_texture_rectangle"));
907
908 glBindTexture(GL_TEXTURE_RECTANGLE_ANGLE, texture);
909 EXPECT_GL_NO_ERROR();
910
911 glTexImage2D(GL_TEXTURE_RECTANGLE_ANGLE, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
912 nullptr);
913 EXPECT_GL_NO_ERROR();
914 }
915}
916
Geoff Lang000dab82017-09-27 14:27:07 -0400917// Test enabling the GL_NV_pack_subimage extension
918TEST_P(WebGLCompatibilityTest, EnablePackPackSubImageExtension)
919{
920 EXPECT_FALSE(extensionEnabled("GL_NV_pack_subimage"));
921
922 // This extensions become core in in ES3/WebGL2.
923 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
924
925 constexpr GLenum parameters[] = {
926 GL_PACK_ROW_LENGTH, GL_PACK_SKIP_ROWS, GL_PACK_SKIP_PIXELS,
927 };
928
929 for (GLenum param : parameters)
930 {
931 GLint resultI = 0;
932 glGetIntegerv(param, &resultI);
933 EXPECT_GL_ERROR(GL_INVALID_ENUM);
934
935 GLfloat resultF = 0.0f;
936 glGetFloatv(param, &resultF);
937 EXPECT_GL_ERROR(GL_INVALID_ENUM);
938
939 glPixelStorei(param, 0);
940 EXPECT_GL_ERROR(GL_INVALID_ENUM);
941 }
942
943 if (extensionRequestable("GL_NV_pack_subimage"))
944 {
945 glRequestExtensionANGLE("GL_NV_pack_subimage");
946 EXPECT_GL_NO_ERROR();
947
948 for (GLenum param : parameters)
949 {
950 GLint resultI = 0;
951 glGetIntegerv(param, &resultI);
952
953 GLfloat resultF = 0.0f;
954 glGetFloatv(param, &resultF);
955
956 glPixelStorei(param, 0);
957
958 EXPECT_GL_NO_ERROR();
959 }
960 }
961}
962
Geoff Langd84a00b2017-10-27 17:27:26 -0400963TEST_P(WebGLCompatibilityTest, EnableRGB8RGBA8Extension)
964{
965 EXPECT_FALSE(extensionEnabled("GL_OES_rgb8_rgba8"));
966
967 // This extensions become core in in ES3/WebGL2.
968 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
969
970 GLRenderbuffer renderbuffer;
971 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
972 EXPECT_GL_NO_ERROR();
973
974 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB8_OES, 1, 1);
975 EXPECT_GL_ERROR(GL_INVALID_ENUM);
976
977 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, 1, 1);
978 EXPECT_GL_ERROR(GL_INVALID_ENUM);
979
980 if (extensionRequestable("GL_OES_rgb8_rgba8"))
981 {
982 glRequestExtensionANGLE("GL_OES_rgb8_rgba8");
983 EXPECT_GL_NO_ERROR();
984
985 EXPECT_TRUE(extensionEnabled("GL_OES_rgb8_rgba8"));
986
987 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB8_OES, 1, 1);
988 EXPECT_GL_NO_ERROR();
989
990 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, 1, 1);
991 EXPECT_GL_NO_ERROR();
992 }
993}
994
Geoff Lange8afa902017-09-27 15:00:43 -0400995// Test enabling the GL_ANGLE_framebuffer_blit extension
996TEST_P(WebGLCompatibilityTest, EnableFramebufferBlitExtension)
997{
998 EXPECT_FALSE(extensionEnabled("GL_ANGLE_framebuffer_blit"));
999
1000 // This extensions become core in in ES3/WebGL2.
1001 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
1002
1003 GLFramebuffer fbo;
1004
1005 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, fbo);
1006 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1007
1008 GLint result;
1009 glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING_ANGLE, &result);
1010 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1011
1012 glBlitFramebufferANGLE(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST);
1013 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1014
1015 if (extensionRequestable("GL_ANGLE_framebuffer_blit"))
1016 {
1017 glRequestExtensionANGLE("GL_ANGLE_framebuffer_blit");
1018 EXPECT_GL_NO_ERROR();
1019
1020 glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, fbo);
1021 glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING_ANGLE, &result);
1022 EXPECT_GL_NO_ERROR();
1023 }
1024}
1025
Geoff Lang2348e212017-09-27 17:46:25 -04001026// Test enabling the GL_OES_get_program_binary extension
1027TEST_P(WebGLCompatibilityTest, EnableProgramBinaryExtension)
1028{
1029 EXPECT_FALSE(extensionEnabled("GL_OES_get_program_binary"));
1030
1031 // This extensions become core in in ES3/WebGL2.
1032 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
1033
1034 GLint result = 0;
1035 glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &result);
1036 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1037
1038 glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, &result);
1039 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1040
1041 const std::string &vert =
1042 "void main()\n"
1043 "{\n"
1044 " gl_Position = vec4(0.0, 0.0, 0.0, 1.0);\n"
1045 "}\n";
1046 const std::string &frag =
1047 "precision highp float;\n"
1048 "void main()\n"
1049 "{\n"
1050 " gl_FragColor = vec4(1.0);\n"
1051 "}\n";
1052 ANGLE_GL_PROGRAM(program, vert, frag);
1053
1054 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &result);
1055 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1056
1057 uint8_t tempArray[512];
1058 GLenum tempFormat = 0;
1059 GLsizei tempLength = 0;
1060 glGetProgramBinaryOES(program, static_cast<GLsizei>(ArraySize(tempArray)), &tempLength,
1061 &tempFormat, tempArray);
1062 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1063
1064 if (extensionRequestable("GL_OES_get_program_binary"))
1065 {
1066 glRequestExtensionANGLE("GL_OES_get_program_binary");
1067 EXPECT_GL_NO_ERROR();
1068
1069 glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &result);
1070 glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, &result);
1071 EXPECT_GL_NO_ERROR();
1072
1073 GLint binaryLength = 0;
1074 glGetProgramiv(program, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
1075 EXPECT_GL_NO_ERROR();
1076
1077 GLenum binaryFormat;
1078 GLsizei writeLength = 0;
1079 std::vector<uint8_t> binary(binaryLength);
1080 glGetProgramBinaryOES(program, binaryLength, &writeLength, &binaryFormat, binary.data());
1081 EXPECT_GL_NO_ERROR();
1082
1083 glProgramBinaryOES(program, binaryFormat, binary.data(), binaryLength);
1084 EXPECT_GL_NO_ERROR();
1085 }
1086}
1087
Geoff Langb0f917f2017-12-05 13:41:54 -05001088// Test enabling the GL_OES_vertex_array_object extension
1089TEST_P(WebGLCompatibilityTest, EnableVertexArrayExtension)
1090{
1091 EXPECT_FALSE(extensionEnabled("GL_OES_vertex_array_object"));
1092
1093 // This extensions become core in in ES3/WebGL2.
1094 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
1095
1096 GLint result = 0;
1097 glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &result);
1098 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1099
1100 // Expect that GL_OES_vertex_array_object is always available. It is implemented in the GL
1101 // frontend.
1102 EXPECT_TRUE(extensionRequestable("GL_OES_vertex_array_object"));
1103
1104 glRequestExtensionANGLE("GL_OES_vertex_array_object");
1105 EXPECT_GL_NO_ERROR();
1106
1107 EXPECT_TRUE(extensionEnabled("GL_OES_vertex_array_object"));
1108
1109 glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &result);
1110 EXPECT_GL_NO_ERROR();
1111
1112 GLuint vao = 0;
1113 glGenVertexArraysOES(0, &vao);
1114 EXPECT_GL_NO_ERROR();
1115
1116 glBindVertexArrayOES(vao);
1117 EXPECT_GL_NO_ERROR();
1118
1119 glDeleteVertexArraysOES(1, &vao);
1120 EXPECT_GL_NO_ERROR();
1121}
1122
Geoff Langa0e0aeb2017-04-12 15:06:29 -04001123// Verify that the context generates the correct error when the framebuffer attachments are
1124// different sizes
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001125TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMismatch)
Geoff Langa0e0aeb2017-04-12 15:06:29 -04001126{
1127 GLFramebuffer fbo;
1128 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1129
1130 GLTexture textures[2];
1131 glBindTexture(GL_TEXTURE_2D, textures[0]);
1132 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1133 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
1134
1135 ASSERT_GL_NO_ERROR();
1136 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1137
1138 GLRenderbuffer renderbuffer;
1139 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
1140 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3);
1141 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
1142
1143 ASSERT_GL_NO_ERROR();
1144 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
1145 glCheckFramebufferStatus(GL_FRAMEBUFFER));
1146
1147 if (extensionRequestable("GL_EXT_draw_buffers"))
1148 {
1149 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1150 EXPECT_GL_NO_ERROR();
1151 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1152
1153 glBindTexture(GL_TEXTURE_2D, textures[1]);
1154 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1155 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
1156 ASSERT_GL_NO_ERROR();
1157
1158 ASSERT_GL_NO_ERROR();
1159 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
1160 glCheckFramebufferStatus(GL_FRAMEBUFFER));
1161
1162 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
1163
1164 ASSERT_GL_NO_ERROR();
1165 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1166
1167 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1168
1169 ASSERT_GL_NO_ERROR();
1170 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
1171 glCheckFramebufferStatus(GL_FRAMEBUFFER));
1172 }
1173}
1174
Corentin Wallez327411e2016-12-09 11:09:17 -05001175// Test that client-side array buffers are forbidden in WebGL mode
1176TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
1177{
1178 const std::string &vert =
1179 "attribute vec3 a_pos;\n"
1180 "void main()\n"
1181 "{\n"
1182 " gl_Position = vec4(a_pos, 1.0);\n"
1183 "}\n";
1184
1185 const std::string &frag =
1186 "precision highp float;\n"
1187 "void main()\n"
1188 "{\n"
1189 " gl_FragColor = vec4(1.0);\n"
1190 "}\n";
1191
1192 ANGLE_GL_PROGRAM(program, vert, frag);
1193
1194 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1195 ASSERT_NE(-1, posLocation);
1196 glUseProgram(program.get());
1197
1198 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -05001199 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -05001200 glEnableVertexAttribArray(posLocation);
1201
1202 ASSERT_GL_NO_ERROR();
1203 glDrawArrays(GL_TRIANGLES, 0, 6);
1204 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1205}
1206
1207// Test that client-side element array buffers are forbidden in WebGL mode
1208TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
1209{
1210 const std::string &vert =
1211 "attribute vec3 a_pos;\n"
1212 "void main()\n"
1213 "{\n"
1214 " gl_Position = vec4(a_pos, 1.0);\n"
1215 "}\n";
1216
1217 const std::string &frag =
1218 "precision highp float;\n"
1219 "void main()\n"
1220 "{\n"
1221 " gl_FragColor = vec4(1.0);\n"
1222 "}\n";
1223
1224 ANGLE_GL_PROGRAM(program, vert, frag);
1225
1226 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1227 ASSERT_NE(-1, posLocation);
1228 glUseProgram(program.get());
1229
1230 const auto &vertices = GetQuadVertices();
1231
1232 GLBuffer vertexBuffer;
1233 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1234 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1235 GL_STATIC_DRAW);
1236
1237 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1238 glEnableVertexAttribArray(posLocation);
1239
Corentin Wallez327411e2016-12-09 11:09:17 -05001240 ASSERT_GL_NO_ERROR();
Corentin Wallezded1b5a2017-03-09 18:58:48 -05001241
1242 // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also
1243 // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate
1244 // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check.
1245 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1)));
Corentin Wallez327411e2016-12-09 11:09:17 -05001246 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1247}
1248
Corentin Wallez672f7f32017-06-15 17:42:17 -04001249// Test that client-side array buffers are forbidden even if the program doesn't use the attribute
1250TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes)
1251{
1252 const std::string &vert =
1253 "void main()\n"
1254 "{\n"
1255 " gl_Position = vec4(1.0);\n"
1256 "}\n";
1257
1258 const std::string &frag =
1259 "precision highp float;\n"
1260 "void main()\n"
1261 "{\n"
1262 " gl_FragColor = vec4(1.0);\n"
1263 "}\n";
1264
1265 ANGLE_GL_PROGRAM(program, vert, frag);
1266
1267 glUseProgram(program.get());
1268
1269 const auto &vertices = GetQuadVertices();
1270 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
1271 glEnableVertexAttribArray(0);
1272
1273 ASSERT_GL_NO_ERROR();
1274 glDrawArrays(GL_TRIANGLES, 0, 6);
1275 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1276}
1277
Geoff Langfb052642017-10-24 13:42:09 -04001278// Test that passing a null pixel data pointer to TexSubImage calls generates an INVALID_VALUE error
1279TEST_P(WebGLCompatibilityTest, NullPixelDataForSubImage)
1280{
1281 // glTexSubImage2D
1282 {
1283 GLTexture texture;
1284 glBindTexture(GL_TEXTURE_2D, texture);
1285
1286 // TexImage with null data - OK
1287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1288 EXPECT_GL_NO_ERROR();
1289
1290 // TexSubImage with zero size and null data - OK
1291 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1292 EXPECT_GL_NO_ERROR();
1293
1294 // TexSubImage with non-zero size and null data - Invalid value
1295 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1296 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1297 }
1298
1299 // glTexSubImage3D
1300 if (getClientMajorVersion() >= 3)
1301 {
1302 GLTexture texture;
1303 glBindTexture(GL_TEXTURE_3D, texture);
1304
1305 // TexImage with null data - OK
1306 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1307 EXPECT_GL_NO_ERROR();
1308
1309 // TexSubImage with zero size and null data - OK
1310 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1311 EXPECT_GL_NO_ERROR();
1312
1313 // TexSubImage with non-zero size and null data - Invalid value
1314 glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1315 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1316 }
1317}
1318
Ken Russellb9f92502018-01-27 19:00:26 -08001319// Tests the WebGL requirement of having the same stencil mask, writemask and ref for front and back
1320// (when stencil testing is enabled)
1321void WebGLCompatibilityTest::TestDifferentStencilMaskAndRef(GLenum errIfMismatch)
Corentin Wallezb1d0a2552016-12-19 16:15:54 -05001322{
1323 // Run the test in an FBO to make sure we have some stencil bits.
1324 GLRenderbuffer renderbuffer;
1325 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
1326 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
1327
1328 GLFramebuffer framebuffer;
1329 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1330 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
1331 renderbuffer.get());
1332
1333 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
1334 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
1335 glUseProgram(program.get());
1336 ASSERT_GL_NO_ERROR();
1337
1338 // Having ref and mask the same for front and back is valid.
1339 glStencilMask(255);
1340 glStencilFunc(GL_ALWAYS, 0, 255);
1341 glDrawArrays(GL_TRIANGLES, 0, 6);
1342 ASSERT_GL_NO_ERROR();
1343
1344 // Having a different front - back write mask generates an error.
1345 glStencilMaskSeparate(GL_FRONT, 1);
1346 glDrawArrays(GL_TRIANGLES, 0, 6);
Ken Russellb9f92502018-01-27 19:00:26 -08001347 EXPECT_GL_ERROR(errIfMismatch);
Corentin Wallezb1d0a2552016-12-19 16:15:54 -05001348
1349 // Setting both write masks separately to the same value is valid.
1350 glStencilMaskSeparate(GL_BACK, 1);
1351 glDrawArrays(GL_TRIANGLES, 0, 6);
1352 ASSERT_GL_NO_ERROR();
1353
1354 // Having a different stencil front - back mask generates an error
1355 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
1356 glDrawArrays(GL_TRIANGLES, 0, 6);
Ken Russellb9f92502018-01-27 19:00:26 -08001357 EXPECT_GL_ERROR(errIfMismatch);
Corentin Wallezb1d0a2552016-12-19 16:15:54 -05001358
1359 // Setting both masks separately to the same value is valid.
1360 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
1361 glDrawArrays(GL_TRIANGLES, 0, 6);
1362 ASSERT_GL_NO_ERROR();
1363
1364 // Having a different stencil front - back reference generates an error
1365 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
1366 glDrawArrays(GL_TRIANGLES, 0, 6);
Ken Russellb9f92502018-01-27 19:00:26 -08001367 EXPECT_GL_ERROR(errIfMismatch);
Corentin Wallezb1d0a2552016-12-19 16:15:54 -05001368
1369 // Setting both references separately to the same value is valid.
1370 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
1371 glDrawArrays(GL_TRIANGLES, 0, 6);
1372 ASSERT_GL_NO_ERROR();
1373
1374 // Using different stencil funcs, everything being equal is valid.
1375 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
1376 glDrawArrays(GL_TRIANGLES, 0, 6);
1377 ASSERT_GL_NO_ERROR();
1378}
Ken Russellb9f92502018-01-27 19:00:26 -08001379TEST_P(WebGLCompatibilityTest, StencilTestEnabledDisallowsDifferentStencilMaskAndRef)
1380{
1381 glEnable(GL_STENCIL_TEST);
1382 TestDifferentStencilMaskAndRef(GL_INVALID_OPERATION);
1383}
1384TEST_P(WebGLCompatibilityTest, StencilTestDisabledAllowsDifferentStencilMaskAndRef)
1385{
1386 glDisable(GL_STENCIL_TEST);
1387 TestDifferentStencilMaskAndRef(GL_NO_ERROR);
1388}
Corentin Wallezb1d0a2552016-12-19 16:15:54 -05001389
Corentin Wallez506fc9c2016-12-21 16:53:33 -05001390// Test that GL_FIXED is forbidden
1391TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
1392{
1393 GLBuffer buffer;
1394 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1395 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1396
1397 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
1398 ASSERT_GL_NO_ERROR();
1399
1400 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
1401 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1402}
1403
1404// Test the WebGL limit of 255 for the attribute stride
1405TEST_P(WebGLCompatibilityTest, MaxStride)
1406{
1407 GLBuffer buffer;
1408 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1409 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
1410
1411 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
1412 ASSERT_GL_NO_ERROR();
1413
1414 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
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, non-instanced version
1419TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
1420{
1421 const std::string &vert =
1422 "attribute float a_pos;\n"
1423 "void main()\n"
1424 "{\n"
1425 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1426 "}\n";
1427
Olli Etuaho5804dc82018-04-13 14:11:46 +03001428 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallezfd456442016-12-21 17:57:00 -05001429 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1430 ASSERT_NE(-1, posLocation);
1431 glUseProgram(program.get());
1432
1433 GLBuffer buffer;
1434 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1435 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1436
1437 glEnableVertexAttribArray(posLocation);
1438
1439 const uint8_t* zeroOffset = nullptr;
1440
1441 // Test touching the last element is valid.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001442 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
Corentin Wallezfd456442016-12-21 17:57:00 -05001443 glDrawArrays(GL_POINTS, 0, 4);
1444 ASSERT_GL_NO_ERROR();
1445
1446 // Test touching the last element + 1 is invalid.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001447 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
Corentin Wallezfd456442016-12-21 17:57:00 -05001448 glDrawArrays(GL_POINTS, 0, 4);
1449 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1450
1451 // Test touching the last element is valid, using a stride.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001452 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
Corentin Wallezfd456442016-12-21 17:57:00 -05001453 glDrawArrays(GL_POINTS, 0, 4);
1454 ASSERT_GL_NO_ERROR();
1455
1456 // Test touching the last element + 1 is invalid, using a stride.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001457 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
Corentin Wallezfd456442016-12-21 17:57:00 -05001458 glDrawArrays(GL_POINTS, 0, 4);
1459 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1460
1461 // Test any offset is valid if no vertices are drawn.
Corentin Wallez91c8de82017-10-12 16:32:44 -04001462 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
Corentin Wallezfd456442016-12-21 17:57:00 -05001463 glDrawArrays(GL_POINTS, 0, 0);
1464 ASSERT_GL_NO_ERROR();
Corentin Wallez91c8de82017-10-12 16:32:44 -04001465
1466 // Test a case of overflow that could give a max vertex that's negative
1467 constexpr GLint kIntMax = std::numeric_limits<GLint>::max();
1468 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 0);
1469 glDrawArrays(GL_POINTS, kIntMax, kIntMax);
1470 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1471}
1472
1473// Test the checks for OOB reads in the vertex buffers, instanced version
1474TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
1475{
1476 const std::string &vert =
1477 "attribute float a_pos;\n"
1478 "attribute float a_w;\n"
1479 "void main()\n"
1480 "{\n"
1481 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1482 "}\n";
1483
Olli Etuaho5804dc82018-04-13 14:11:46 +03001484 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez91c8de82017-10-12 16:32:44 -04001485 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1486 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1487 ASSERT_NE(-1, posLocation);
1488 ASSERT_NE(-1, wLocation);
1489 glUseProgram(program.get());
1490
1491 GLBuffer buffer;
1492 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1493 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1494
1495 glEnableVertexAttribArray(posLocation);
1496 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1497 glVertexAttribDivisor(posLocation, 0);
1498
1499 glEnableVertexAttribArray(wLocation);
1500 glVertexAttribDivisor(wLocation, 1);
1501
1502 const uint8_t* zeroOffset = nullptr;
1503
1504 // Test touching the last element is valid.
1505 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1506 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1507 ASSERT_GL_NO_ERROR();
1508
1509 // Test touching the last element + 1 is invalid.
1510 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1511 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1512 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1513
1514 // Test touching the last element is valid, using a stride.
1515 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1516 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1517 ASSERT_GL_NO_ERROR();
1518
1519 // Test touching the last element + 1 is invalid, using a stride.
1520 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1521 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1522 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1523
1524 // Test any offset is valid if no vertices are drawn.
1525 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1526 glDrawArraysInstanced(GL_POINTS, 0, 0, 1);
1527 ASSERT_GL_NO_ERROR();
1528
1529 // Test any offset is valid if no primitives are drawn.
1530 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1531 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1532 ASSERT_GL_NO_ERROR();
1533}
1534
1535// Test the checks for OOB reads in the vertex buffers, ANGLE_instanced_arrays version
1536TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsInstancedANGLE)
1537{
1538 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_ANGLE_instanced_arrays"));
1539 glRequestExtensionANGLE("GL_ANGLE_instanced_arrays");
1540 EXPECT_GL_NO_ERROR();
1541
1542 const std::string &vert =
1543 "attribute float a_pos;\n"
1544 "attribute float a_w;\n"
1545 "void main()\n"
1546 "{\n"
1547 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1548 "}\n";
1549
Olli Etuaho5804dc82018-04-13 14:11:46 +03001550 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez91c8de82017-10-12 16:32:44 -04001551 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1552 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1553 ASSERT_NE(-1, posLocation);
1554 ASSERT_NE(-1, wLocation);
1555 glUseProgram(program.get());
1556
1557 GLBuffer buffer;
1558 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1559 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1560
1561 glEnableVertexAttribArray(posLocation);
1562 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1563 glVertexAttribDivisorANGLE(posLocation, 0);
1564
1565 glEnableVertexAttribArray(wLocation);
1566 glVertexAttribDivisorANGLE(wLocation, 1);
1567
1568 const uint8_t* zeroOffset = nullptr;
1569
1570 // Test touching the last element is valid.
1571 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1572 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1573 ASSERT_GL_NO_ERROR();
1574
1575 // Test touching the last element + 1 is invalid.
1576 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1577 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1578 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1579
1580 // Test touching the last element is valid, using a stride.
1581 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1582 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1583 ASSERT_GL_NO_ERROR();
1584
1585 // Test touching the last element + 1 is invalid, using a stride.
1586 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1587 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1588 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1589
1590 // Test any offset is valid if no vertices are drawn.
1591 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1592 glDrawArraysInstancedANGLE(GL_POINTS, 0, 0, 1);
1593 ASSERT_GL_NO_ERROR();
1594
1595 // Test any offset is valid if no primitives are drawn.
1596 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1597 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 0);
1598 ASSERT_GL_NO_ERROR();
Corentin Wallezfd456442016-12-21 17:57:00 -05001599}
1600
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001601// Test the checks for OOB reads in the index buffer
1602TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -05001603{
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001604 const std::string &vert =
1605 "attribute float a_pos;\n"
1606 "void main()\n"
1607 "{\n"
1608 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1609 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -05001610
Olli Etuaho5804dc82018-04-13 14:11:46 +03001611 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001612 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1613 ASSERT_NE(-1, posLocation);
1614 glUseProgram(program.get());
1615
1616 GLBuffer vertexBuffer;
1617 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1618 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1619
1620 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001621 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001622
1623 const uint8_t *zeroOffset = nullptr;
1624 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
1625
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001626 GLBuffer indexBuffer;
1627 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1628 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -05001629 ASSERT_GL_NO_ERROR();
1630
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001631 // Test touching the last index is valid
1632 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1633 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -05001634
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001635 // Test touching the last + 1 element is invalid
1636 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
1637 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -05001638
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001639 // Test any offset if valid if count is zero
1640 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
1641 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -05001642
1643 // Test touching the first index is valid
1644 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1645 ASSERT_GL_NO_ERROR();
1646
1647 // Test touching the first - 1 index is invalid
1648 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
1649 // the historic behavior of WebGL implementations
1650 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
1651 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -05001652}
1653
Corentin Wallez91c8de82017-10-12 16:32:44 -04001654// Test the checks for OOB in vertex buffers caused by indices, non-instanced version
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001655TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInVertexBuffer)
1656{
1657 const std::string &vert =
1658 "attribute float a_pos;\n"
1659 "void main()\n"
1660 "{\n"
1661 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1662 "}\n";
1663
Olli Etuaho5804dc82018-04-13 14:11:46 +03001664 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001665 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1666 ASSERT_NE(-1, posLocation);
1667 glUseProgram(program.get());
1668
1669 GLBuffer vertexBuffer;
1670 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1671 glBufferData(GL_ARRAY_BUFFER, 8, nullptr, GL_STATIC_DRAW);
1672
1673 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001674 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001675
1676 const uint8_t *zeroOffset = nullptr;
1677 const uint8_t testIndices[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 255};
1678
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001679 GLBuffer indexBuffer;
1680 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1681 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(testIndices), testIndices, GL_STATIC_DRAW);
1682 ASSERT_GL_NO_ERROR();
1683
1684 // Test touching the end of the vertex buffer is valid
1685 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 7);
1686 ASSERT_GL_NO_ERROR();
1687
1688 // Test touching just after the end of the vertex buffer is invalid
1689 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 8);
1690 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1691
1692 // Test touching the whole vertex buffer is valid
1693 glDrawElements(GL_POINTS, 8, GL_UNSIGNED_BYTE, zeroOffset + 0);
1694 ASSERT_GL_NO_ERROR();
1695
1696 // Test an index that would be negative
1697 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 9);
1698 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1699}
1700
Frank Henigman6137ddc2017-02-10 18:55:07 -05001701// Test depth range with 'near' more or less than 'far.'
1702TEST_P(WebGLCompatibilityTest, DepthRange)
1703{
1704 glDepthRangef(0, 1);
1705 ASSERT_GL_NO_ERROR();
1706
1707 glDepthRangef(.5, .5);
1708 ASSERT_GL_NO_ERROR();
1709
1710 glDepthRangef(1, 0);
1711 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1712}
1713
Frank Henigman146e8a12017-03-02 23:22:37 -05001714// Test all blend function combinations.
1715// In WebGL it is invalid to combine constant color with constant alpha.
1716TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
1717{
1718 constexpr GLenum srcFunc[] = {
1719 GL_ZERO,
1720 GL_ONE,
1721 GL_SRC_COLOR,
1722 GL_ONE_MINUS_SRC_COLOR,
1723 GL_DST_COLOR,
1724 GL_ONE_MINUS_DST_COLOR,
1725 GL_SRC_ALPHA,
1726 GL_ONE_MINUS_SRC_ALPHA,
1727 GL_DST_ALPHA,
1728 GL_ONE_MINUS_DST_ALPHA,
1729 GL_CONSTANT_COLOR,
1730 GL_ONE_MINUS_CONSTANT_COLOR,
1731 GL_CONSTANT_ALPHA,
1732 GL_ONE_MINUS_CONSTANT_ALPHA,
1733 GL_SRC_ALPHA_SATURATE,
1734 };
1735
1736 constexpr GLenum dstFunc[] = {
1737 GL_ZERO, GL_ONE,
1738 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1739 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1740 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1741 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
1742 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
1743 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
1744 };
1745
1746 for (GLenum src : srcFunc)
1747 {
1748 for (GLenum dst : dstFunc)
1749 {
1750 glBlendFunc(src, dst);
1751 CheckBlendFunctions(src, dst);
1752 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
1753 CheckBlendFunctions(src, dst);
1754 }
1755 }
1756}
1757
Geoff Langfc32e8b2017-05-31 14:16:59 -04001758// Test that binding/querying uniforms and attributes with invalid names generates errors
1759TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
1760{
1761 const std::string validAttribName =
1762 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
1763 const std::string validUniformName =
1764 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
Geoff Langa71a98e2017-06-19 15:15:00 -04001765 std::vector<char> invalidSet = {'"', '$', '`', '@', '\''};
1766 if (getClientMajorVersion() < 3)
1767 {
1768 invalidSet.push_back('\\');
1769 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04001770
1771 std::string vert = "attribute float ";
1772 vert += validAttribName;
1773 vert +=
1774 ";\n"
1775 "void main()\n"
1776 "{\n"
1777 " gl_Position = vec4(1.0);\n"
1778 "}\n";
1779
1780 std::string frag =
1781 "precision highp float;\n"
1782 "uniform vec4 ";
1783 frag += validUniformName;
Geoff Langcab92ee2017-07-19 17:32:07 -04001784 // Insert illegal characters into comments
Geoff Langfc32e8b2017-05-31 14:16:59 -04001785 frag +=
1786 ";\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001787 " // $ \" @ /*\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001788 "void main()\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001789 "{/*\n"
1790 " ` @ $\n"
1791 " */gl_FragColor = vec4(1.0);\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001792 "}\n";
1793
1794 ANGLE_GL_PROGRAM(program, vert, frag);
1795 EXPECT_GL_NO_ERROR();
1796
1797 for (char invalidChar : invalidSet)
1798 {
1799 std::string invalidName = validAttribName + invalidChar;
1800 glGetAttribLocation(program, invalidName.c_str());
1801 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1802 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1803
1804 glBindAttribLocation(program, 0, invalidName.c_str());
1805 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1806 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1807 }
1808
1809 for (char invalidChar : invalidSet)
1810 {
1811 std::string invalidName = validUniformName + invalidChar;
1812 glGetUniformLocation(program, invalidName.c_str());
1813 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1814 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1815 }
1816
1817 for (char invalidChar : invalidSet)
1818 {
1819 std::string invalidAttribName = validAttribName + invalidChar;
1820 const char *invalidVert[] = {
1821 "attribute float ",
1822 invalidAttribName.c_str(),
1823 ";\n",
1824 "void main()\n",
1825 "{\n",
1826 " gl_Position = vec4(1.0);\n",
1827 "}\n",
1828 };
1829
1830 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1831 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
1832 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1833 glDeleteShader(shader);
1834 }
1835}
1836
Geoff Langcab92ee2017-07-19 17:32:07 -04001837// Test that line continuation is handled correctly when valdiating shader source
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -07001838TEST_P(WebGLCompatibilityTest, ShaderSourceLineContinuation)
1839{
1840 // Verify that a line continuation character (i.e. backslash) cannot be used
1841 // within a preprocessor directive in a ES2 context.
1842 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
1843
1844 const char *validVert =
1845 "#define foo this is a test\n"
1846 "precision mediump float;\n"
1847 "void main()\n"
1848 "{\n"
1849 " gl_Position = vec4(1.0);\n"
1850 "}\n";
1851
1852 const char *invalidVert =
1853 "#define foo this \\n"
1854 " is a test\n"
1855 "precision mediump float;\n"
1856 "void main()\n"
1857 "{\n"
1858 " gl_Position = vec4(1.0);\n"
1859 "}\n";
1860
1861 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1862 glShaderSource(shader, 1, &validVert, nullptr);
1863 EXPECT_GL_NO_ERROR();
1864
1865 glShaderSource(shader, 1, &invalidVert, nullptr);
1866 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1867 glDeleteShader(shader);
1868}
1869
1870// Test that line continuation is handled correctly when valdiating shader source
Geoff Langcab92ee2017-07-19 17:32:07 -04001871TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
1872{
1873 const char *validVert =
1874 "#version 300 es\n"
1875 "precision mediump float;\n"
1876 "\n"
1877 "void main ()\n"
1878 "{\n"
1879 " float f\\\n"
1880 "oo = 1.0;\n"
1881 " gl_Position = vec4(foo);\n"
1882 "}\n";
1883
1884 const char *invalidVert =
1885 "#version 300 es\n"
1886 "precision mediump float;\n"
1887 "\n"
1888 "void main ()\n"
1889 "{\n"
1890 " float f\\$\n"
1891 "oo = 1.0;\n"
1892 " gl_Position = vec4(foo);\n"
1893 "}\n";
1894
1895 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1896 glShaderSource(shader, 1, &validVert, nullptr);
1897 EXPECT_GL_NO_ERROR();
1898 glShaderSource(shader, 1, &invalidVert, nullptr);
1899 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1900 glDeleteShader(shader);
1901}
1902
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001903// Tests bindAttribLocations for reserved prefixes and length limits
1904TEST_P(WebGLCompatibilityTest, BindAttribLocationLimitation)
1905{
1906 constexpr int maxLocStringLength = 256;
1907 const std::string tooLongString(maxLocStringLength + 1, '_');
1908
1909 glBindAttribLocation(0, 0, "_webgl_var");
1910
1911 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1912
1913 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
1914
1915 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1916}
1917
Corentin Wallez0dc97812017-06-22 14:38:44 -04001918// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001919TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1920{
1921 const std::string &vert =
1922 "attribute float a_pos;\n"
1923 "void main()\n"
1924 "{\n"
1925 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1926 "}\n";
1927
Olli Etuaho5804dc82018-04-13 14:11:46 +03001928 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Geoff Lang407d4e72017-04-12 14:54:11 -04001929
1930 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1931 ASSERT_NE(-1, posLocation);
1932
1933 glUseProgram(program.get());
1934
1935 GLBuffer buffer;
1936 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1937 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1938
1939 glEnableVertexAttribArray(posLocation);
1940 glVertexAttribDivisor(posLocation, 1);
1941
Geoff Lang407d4e72017-04-12 14:54:11 -04001942 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1943 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04001944 ASSERT_GL_NO_ERROR();
1945}
1946
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001947// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1948TEST_P(WebGLCompatibilityTest, NPOT)
1949{
1950 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1951
1952 // Create a texture and set an NPOT mip 0, should always be acceptable.
1953 GLTexture texture;
1954 glBindTexture(GL_TEXTURE_2D, texture.get());
1955 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1956 ASSERT_GL_NO_ERROR();
1957
1958 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1959 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1960 if (getClientMajorVersion() < 3)
1961 {
1962 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1963 }
1964 else
1965 {
1966 ASSERT_GL_NO_ERROR();
1967 }
1968
1969 if (extensionRequestable("GL_OES_texture_npot"))
1970 {
1971 glRequestExtensionANGLE("GL_OES_texture_npot");
1972 ASSERT_GL_NO_ERROR();
1973
1974 // Try again to set NPOT mip 1
1975 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1976 ASSERT_GL_NO_ERROR();
1977 }
1978}
1979
Jamie Madillcad97ee2017-02-02 18:52:44 -05001980template <typename T>
1981void FillTexture2D(GLuint texture,
1982 GLsizei width,
1983 GLsizei height,
1984 const T &onePixelData,
1985 GLint level,
1986 GLint internalFormat,
1987 GLenum format,
1988 GLenum type)
1989{
1990 std::vector<T> allPixelsData(width * height, onePixelData);
1991
1992 glBindTexture(GL_TEXTURE_2D, texture);
1993 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
1994 allPixelsData.data());
1995 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1999}
2000
Frank Henigman875bbba2017-02-08 16:38:17 -05002001// Test that unset gl_Position defaults to (0,0,0,0).
2002TEST_P(WebGLCompatibilityTest, DefaultPosition)
2003{
2004 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
2005 // and green otherwise. The center of each quadrant will be red if and only if all
2006 // four corners are red.
2007 const std::string vertexShader =
2008 "attribute vec3 pos;\n"
2009 "varying vec4 color;\n"
2010 "void main() {\n"
2011 " if (gl_Position == vec4(0,0,0,0)) {\n"
2012 " color = vec4(1,0,0,1);\n"
2013 " } else {\n"
2014 " color = vec4(0,1,0,1);\n"
2015 " }\n"
2016 " gl_Position = vec4(pos,1);\n"
2017 "}\n";
2018
2019 const std::string fragmentShader =
2020 "precision mediump float;\n"
2021 "varying vec4 color;\n"
2022 "void main() {\n"
2023 " gl_FragColor = color;\n"
2024 "}\n";
2025
2026 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2027 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
2028 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
2029 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
2030 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
2031 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
2032}
2033
Jamie Madilla4595b82017-01-11 17:36:34 -05002034// Tests that a rendering feedback loop triggers a GL error under WebGL.
2035// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
2036TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
2037{
2038 const std::string vertexShader =
2039 "attribute vec4 a_position;\n"
2040 "varying vec2 v_texCoord;\n"
2041 "void main() {\n"
2042 " gl_Position = a_position;\n"
2043 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
2044 "}\n";
2045
2046 const std::string fragmentShader =
2047 "precision mediump float;\n"
2048 "varying vec2 v_texCoord;\n"
2049 "uniform sampler2D u_texture;\n"
2050 "void main() {\n"
2051 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
2052 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
2053 "}\n";
2054
2055 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05002056 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05002057
2058 ASSERT_GL_NO_ERROR();
2059
2060 GLFramebuffer framebuffer;
2061 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2062 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2063
2064 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2065
2066 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2067
2068 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
2069 ASSERT_NE(-1, uniformLoc);
2070
2071 glUseProgram(program.get());
2072 glUniform1i(uniformLoc, 0);
2073 glDisable(GL_BLEND);
2074 glDisable(GL_DEPTH_TEST);
2075 ASSERT_GL_NO_ERROR();
2076
2077 // Drawing with a texture that is also bound to the current framebuffer should fail
2078 glBindTexture(GL_TEXTURE_2D, texture.get());
2079 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2080 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2081
2082 // Ensure that the texture contents did not change after the previous render
2083 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2084 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2085 ASSERT_GL_NO_ERROR();
2086 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
2087
2088 // Drawing when texture is bound to an inactive uniform should succeed
2089 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05002090 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05002091
2092 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2093 glActiveTexture(GL_TEXTURE1);
2094 glBindTexture(GL_TEXTURE_2D, texture.get());
2095 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2096 ASSERT_GL_NO_ERROR();
2097 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2098}
2099
Bryan Bernhart58806562017-01-05 13:09:31 -08002100// Test for the max draw buffers and color attachments.
2101TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
2102{
2103 // This test only applies to ES2.
2104 if (getClientMajorVersion() != 2)
2105 {
2106 return;
2107 }
2108
2109 GLFramebuffer fbo[2];
2110 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
2111
2112 // Test that is valid when we bind with a single attachment point.
2113 GLTexture texture;
2114 glBindTexture(GL_TEXTURE_2D, texture.get());
2115 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2116 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2117 ASSERT_GL_NO_ERROR();
2118
2119 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
2120 // attachment point.
2121 if (extensionRequestable("GL_EXT_draw_buffers"))
2122 {
2123 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2124 EXPECT_GL_NO_ERROR();
2125 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
2126
2127 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
2128
2129 GLTexture texture2;
2130 glBindTexture(GL_TEXTURE_2D, texture2.get());
2131 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2132 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
2133 0);
2134 ASSERT_GL_NO_ERROR();
2135 }
2136}
2137
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002138// Test that the offset in the index buffer is forced to be a multiple of the element size
2139TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
2140{
2141 const std::string &vert =
2142 "attribute vec3 a_pos;\n"
2143 "void main()\n"
2144 "{\n"
2145 " gl_Position = vec4(a_pos, 1.0);\n"
2146 "}\n";
2147
Olli Etuaho5804dc82018-04-13 14:11:46 +03002148 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002149
2150 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
2151 ASSERT_NE(-1, posLocation);
2152 glUseProgram(program.get());
2153
2154 const auto &vertices = GetQuadVertices();
2155
2156 GLBuffer vertexBuffer;
2157 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
2158 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
2159 GL_STATIC_DRAW);
2160
2161 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
2162 glEnableVertexAttribArray(posLocation);
2163
2164 GLBuffer indexBuffer;
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002165 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002166 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
2167 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
2168
2169 ASSERT_GL_NO_ERROR();
2170
2171 const char *zeroIndices = nullptr;
2172
2173 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
2174 ASSERT_GL_NO_ERROR();
2175
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002176 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002177 ASSERT_GL_NO_ERROR();
2178
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002179 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices + 1);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002180 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2181}
2182
2183// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
2184// size
2185TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
2186{
2187 const char *zeroOffset = nullptr;
2188
2189 // Base case, vector of two floats
2190 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
2191 ASSERT_GL_NO_ERROR();
2192
2193 // Test setting a non-multiple offset
2194 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
2195 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2196 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
2197 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2198 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
2199 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2200
2201 // Test setting a non-multiple stride
2202 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
2203 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2204 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
2205 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2206 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
2207 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2208}
2209
Jamie Madillcad97ee2017-02-02 18:52:44 -05002210void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
2211 const std::array<GLenum, 2> &drawBuffers,
2212 GLenum expectedError)
2213{
2214 glDrawBuffersEXT(2, drawBuffers.data());
2215
2216 // Make sure framebuffer is complete before feedback loop detection
2217 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2218
2219 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
2220
2221 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
2222 // it should be NO_ERROR"
2223 EXPECT_GL_ERROR(expectedError);
2224}
2225
2226// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
2227// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
2228TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
2229{
2230 const std::string vertexShader =
2231 "attribute vec4 aPosition;\n"
2232 "varying vec2 texCoord;\n"
2233 "void main() {\n"
2234 " gl_Position = aPosition;\n"
2235 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2236 "}\n";
2237
2238 const std::string fragmentShader =
2239 "#extension GL_EXT_draw_buffers : require\n"
2240 "precision mediump float;\n"
2241 "uniform sampler2D tex;\n"
2242 "varying vec2 texCoord;\n"
2243 "void main() {\n"
2244 " gl_FragData[0] = texture2D(tex, texCoord);\n"
2245 " gl_FragData[1] = texture2D(tex, texCoord);\n"
2246 "}\n";
2247
2248 GLsizei width = 8;
2249 GLsizei height = 8;
2250
2251 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
2252 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
2253 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
2254 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
2255 {
2256 // No WEBGL_draw_buffers support -- this is legal.
2257 return;
2258 }
2259
2260 GLint maxDrawBuffers = 0;
2261 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2262
Yunchao He9550c602018-02-13 14:47:05 +08002263 // Test skipped because MAX_DRAW_BUFFERS is too small.
2264 ANGLE_SKIP_TEST_IF(maxDrawBuffers < 2);
Jamie Madillcad97ee2017-02-02 18:52:44 -05002265
2266 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2267 glUseProgram(program.get());
2268 glViewport(0, 0, width, height);
2269
2270 GLTexture tex0;
2271 GLTexture tex1;
2272 GLFramebuffer fbo;
2273 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2274 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2275 ASSERT_GL_NO_ERROR();
2276
2277 glBindTexture(GL_TEXTURE_2D, tex1.get());
2278 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2279 ASSERT_NE(-1, texLoc);
2280 glUniform1i(texLoc, 0);
2281 ASSERT_GL_NO_ERROR();
2282
2283 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2284 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2285 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2286 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2287
2288 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
2289 GL_INVALID_OPERATION);
2290 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2291 GL_INVALID_OPERATION);
2292 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2293}
2294
Jamie Madill07be8bf2017-02-02 19:59:57 -05002295// Test tests that texture copying feedback loops are properly rejected in WebGL.
2296// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
2297TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
2298{
2299 GLTexture texture;
2300 glBindTexture(GL_TEXTURE_2D, texture.get());
2301 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2302 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2305 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2306
2307 GLTexture texture2;
2308 glBindTexture(GL_TEXTURE_2D, texture2.get());
2309 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2310 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2311 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2314
2315 GLFramebuffer framebuffer;
2316 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2317 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2318
2319 // framebuffer should be FRAMEBUFFER_COMPLETE.
2320 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2321 ASSERT_GL_NO_ERROR();
2322
2323 // testing copyTexImage2D
2324
2325 // copyTexImage2D to same texture but different level
2326 glBindTexture(GL_TEXTURE_2D, texture.get());
2327 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
2328 EXPECT_GL_NO_ERROR();
2329
2330 // copyTexImage2D to same texture same level, invalid feedback loop
2331 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2332 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2333
2334 // copyTexImage2D to different texture
2335 glBindTexture(GL_TEXTURE_2D, texture2.get());
2336 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2337 EXPECT_GL_NO_ERROR();
2338
2339 // testing copyTexSubImage2D
2340
2341 // copyTexSubImage2D to same texture but different level
2342 glBindTexture(GL_TEXTURE_2D, texture.get());
2343 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
2344 EXPECT_GL_NO_ERROR();
2345
2346 // copyTexSubImage2D to same texture same level, invalid feedback loop
2347 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2348 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2349
2350 // copyTexSubImage2D to different texture
2351 glBindTexture(GL_TEXTURE_2D, texture2.get());
2352 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2353 EXPECT_GL_NO_ERROR();
2354}
2355
2356void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
2357 const std::array<GLenum, 2> &drawBuffers,
2358 GLenum expectedError)
2359{
2360 glDrawBuffers(2, drawBuffers.data());
2361
2362 // Make sure framebuffer is complete before feedback loop detection
2363 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2364
2365 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
2366
2367 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
2368 // it should be NO_ERROR"
2369 EXPECT_GL_ERROR(expectedError);
2370}
2371
Yuly Novikov817232e2017-02-22 18:36:10 -05002372// Tests invariance matching rules between built in varyings.
2373// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
2374TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
2375{
2376 const std::string vertexShaderVariant =
2377 "varying vec4 v_varying;\n"
2378 "void main()\n"
2379 "{\n"
2380 " gl_PointSize = 1.0;\n"
2381 " gl_Position = v_varying;\n"
2382 "}";
2383 const std::string fragmentShaderInvariantGlFragCoord =
2384 "invariant gl_FragCoord;\n"
2385 "void main()\n"
2386 "{\n"
2387 " gl_FragColor = gl_FragCoord;\n"
2388 "}";
2389 const std::string fragmentShaderInvariantGlPointCoord =
2390 "invariant gl_PointCoord;\n"
2391 "void main()\n"
2392 "{\n"
2393 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
2394 "}";
2395
2396 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
2397 EXPECT_EQ(0u, program);
2398
2399 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
2400 EXPECT_EQ(0u, program);
2401}
2402
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04002403// Tests global namespace conflicts between uniforms and attributes.
2404// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
2405TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
2406{
2407 const std::string vertexShader =
2408 "attribute vec4 foo;\n"
2409 "void main()\n"
2410 "{\n"
2411 " gl_Position = foo;\n"
2412 "}";
2413 const std::string fragmentShader =
2414 "precision mediump float;\n"
2415 "uniform vec4 foo;\n"
2416 "void main()\n"
2417 "{\n"
2418 " gl_FragColor = foo;\n"
2419 "}";
2420
2421 GLuint program = CompileProgram(vertexShader, fragmentShader);
2422 EXPECT_EQ(0u, program);
2423}
2424
Geoff Lang966c9402017-04-18 12:38:27 -04002425// Test dimension and image size validation of compressed textures
2426TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
2427{
2428 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
2429 {
2430 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
2431 }
2432
Yunchao He9550c602018-02-13 14:47:05 +08002433 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_compression_dxt1"));
Geoff Lang966c9402017-04-18 12:38:27 -04002434
2435 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
2436
2437 GLTexture texture;
2438 glBindTexture(GL_TEXTURE_2D, texture);
2439
2440 // Regular case, verify that it works
2441 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2442 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2443 ASSERT_GL_NO_ERROR();
2444
2445 // Test various dimensions that are not valid
2446 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
2447 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2448 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2449
2450 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
2451 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2452 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2453
2454 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2455 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2456 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2457
2458 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2459 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2460 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2461
2462 // Test various image sizes that are not valid
2463 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2464 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
2465 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2466
2467 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2468 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
2469 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2470
2471 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
2472 CompressedImageDXT1);
2473 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2474
2475 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
2476 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2477 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2478
2479 // Fill a full mip chain and verify that it works
2480 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2481 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2482 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2483 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2484 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2485 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2486 ASSERT_GL_NO_ERROR();
2487
2488 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2489 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2490 ASSERT_GL_NO_ERROR();
2491
2492 // Test that non-block size sub-uploads are not valid for the 0 mip
2493 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2494 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2495 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2496
2497 // Test that non-block size sub-uploads are valid for if they fill the whole mip
2498 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2499 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2500 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2501 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2502 ASSERT_GL_NO_ERROR();
2503
2504 // Test that if the format miss-matches the texture, an error is generated
2505 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2506 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2507 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2508}
2509
Geoff Lang677bb6f2017-04-05 12:40:40 -04002510TEST_P(WebGLCompatibilityTest, L32FTextures)
2511{
2512 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
2513 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
2514
2515 for (auto extension : FloatingPointTextureExtensions)
2516 {
2517 if (strlen(extension) > 0 && extensionRequestable(extension))
2518 {
2519 glRequestExtensionANGLE(extension);
2520 ASSERT_GL_NO_ERROR();
2521 }
2522
2523 // Unsized L 32F
2524 {
2525 bool texture = extensionEnabled("GL_OES_texture_float");
2526 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2527 bool render = false;
2528 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
2529 textureData, readPixelData);
2530 }
2531
2532 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2533 {
2534 // Sized L 32F
2535 bool texture = extensionEnabled("GL_OES_texture_float") &&
2536 extensionEnabled("GL_EXT_texture_storage");
2537 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2538 bool render = false;
2539 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
2540 render, textureData, readPixelData);
2541 }
2542 }
2543}
2544
2545TEST_P(WebGLCompatibilityTest, A32FTextures)
2546{
2547 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
2548 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
2549
2550 for (auto extension : FloatingPointTextureExtensions)
2551 {
2552 if (strlen(extension) > 0 && extensionRequestable(extension))
2553 {
2554 glRequestExtensionANGLE(extension);
2555 ASSERT_GL_NO_ERROR();
2556 }
2557
2558 // Unsized A 32F
2559 {
2560 bool texture = extensionEnabled("GL_OES_texture_float");
2561 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2562 bool render = false;
2563 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
2564 textureData, readPixelData);
2565 }
2566
2567 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2568 {
2569 // Sized A 32F
2570 bool texture = extensionEnabled("GL_OES_texture_float") &&
2571 extensionEnabled("GL_EXT_texture_storage");
2572 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2573 bool render = false;
2574 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
2575 textureData, readPixelData);
2576 }
2577 }
2578}
2579
2580TEST_P(WebGLCompatibilityTest, LA32FTextures)
2581{
2582 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
2583 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
2584 textureData[1]};
2585
2586 for (auto extension : FloatingPointTextureExtensions)
2587 {
2588 if (strlen(extension) > 0 && extensionRequestable(extension))
2589 {
2590 glRequestExtensionANGLE(extension);
2591 ASSERT_GL_NO_ERROR();
2592 }
2593
2594 // Unsized LA 32F
2595 {
2596 bool texture = extensionEnabled("GL_OES_texture_float");
2597 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2598 bool render = false;
2599 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2600 filter, render, textureData, readPixelData);
2601 }
2602
2603 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2604 {
2605 // Sized LA 32F
2606 bool texture = extensionEnabled("GL_OES_texture_float") &&
2607 extensionEnabled("GL_EXT_texture_storage");
2608 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2609 bool render = false;
2610 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2611 filter, render, textureData, readPixelData);
2612 }
2613 }
2614}
2615
2616TEST_P(WebGLCompatibilityTest, R32FTextures)
2617{
2618 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
2619
2620 for (auto extension : FloatingPointTextureExtensions)
2621 {
2622 if (strlen(extension) > 0 && extensionRequestable(extension))
2623 {
2624 glRequestExtensionANGLE(extension);
2625 ASSERT_GL_NO_ERROR();
2626 }
2627
2628 // Unsized R 32F
2629 {
2630 bool texture =
2631 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
2632 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2633 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2634 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2635 }
2636
2637 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2638 {
2639 // Sized R 32F
2640 bool texture =
2641 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2642 extensionEnabled("GL_EXT_texture_rg") &&
2643 extensionEnabled("GL_EXT_texture_storage"));
2644 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2645 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2646 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2647 }
2648 }
2649}
2650
2651TEST_P(WebGLCompatibilityTest, RG32FTextures)
2652{
2653 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
2654
2655 for (auto extension : FloatingPointTextureExtensions)
2656 {
2657 if (strlen(extension) > 0 && extensionRequestable(extension))
2658 {
2659 glRequestExtensionANGLE(extension);
2660 ASSERT_GL_NO_ERROR();
2661 }
2662
2663 // Unsized RG 32F
2664 {
2665 bool texture =
2666 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
2667 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2668 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2669 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2670 }
2671
2672 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2673 {
2674 // Sized RG 32F
2675 bool texture =
2676 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2677 extensionEnabled("GL_EXT_texture_rg") &&
2678 extensionEnabled("GL_EXT_texture_storage"));
2679 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2680 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2681 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2682 }
2683 }
2684}
2685
2686TEST_P(WebGLCompatibilityTest, RGB32FTextures)
2687{
Yunchao He9550c602018-02-13 14:47:05 +08002688 ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002689
Geoff Lang677bb6f2017-04-05 12:40:40 -04002690 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
2691
2692 for (auto extension : FloatingPointTextureExtensions)
2693 {
2694 if (strlen(extension) > 0 && extensionRequestable(extension))
2695 {
2696 glRequestExtensionANGLE(extension);
2697 ASSERT_GL_NO_ERROR();
2698 }
2699
2700 // Unsized RGB 32F
2701 {
2702 bool texture = extensionEnabled("GL_OES_texture_float");
2703 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2704 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2705 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
2706 }
2707
2708 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2709 {
2710 // Sized RGBA 32F
2711 bool texture =
2712 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2713 extensionEnabled("GL_EXT_texture_storage"));
2714 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2715 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2716 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
2717 data);
2718 }
2719 }
2720}
2721
2722TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
2723{
2724 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2725
2726 for (auto extension : FloatingPointTextureExtensions)
2727 {
2728 if (strlen(extension) > 0 && extensionRequestable(extension))
2729 {
2730 glRequestExtensionANGLE(extension);
2731 ASSERT_GL_NO_ERROR();
2732 }
2733
2734 // Unsized RGBA 32F
2735 {
2736 bool texture = extensionEnabled("GL_OES_texture_float");
2737 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2738 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2739 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2740 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
2741 }
2742
2743 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2744 {
2745 // Sized RGBA 32F
2746 bool texture =
2747 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2748 extensionEnabled("GL_EXT_texture_storage"));
2749 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2750 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2751 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2752 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
2753 data);
2754 }
2755 }
2756}
2757
2758TEST_P(WebGLCompatibilityTest, R16FTextures)
2759{
2760 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
2761 const GLushort textureData[] = {
2762 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2763 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2764
2765 for (auto extension : FloatingPointTextureExtensions)
2766 {
2767 if (strlen(extension) > 0 && extensionRequestable(extension))
2768 {
2769 glRequestExtensionANGLE(extension);
2770 ASSERT_GL_NO_ERROR();
2771 }
2772
2773 // Unsized R 16F (OES)
2774 {
2775 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2776 extensionEnabled("GL_EXT_texture_rg");
2777 bool filter = getClientMajorVersion() >= 3 ||
2778 extensionEnabled("GL_OES_texture_half_float_linear");
2779 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2780 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2781 textureData, readPixelsData);
2782 }
2783
2784 // Unsized R 16F
2785 {
2786 bool texture = false;
2787 bool filter = false;
2788 bool render = false;
2789 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2790 textureData, readPixelsData);
2791 }
2792
2793 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2794 {
2795 // Sized R 16F
2796 bool texture = getClientMajorVersion() >= 3;
2797 bool filter = getClientMajorVersion() >= 3 ||
2798 extensionEnabled("GL_OES_texture_half_float_linear");
2799 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2800 extensionEnabled("GL_EXT_color_buffer_float");
2801 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2802 textureData, readPixelsData);
2803 }
2804 }
2805}
2806
2807TEST_P(WebGLCompatibilityTest, RG16FTextures)
2808{
2809 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
2810 const GLushort textureData[] = {
2811 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2812 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2813
2814 for (auto extension : FloatingPointTextureExtensions)
2815 {
2816 if (strlen(extension) > 0 && extensionRequestable(extension))
2817 {
2818 glRequestExtensionANGLE(extension);
2819 ASSERT_GL_NO_ERROR();
2820 }
2821
2822 // Unsized RG 16F (OES)
2823 {
2824 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2825 extensionEnabled("GL_EXT_texture_rg");
2826 bool filter = getClientMajorVersion() >= 3 ||
2827 extensionEnabled("GL_OES_texture_half_float_linear");
2828 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
2829 extensionEnabled("GL_EXT_texture_rg");
2830 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2831 textureData, readPixelsData);
2832 }
2833
2834 // Unsized RG 16F
2835 {
2836 bool texture = false;
2837 bool filter = false;
2838 bool render = false;
2839 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2840 textureData, readPixelsData);
2841 }
2842
2843 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2844 {
2845 // Sized RG 16F
2846 bool texture = getClientMajorVersion() >= 3;
2847 bool filter = getClientMajorVersion() >= 3 ||
2848 extensionEnabled("GL_OES_texture_half_float_linear");
2849 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2850 extensionEnabled("GL_EXT_color_buffer_float");
2851 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2852 textureData, readPixelsData);
2853 }
2854 }
2855}
2856
2857TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2858{
Yunchao He9550c602018-02-13 14:47:05 +08002859 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002860
Geoff Lang677bb6f2017-04-05 12:40:40 -04002861 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2862 const GLushort textureData[] = {
2863 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2864 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2865
2866 for (auto extension : FloatingPointTextureExtensions)
2867 {
2868 if (strlen(extension) > 0 && extensionRequestable(extension))
2869 {
2870 glRequestExtensionANGLE(extension);
2871 ASSERT_GL_NO_ERROR();
2872 }
2873
2874 // Unsized RGB 16F (OES)
2875 {
2876 bool texture = extensionEnabled("GL_OES_texture_half_float");
2877 bool filter = getClientMajorVersion() >= 3 ||
2878 extensionEnabled("GL_OES_texture_half_float_linear");
2879 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2880 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2881 textureData, readPixelsData);
2882 }
2883
2884 // Unsized RGB 16F
2885 {
2886 bool texture = false;
2887 bool filter = false;
2888 bool render = false;
2889 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2890 textureData, readPixelsData);
2891 }
2892
2893 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2894 {
2895 // Sized RGB 16F
2896 bool texture = getClientMajorVersion() >= 3;
2897 bool filter = getClientMajorVersion() >= 3 ||
2898 extensionEnabled("GL_OES_texture_half_float_linear");
2899 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2900 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2901 textureData, readPixelsData);
2902 }
2903 }
2904}
2905
2906TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2907{
Yunchao He9550c602018-02-13 14:47:05 +08002908 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002909
Geoff Lang677bb6f2017-04-05 12:40:40 -04002910 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2911 const GLushort textureData[] = {
2912 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2913 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2914
2915 for (auto extension : FloatingPointTextureExtensions)
2916 {
2917 if (strlen(extension) > 0 && extensionRequestable(extension))
2918 {
2919 glRequestExtensionANGLE(extension);
2920 ASSERT_GL_NO_ERROR();
2921 }
2922
2923 // Unsized RGBA 16F (OES)
2924 {
2925 bool texture = extensionEnabled("GL_OES_texture_half_float");
2926 bool filter = getClientMajorVersion() >= 3 ||
2927 extensionEnabled("GL_OES_texture_half_float_linear");
2928 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2929 extensionEnabled("GL_EXT_color_buffer_float");
2930 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2931 textureData, readPixelsData);
2932 }
2933
2934 // Unsized RGBA 16F
2935 {
2936 bool texture = false;
2937 bool filter = false;
2938 bool render = false;
2939 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2940 textureData, readPixelsData);
2941 }
2942
2943 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2944 {
2945 // Sized RGBA 16F
2946 bool texture = getClientMajorVersion() >= 3;
2947 bool filter = getClientMajorVersion() >= 3 ||
2948 extensionEnabled("GL_OES_texture_half_float_linear");
2949 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2950 extensionEnabled("GL_EXT_color_buffer_float");
2951 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2952 textureData, readPixelsData);
2953 }
2954 }
2955}
2956
Geoff Lang6e898aa2017-06-02 11:17:26 -04002957// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2958// accepted by glTexImage2D
2959TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2960{
Yunchao He9550c602018-02-13 14:47:05 +08002961 // Test skipped because it is only valid for WebGL1 contexts.
2962 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
Geoff Lang6e898aa2017-06-02 11:17:26 -04002963
Yunchao He9550c602018-02-13 14:47:05 +08002964 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_OES_texture_float"));
2965
Geoff Lang6e898aa2017-06-02 11:17:26 -04002966 glRequestExtensionANGLE("GL_OES_texture_float");
2967 ASSERT_GL_NO_ERROR();
2968
2969 GLTexture texture;
2970 glBindTexture(GL_TEXTURE_2D, texture);
2971
2972 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2973 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2974
2975 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2976 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2977
2978 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2979 {
2980 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2981 ASSERT_GL_NO_ERROR();
2982
2983 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2984 EXPECT_GL_NO_ERROR();
2985 }
2986
2987 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2988 {
2989 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2990 ASSERT_GL_NO_ERROR();
2991
2992 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2993 EXPECT_GL_NO_ERROR();
2994 }
2995}
2996
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08002997// Verify GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point.
2998TEST_P(WebGLCompatibilityTest, DepthStencilAttachment)
2999{
3000 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3001
3002 // Test that attaching a bound texture succeeds.
3003 GLTexture texture;
3004 glBindTexture(GL_TEXTURE_2D, texture);
3005
3006 GLFramebuffer fbo;
3007 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3008
3009 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture, 0);
3010
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003011 GLint attachmentType = 0;
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003012 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003013 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003014 EXPECT_GL_NO_ERROR();
3015 EXPECT_GLENUM_EQ(GL_TEXTURE, attachmentType);
3016
3017 // Test when if no attach object at the named attachment point and pname is not OBJECT_TYPE.
3018 GLFramebuffer fbo2;
3019 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
3020
3021 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003022 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003023 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3024}
3025
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003026// Verify framebuffer attachments return expected types when in an inconsistant state.
3027TEST_P(WebGLCompatibilityTest, FramebufferAttachmentConsistancy)
3028{
3029 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3030
3031 GLFramebuffer fbo;
3032 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3033
3034 GLRenderbuffer rb1;
3035 glBindRenderbuffer(GL_RENDERBUFFER, rb1);
3036
3037 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb1);
3038
3039 GLint attachmentType = 0;
3040 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3041 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3042
3043 EXPECT_GL_NO_ERROR();
3044 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3045
3046 GLRenderbuffer rb2;
3047 glBindRenderbuffer(GL_RENDERBUFFER, rb2);
3048
3049 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3050
3051 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
3052 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3053
3054 EXPECT_GL_NO_ERROR();
3055 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)5f198102017-12-12 14:21:39 -08003056
3057 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb2);
3058
3059 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3060 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3061
3062 EXPECT_GL_NO_ERROR();
3063 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3064
3065 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3066
3067 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3068 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3069
3070 EXPECT_GL_NO_ERROR();
3071 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003072}
3073
Jamie Madill07be8bf2017-02-02 19:59:57 -05003074// This tests that rendering feedback loops works as expected with WebGL 2.
3075// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
3076TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
3077{
3078 const std::string vertexShader =
3079 "#version 300 es\n"
3080 "in vec4 aPosition;\n"
3081 "out vec2 texCoord;\n"
3082 "void main() {\n"
3083 " gl_Position = aPosition;\n"
3084 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3085 "}\n";
3086
3087 const std::string fragmentShader =
3088 "#version 300 es\n"
3089 "precision mediump float;\n"
3090 "uniform sampler2D tex;\n"
3091 "in vec2 texCoord;\n"
3092 "out vec4 oColor;\n"
3093 "void main() {\n"
3094 " oColor = texture(tex, texCoord);\n"
3095 "}\n";
3096
3097 GLsizei width = 8;
3098 GLsizei height = 8;
3099
3100 GLint maxDrawBuffers = 0;
3101 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3102 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
3103 ASSERT_GE(maxDrawBuffers, 2);
3104
3105 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3106 glUseProgram(program.get());
3107 glViewport(0, 0, width, height);
3108
3109 GLTexture tex0;
3110 GLTexture tex1;
3111 GLFramebuffer fbo;
3112 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3113 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3114 ASSERT_GL_NO_ERROR();
3115
3116 glBindTexture(GL_TEXTURE_2D, tex1.get());
3117 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3118 ASSERT_NE(-1, texLoc);
3119 glUniform1i(texLoc, 0);
3120
3121 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
3122 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3123 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3124 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
3125 ASSERT_GL_NO_ERROR();
3126
3127 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
3128 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
3129 GL_INVALID_OPERATION);
3130 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
3131}
3132
Jamie Madill1d37bc52017-02-02 19:59:58 -05003133// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
3134// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
3135TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
3136{
3137 const std::string vertexShader =
3138 "#version 300 es\n"
3139 "in vec4 aPosition;\n"
3140 "out vec2 texCoord;\n"
3141 "void main() {\n"
3142 " gl_Position = aPosition;\n"
3143 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3144 "}\n";
3145
3146 const std::string fragmentShader =
3147 "#version 300 es\n"
3148 "precision mediump float;\n"
3149 "uniform sampler2D tex;\n"
3150 "in vec2 texCoord;\n"
3151 "out vec4 oColor;\n"
3152 "void main() {\n"
3153 " oColor = texture(tex, texCoord);\n"
3154 "}\n";
3155
3156 GLsizei width = 8;
3157 GLsizei height = 8;
3158
3159 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3160 glUseProgram(program.get());
3161
3162 glViewport(0, 0, width, height);
3163
3164 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3165 glUniform1i(texLoc, 0);
3166
3167 // Create textures and allocate storage
3168 GLTexture tex0;
3169 GLTexture tex1;
3170 GLRenderbuffer rb;
3171 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3172 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
3173 GL_UNSIGNED_INT);
3174 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
3175 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
3176 ASSERT_GL_NO_ERROR();
3177
3178 GLFramebuffer fbo;
3179 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3180 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3181
3182 // Test rendering and sampling feedback loop for depth buffer
3183 glBindTexture(GL_TEXTURE_2D, tex1.get());
3184 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
3185 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3186
3187 // The same image is used as depth buffer during rendering.
3188 glEnable(GL_DEPTH_TEST);
3189 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3190 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3191
3192 // The same image is used as depth buffer. But depth mask is false.
3193 glDepthMask(GL_FALSE);
3194 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3195 EXPECT_GL_NO_ERROR();
3196
3197 // The same image is used as depth buffer. But depth test is not enabled during rendering.
3198 glDepthMask(GL_TRUE);
3199 glDisable(GL_DEPTH_TEST);
3200 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3201 EXPECT_GL_NO_ERROR();
3202
3203 // Test rendering and sampling feedback loop for stencil buffer
3204 glBindTexture(GL_RENDERBUFFER, rb.get());
3205 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
3206 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
3207 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3208 constexpr GLint stencilClearValue = 0x40;
3209 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
3210
3211 // The same image is used as stencil buffer during rendering.
3212 glEnable(GL_STENCIL_TEST);
3213 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3214 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3215
3216 // The same image is used as stencil buffer. But stencil mask is zero.
3217 glStencilMask(0x0);
3218 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3219 EXPECT_GL_NO_ERROR();
3220
3221 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
3222 glStencilMask(0xffff);
3223 glDisable(GL_STENCIL_TEST);
3224 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3225 EXPECT_GL_NO_ERROR();
3226}
3227
Jamie Madillfd3dd432017-02-02 19:59:59 -05003228// The source and the target for CopyTexSubImage3D are the same 3D texture.
3229// But the level of the 3D texture != the level of the read attachment.
3230TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
3231{
3232 GLTexture texture;
3233 GLFramebuffer framebuffer;
3234
3235 glBindTexture(GL_TEXTURE_3D, texture.get());
3236 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3237
3238 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3239 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3240 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
3241 ASSERT_GL_NO_ERROR();
3242
3243 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3244 EXPECT_GL_NO_ERROR();
3245}
3246
3247// The source and the target for CopyTexSubImage3D are the same 3D texture.
3248// But the zoffset of the 3D texture != the layer of the read attachment.
3249TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
3250{
3251 GLTexture texture;
3252 GLFramebuffer framebuffer;
3253
3254 glBindTexture(GL_TEXTURE_3D, texture.get());
3255 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3256
3257 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3258 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
3259 ASSERT_GL_NO_ERROR();
3260
3261 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
3262 EXPECT_GL_NO_ERROR();
3263}
3264
3265// The source and the target for CopyTexSubImage3D are the same 3D texture.
3266// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
3267TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
3268{
3269 GLTexture texture;
3270 GLFramebuffer framebuffer;
3271
3272 glBindTexture(GL_TEXTURE_3D, texture.get());
3273 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3274
3275 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3276 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3277 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3278 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
3279 ASSERT_GL_NO_ERROR();
3280
3281 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3282 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3283}
3284
Corentin Wallez59c41592017-07-11 13:19:54 -04003285// Verify that errors are generated when there isn't a defined conversion between the clear type and
3286// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04003287TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
3288{
Yunchao He9550c602018-02-13 14:47:05 +08003289 // Test skipped for D3D11 because it generates D3D11 runtime warnings.
3290 ANGLE_SKIP_TEST_IF(IsD3D11());
Geoff Lang76e65652017-03-27 14:58:02 -04003291
3292 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3293 constexpr int clearInt[] = {0, 0, 0, 0};
3294 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3295
3296 GLTexture texture;
3297 GLFramebuffer framebuffer;
3298
3299 glBindTexture(GL_TEXTURE_2D, texture.get());
3300 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3301
3302 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
3303 ASSERT_GL_NO_ERROR();
3304
3305 // Unsigned integer buffer
3306 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
3307 ASSERT_GL_NO_ERROR();
3308
3309 glClearBufferfv(GL_COLOR, 0, clearFloat);
3310 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3311
3312 glClearBufferiv(GL_COLOR, 0, clearInt);
3313 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3314
3315 glClearBufferuiv(GL_COLOR, 0, clearUint);
3316 EXPECT_GL_NO_ERROR();
3317
3318 glClear(GL_COLOR_BUFFER_BIT);
3319 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3320
3321 // Integer buffer
3322 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
3323 ASSERT_GL_NO_ERROR();
3324
3325 glClearBufferfv(GL_COLOR, 0, clearFloat);
3326 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3327
3328 glClearBufferiv(GL_COLOR, 0, clearInt);
3329 EXPECT_GL_NO_ERROR();
3330
3331 glClearBufferuiv(GL_COLOR, 0, clearUint);
3332 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3333
3334 glClear(GL_COLOR_BUFFER_BIT);
3335 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3336
3337 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04003338 if (extensionRequestable("GL_EXT_color_buffer_float"))
3339 {
3340 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3341 }
Geoff Lang76e65652017-03-27 14:58:02 -04003342
Geoff Lang677bb6f2017-04-05 12:40:40 -04003343 if (extensionEnabled("GL_EXT_color_buffer_float"))
3344 {
3345 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3346 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003347
Geoff Lang677bb6f2017-04-05 12:40:40 -04003348 glClearBufferfv(GL_COLOR, 0, clearFloat);
3349 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003350
Geoff Lang677bb6f2017-04-05 12:40:40 -04003351 glClearBufferiv(GL_COLOR, 0, clearInt);
3352 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04003353
Geoff Lang677bb6f2017-04-05 12:40:40 -04003354 glClearBufferuiv(GL_COLOR, 0, clearUint);
3355 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3356
3357 glClear(GL_COLOR_BUFFER_BIT);
3358 EXPECT_GL_NO_ERROR();
3359 }
Geoff Lang76e65652017-03-27 14:58:02 -04003360
3361 // Normalized uint buffer
3362 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3363 ASSERT_GL_NO_ERROR();
3364
3365 glClearBufferfv(GL_COLOR, 0, clearFloat);
3366 EXPECT_GL_NO_ERROR();
3367
3368 glClearBufferiv(GL_COLOR, 0, clearInt);
3369 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3370
3371 glClearBufferuiv(GL_COLOR, 0, clearUint);
3372 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3373
3374 glClear(GL_COLOR_BUFFER_BIT);
3375 EXPECT_GL_NO_ERROR();
3376}
3377
Corentin Wallez59c41592017-07-11 13:19:54 -04003378// Test the interaction of WebGL compatibility clears with default framebuffers
3379TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
3380{
3381 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3382 constexpr int clearInt[] = {0, 0, 0, 0};
3383 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3384
3385 // glClear works as usual, this is also a regression test for a bug where we
3386 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
3387 glClear(GL_COLOR_BUFFER_BIT);
3388 EXPECT_GL_NO_ERROR();
3389
3390 // Default framebuffers are normalized uints, so only glClearBufferfv works.
3391 glClearBufferfv(GL_COLOR, 0, clearFloat);
3392 EXPECT_GL_NO_ERROR();
3393
3394 glClearBufferiv(GL_COLOR, 0, clearInt);
3395 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3396
3397 glClearBufferuiv(GL_COLOR, 0, clearUint);
3398 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3399}
3400
Geoff Lange4915782017-04-12 15:19:07 -04003401// Verify that errors are generate when trying to blit from an image to itself
3402TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
3403{
3404 GLTexture textures[2];
3405 glBindTexture(GL_TEXTURE_2D, textures[0]);
3406 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3407 glBindTexture(GL_TEXTURE_2D, textures[1]);
3408 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3409
3410 GLRenderbuffer renderbuffers[2];
3411 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
3412 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3413 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
3414 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3415
3416 GLFramebuffer framebuffers[2];
3417 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
3418 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
3419
3420 ASSERT_GL_NO_ERROR();
3421
3422 // Same texture
3423 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3424 0);
3425 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3426 0);
3427 ASSERT_GL_NO_ERROR();
3428 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3429 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3430
3431 // Same textures but different renderbuffers
3432 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3433 renderbuffers[0]);
3434 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3435 renderbuffers[1]);
3436 ASSERT_GL_NO_ERROR();
3437 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3438 ASSERT_GL_NO_ERROR();
3439 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3440 GL_NEAREST);
3441 ASSERT_GL_NO_ERROR();
3442 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3443 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3444 GL_NEAREST);
3445 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3446
3447 // Same renderbuffers but different textures
3448 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3449 0);
3450 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
3451 0);
3452 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3453 renderbuffers[0]);
3454 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3455 renderbuffers[0]);
3456 ASSERT_GL_NO_ERROR();
3457 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3458 ASSERT_GL_NO_ERROR();
3459 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3460 GL_NEAREST);
3461 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3462 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3463 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3464 GL_NEAREST);
3465 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3466}
3467
Geoff Lange0cff192017-05-30 13:04:56 -04003468// Verify that errors are generated when the fragment shader output doesn't match the bound color
3469// buffer types
3470TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
3471{
3472 const std::string vertexShader =
3473 "#version 300 es\n"
3474 "void main() {\n"
3475 " gl_Position = vec4(0, 0, 0, 1);\n"
3476 "}\n";
3477
3478 const std::string fragmentShader =
3479 "#version 300 es\n"
3480 "precision mediump float;\n"
3481 "layout(location = 0) out vec4 floatOutput;\n"
3482 "layout(location = 1) out uvec4 uintOutput;\n"
3483 "layout(location = 2) out ivec4 intOutput;\n"
3484 "void main() {\n"
3485 " floatOutput = vec4(0, 0, 0, 1);\n"
3486 " uintOutput = uvec4(0, 0, 0, 1);\n"
3487 " intOutput = ivec4(0, 0, 0, 1);\n"
3488 "}\n";
3489
3490 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3491 glUseProgram(program.get());
3492
3493 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
3494 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
3495 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
3496
3497 GLFramebuffer fbo;
3498 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3499
3500 GLRenderbuffer floatRenderbuffer;
3501 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
3502 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
3503 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3504 floatRenderbuffer);
3505
3506 GLRenderbuffer uintRenderbuffer;
3507 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
3508 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
3509 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3510 uintRenderbuffer);
3511
3512 GLRenderbuffer intRenderbuffer;
3513 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
3514 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
3515 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3516 intRenderbuffer);
3517
3518 ASSERT_GL_NO_ERROR();
3519
3520 GLint maxDrawBuffers = 0;
3521 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3522 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
3523 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
3524 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
3525 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
3526
3527 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
3528
3529 // Check that the correct case generates no errors
3530 glDrawArrays(GL_TRIANGLES, 0, 6);
3531 EXPECT_GL_NO_ERROR();
3532
3533 // Unbind some buffers and verify that there are still no errors
3534 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3535 0);
3536 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3537 0);
3538 glDrawArrays(GL_TRIANGLES, 0, 6);
3539 EXPECT_GL_NO_ERROR();
3540
3541 // Swap the int and uint buffers to and verify that an error is generated
3542 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3543 intRenderbuffer);
3544 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3545 uintRenderbuffer);
3546 glDrawArrays(GL_TRIANGLES, 0, 6);
3547 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3548
3549 // Swap the float and uint buffers to and verify that an error is generated
3550 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3551 floatRenderbuffer);
3552 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3553 uintRenderbuffer);
3554 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3555 intRenderbuffer);
3556 glDrawArrays(GL_TRIANGLES, 0, 6);
3557 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3558}
3559
Geoff Lang9ab5b822017-05-30 16:19:23 -04003560// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
3561// types
Corentin Wallezc3bc9842017-10-11 15:15:59 -04003562TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch)
Geoff Lang9ab5b822017-05-30 16:19:23 -04003563{
3564 const std::string vertexShader =
3565 "#version 300 es\n"
3566 "in vec4 floatInput;\n"
3567 "in uvec4 uintInput;\n"
3568 "in ivec4 intInput;\n"
3569 "void main() {\n"
3570 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
3571 "}\n";
3572
3573 const std::string fragmentShader =
3574 "#version 300 es\n"
3575 "precision mediump float;\n"
3576 "out vec4 outputColor;\n"
3577 "void main() {\n"
3578 " outputColor = vec4(0, 0, 0, 1);"
3579 "}\n";
3580
3581 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3582 glUseProgram(program.get());
3583
3584 GLint floatLocation = glGetAttribLocation(program, "floatInput");
3585 GLint uintLocation = glGetAttribLocation(program, "uintInput");
3586 GLint intLocation = glGetAttribLocation(program, "intInput");
3587
3588 // Default attributes are of float types
3589 glDrawArrays(GL_TRIANGLES, 0, 6);
3590 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3591
3592 // Set the default attributes to the correct types, should succeed
3593 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
3594 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
3595 glDrawArrays(GL_TRIANGLES, 0, 6);
3596 EXPECT_GL_NO_ERROR();
3597
3598 // Change the default float attribute to an integer, should fail
3599 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
3600 glDrawArrays(GL_TRIANGLES, 0, 6);
3601 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3602
3603 // Use a buffer for some attributes
3604 GLBuffer buffer;
3605 glBindBuffer(GL_ARRAY_BUFFER, buffer);
3606 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
3607 glEnableVertexAttribArray(floatLocation);
3608 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3609 glDrawArrays(GL_TRIANGLES, 0, 6);
3610 EXPECT_GL_NO_ERROR();
3611
3612 // Use a float pointer attrib for a uint input
3613 glEnableVertexAttribArray(uintLocation);
3614 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3615 glDrawArrays(GL_TRIANGLES, 0, 6);
3616 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3617
3618 // Use a uint pointer for the uint input
3619 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
3620 glDrawArrays(GL_TRIANGLES, 0, 6);
3621 EXPECT_GL_NO_ERROR();
3622}
3623
Geoff Langfa125c92017-10-24 13:01:46 -04003624// Test that it's not possible to query the non-zero color attachments without the drawbuffers
3625// extension in WebGL1
3626TEST_P(WebGLCompatibilityTest, FramebufferAttachmentQuery)
3627{
3628 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3629 ANGLE_SKIP_TEST_IF(extensionEnabled("GL_EXT_draw_buffers"));
3630
3631 GLFramebuffer fbo;
3632 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3633 EXPECT_GL_NO_ERROR();
3634
3635 GLint result;
3636 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
3637 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &result);
3638 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3639
3640 GLRenderbuffer renderbuffer;
3641 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
3642 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
3643 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderbuffer);
3644 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3645}
3646
Corentin Walleze7557742017-06-01 13:09:57 -04003647// Tests the WebGL removal of undefined behavior when attachments aren't written to.
3648TEST_P(WebGLCompatibilityTest, DrawBuffers)
3649{
Corentin Walleze7557742017-06-01 13:09:57 -04003650 // Make sure we can use at least 4 attachments for the tests.
3651 bool useEXT = false;
3652 if (getClientMajorVersion() < 3)
3653 {
Yunchao He9550c602018-02-13 14:47:05 +08003654 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_EXT_draw_buffers"));
Corentin Walleze7557742017-06-01 13:09:57 -04003655
3656 glRequestExtensionANGLE("GL_EXT_draw_buffers");
3657 useEXT = true;
3658 EXPECT_GL_NO_ERROR();
3659 }
3660
3661 GLint maxDrawBuffers = 0;
3662 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
Yunchao He9550c602018-02-13 14:47:05 +08003663 // Test skipped because MAX_DRAW_BUFFERS is too small.
3664 ANGLE_SKIP_TEST_IF(maxDrawBuffers < 4);
Corentin Walleze7557742017-06-01 13:09:57 -04003665
3666 // Clears all the renderbuffers to red.
3667 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
3668 GLFramebuffer clearFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003669 glBindFramebuffer(GL_FRAMEBUFFER, clearFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003670
3671 glClearColor(1, 0, 0, 1);
3672 for (int i = 0; i < 4; ++i)
3673 {
Geoff Lange8afa902017-09-27 15:00:43 -04003674 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003675 renderbuffers[i]);
3676 glClear(GL_COLOR_BUFFER_BIT);
3677 }
3678 ASSERT_GL_NO_ERROR();
3679 };
3680
3681 // Checks that the renderbuffers specified by mask have the correct color
3682 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
3683 GLFramebuffer readFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003684 glBindFramebuffer(GL_FRAMEBUFFER, readFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003685
3686 for (int i = 0; i < 4; ++i)
3687 {
3688 if (mask & (1 << i))
3689 {
Geoff Lange8afa902017-09-27 15:00:43 -04003690 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3691 renderbuffers[i]);
Corentin Walleze7557742017-06-01 13:09:57 -04003692 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
3693 }
3694 }
3695 ASSERT_GL_NO_ERROR();
3696 };
3697
3698 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
3699 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
3700 if (useEXT)
3701 {
3702 glDrawBuffersEXT(numBuffers, buffers);
3703 }
3704 else
3705 {
3706 glDrawBuffers(numBuffers, buffers);
3707 }
3708 };
3709
3710 // Initialized the test framebuffer
3711 GLFramebuffer drawFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003712 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003713
3714 GLRenderbuffer renderbuffers[4];
3715 for (int i = 0; i < 4; ++i)
3716 {
3717 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
Geoff Langd84a00b2017-10-27 17:27:26 -04003718 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
Geoff Lange8afa902017-09-27 15:00:43 -04003719 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003720 renderbuffers[i]);
3721 }
3722
3723 ASSERT_GL_NO_ERROR();
3724
Corentin Walleze7557742017-06-01 13:09:57 -04003725 GLenum allDrawBuffers[] = {
3726 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3727 };
3728
3729 GLenum halfDrawBuffers[] = {
3730 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3731 };
3732
3733 // Test that when using gl_FragColor, only the first attachment is written to.
3734 const char *fragESSL1 =
3735 "precision highp float;\n"
3736 "void main()\n"
3737 "{\n"
3738 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3739 "}\n";
Olli Etuaho5804dc82018-04-13 14:11:46 +03003740 ANGLE_GL_PROGRAM(programESSL1, essl1_shaders::vs::Simple(), fragESSL1);
Corentin Walleze7557742017-06-01 13:09:57 -04003741
3742 {
3743 ClearEverythingToRed(renderbuffers);
3744
Geoff Lange8afa902017-09-27 15:00:43 -04003745 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003746 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003747 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003748 ASSERT_GL_NO_ERROR();
3749
3750 CheckColors(renderbuffers, 0b0001, GLColor::green);
3751 CheckColors(renderbuffers, 0b1110, GLColor::red);
3752 }
3753
3754 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
3755 // written to.
3756 {
3757 ClearEverythingToRed(renderbuffers);
3758
Geoff Lange8afa902017-09-27 15:00:43 -04003759 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003760 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003761 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003762 ASSERT_GL_NO_ERROR();
3763
3764 CheckColors(renderbuffers, 0b1111, GLColor::red);
3765 }
3766
3767 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
3768 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
3769 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
3770 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
3771 // attachments not declared in the shader should not be written to.
Olli Etuaho5804dc82018-04-13 14:11:46 +03003772 const char *positionAttrib;
Corentin Walleze7557742017-06-01 13:09:57 -04003773 const char *writeOddOutputsVert;
3774 const char *writeOddOutputsFrag;
3775 GLColor unwrittenColor;
3776 if (useEXT)
3777 {
3778 // In the extension, when an attachment isn't written to, it should get 0's
3779 unwrittenColor = GLColor(0, 0, 0, 0);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003780 positionAttrib = essl1_shaders::PositionAttrib();
3781 writeOddOutputsVert = essl1_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003782 writeOddOutputsFrag =
3783 "#extension GL_EXT_draw_buffers : require\n"
3784 "precision highp float;\n"
3785 "void main()\n"
3786 "{\n"
3787 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3788 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3789 "}\n";
3790 }
3791 else
3792 {
3793 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
3794 // because of the preceding clears.
3795 unwrittenColor = GLColor::red;
Olli Etuaho5804dc82018-04-13 14:11:46 +03003796 positionAttrib = essl3_shaders::PositionAttrib();
3797 writeOddOutputsVert = essl3_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003798 writeOddOutputsFrag =
3799 "#version 300 es\n"
3800 "precision highp float;\n"
3801 "layout(location = 1) out vec4 output1;"
3802 "layout(location = 3) out vec4 output2;"
3803 "void main()\n"
3804 "{\n"
3805 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3806 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3807 "}\n";
3808 }
3809 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
3810
3811 // Test that attachments not written to get the "unwritten" color
3812 {
3813 ClearEverythingToRed(renderbuffers);
3814
Geoff Lange8afa902017-09-27 15:00:43 -04003815 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003816 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003817 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003818 ASSERT_GL_NO_ERROR();
3819
3820 CheckColors(renderbuffers, 0b1010, GLColor::green);
3821 CheckColors(renderbuffers, 0b0101, unwrittenColor);
3822 }
3823
3824 // Test that attachments not written to get the "unwritten" color but that even when the
3825 // extension is used, disabled attachments are not written at all and stay red.
3826 {
3827 ClearEverythingToRed(renderbuffers);
3828
Geoff Lange8afa902017-09-27 15:00:43 -04003829 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003830 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003831 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003832 ASSERT_GL_NO_ERROR();
3833
3834 CheckColors(renderbuffers, 0b1000, GLColor::green);
3835 CheckColors(renderbuffers, 0b0100, unwrittenColor);
3836 CheckColors(renderbuffers, 0b0011, GLColor::red);
3837 }
3838}
3839
Geoff Lang536eca12017-09-13 11:23:35 -04003840// Test that it's possible to generate mipmaps on unsized floating point textures once the
3841// extensions have been enabled
3842TEST_P(WebGLCompatibilityTest, GenerateMipmapUnsizedFloatingPointTexture)
3843{
3844 if (extensionRequestable("GL_OES_texture_float"))
3845 {
3846 glRequestExtensionANGLE("GL_OES_texture_float");
3847 }
3848 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3849
3850 GLTexture texture;
3851 glBindTexture(GL_TEXTURE_2D, texture);
3852
3853 constexpr GLColor32F data[4] = {
3854 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3855 };
3856 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_FLOAT, data);
3857 ASSERT_GL_NO_ERROR();
3858
3859 glGenerateMipmap(GL_TEXTURE_2D);
3860 EXPECT_GL_NO_ERROR();
3861}
3862// Test that it's possible to generate mipmaps on unsized floating point textures once the
3863// extensions have been enabled
3864TEST_P(WebGLCompatibilityTest, GenerateMipmapSizedFloatingPointTexture)
3865{
3866 if (extensionRequestable("GL_OES_texture_float"))
3867 {
3868 glRequestExtensionANGLE("GL_OES_texture_float");
3869 }
3870 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3871
3872 if (extensionRequestable("GL_EXT_texture_storage"))
3873 {
3874 glRequestExtensionANGLE("GL_EXT_texture_storage");
3875 }
3876 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage"));
3877
3878 GLTexture texture;
3879 glBindTexture(GL_TEXTURE_2D, texture);
3880
3881 constexpr GLColor32F data[4] = {
3882 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3883 };
3884 glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA32F, 2, 2);
3885 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_FLOAT, data);
3886 ASSERT_GL_NO_ERROR();
3887
3888 glGenerateMipmap(GL_TEXTURE_2D);
3889 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3890
3891 if (extensionRequestable("GL_EXT_color_buffer_float"))
3892 {
3893 // Format is renderable but not filterable
3894 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3895 glGenerateMipmap(GL_TEXTURE_2D);
3896 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3897 }
3898
3899 if (extensionRequestable("GL_EXT_color_buffer_float_linear"))
3900 {
3901 // Format is renderable but not filterable
3902 glRequestExtensionANGLE("GL_EXT_color_buffer_float_linear");
3903
3904 if (extensionEnabled("GL_EXT_color_buffer_float"))
3905 {
3906 // Format is filterable and renderable
3907 glGenerateMipmap(GL_TEXTURE_2D);
3908 EXPECT_GL_NO_ERROR();
3909 }
3910 else
3911 {
3912 // Format is filterable but not renderable
3913 glGenerateMipmap(GL_TEXTURE_2D);
3914 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3915 }
3916 }
3917}
3918
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003919// Verify that a texture format is only allowed with extension enabled.
3920void WebGLCompatibilityTest::validateTexImageExtensionFormat(GLenum format,
3921 const std::string &extName)
3922{
3923 // Verify texture format fails by default.
3924 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3925 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3926
3927 if (extensionRequestable(extName))
3928 {
3929 // Verify texture format is allowed once extension is enabled.
3930 glRequestExtensionANGLE(extName.c_str());
3931 EXPECT_TRUE(extensionEnabled(extName));
3932
3933 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3934 ASSERT_GL_NO_ERROR();
3935 }
3936}
3937
Geoff Lang86f81162017-10-30 15:10:45 -04003938// Test enabling various non-compressed texture format extensions
3939TEST_P(WebGLCompatibilityTest, EnableTextureFormatExtensions)
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003940{
Geoff Lang2c5c41f2017-10-31 10:58:09 -04003941 ANGLE_SKIP_TEST_IF(IsOzone());
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003942 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
3943
3944 GLTexture texture;
3945 glBindTexture(GL_TEXTURE_2D, texture.get());
3946
3947 // Verify valid format is allowed.
3948 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3949 ASSERT_GL_NO_ERROR();
3950
3951 // Verify invalid format fails.
3952 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA32F, GL_UNSIGNED_BYTE, nullptr);
3953 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3954
3955 // Verify formats from enableable extensions.
Geoff Lang660b28c2017-10-30 12:58:56 -04003956 if (!IsOpenGLES())
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003957 {
3958 validateTexImageExtensionFormat(GL_RED_EXT, "GL_EXT_texture_rg");
3959 }
3960
3961 validateTexImageExtensionFormat(GL_SRGB_EXT, "GL_EXT_texture_sRGB");
3962 validateTexImageExtensionFormat(GL_BGRA_EXT, "GL_EXT_texture_format_BGRA8888");
3963}
3964
Geoff Lang86f81162017-10-30 15:10:45 -04003965void WebGLCompatibilityTest::validateCompressedTexImageExtensionFormat(GLenum format,
3966 GLsizei width,
3967 GLsizei height,
3968 GLsizei blockSize,
3969 const std::string &extName,
3970 bool subImageAllowed)
3971{
3972 std::vector<GLubyte> data(blockSize, 0u);
3973
3974 GLTexture texture;
3975 glBindTexture(GL_TEXTURE_2D, texture.get());
3976
3977 // Verify texture format fails by default.
3978 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
3979 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3980
3981 if (extensionRequestable(extName))
3982 {
3983 // Verify texture format is allowed once extension is enabled.
3984 glRequestExtensionANGLE(extName.c_str());
3985 EXPECT_TRUE(extensionEnabled(extName));
3986
3987 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
3988 EXPECT_GL_NO_ERROR();
3989
3990 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, blockSize,
3991 data.data());
3992 if (subImageAllowed)
3993 {
3994 EXPECT_GL_NO_ERROR();
3995 }
3996 else
3997 {
3998 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3999 }
4000 }
4001}
4002
4003// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGB_S3TC_DXT1_EXT
4004TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGB)
4005{
4006 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 8,
4007 "GL_EXT_texture_compression_dxt1", true);
4008}
4009
4010// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
4011TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGBA)
4012{
4013 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 8,
4014 "GL_EXT_texture_compression_dxt1", true);
4015}
4016
4017// Test enabling GL_ANGLE_texture_compression_dxt3
4018TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3)
4019{
4020 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 16,
4021 "GL_ANGLE_texture_compression_dxt3", true);
4022}
4023
4024// Test enabling GL_ANGLE_texture_compression_dxt5
4025TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5)
4026{
4027 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 16,
4028 "GL_ANGLE_texture_compression_dxt5", true);
4029}
4030
4031// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
4032TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGB)
4033{
4034 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 8,
4035 "GL_EXT_texture_compression_s3tc_srgb", true);
4036}
4037
4038// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
4039TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGBA)
4040{
4041 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 8,
4042 "GL_EXT_texture_compression_s3tc_srgb", true);
4043}
4044
4045// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
4046TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3SRGBA)
4047{
4048 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 16,
4049 "GL_EXT_texture_compression_s3tc_srgb", true);
4050}
4051
4052// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
4053TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5SRGBA)
4054{
4055 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 16,
4056 "GL_EXT_texture_compression_s3tc_srgb", true);
4057}
4058
4059// Test enabling GL_OES_compressed_ETC1_RGB8_texture
4060TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionETC1)
4061{
4062 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_OES, 4, 4, 8,
4063 "GL_OES_compressed_ETC1_RGB8_texture", false);
4064}
4065
4066// Test enabling GL_ANGLE_lossy_etc_decode
4067TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionLossyDecode)
4068{
4069 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 8,
4070 "GL_ANGLE_lossy_etc_decode", true);
4071}
4072
Frank Henigmanfccbac22017-05-28 17:29:26 -04004073// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
4074// qualifiers.
4075TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
4076{
4077 const std::string vertexShader =
4078 "#version 300 es\n"
4079 "uniform Block { mediump vec4 val; };\n"
4080 "void main() { gl_Position = val; }\n";
4081 const std::string fragmentShader =
4082 "#version 300 es\n"
4083 "uniform Block { highp vec4 val; };\n"
4084 "out highp vec4 out_FragColor;\n"
4085 "void main() { out_FragColor = val; }\n";
4086
4087 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
4088 ASSERT_NE(0u, vs);
4089 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
4090 ASSERT_NE(0u, fs);
4091
4092 GLuint program = glCreateProgram();
4093
4094 glAttachShader(program, vs);
4095 glDeleteShader(vs);
4096 glAttachShader(program, fs);
4097 glDeleteShader(fs);
4098
4099 glLinkProgram(program);
4100 GLint linkStatus;
4101 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
4102 ASSERT_EQ(0, linkStatus);
4103
4104 glDeleteProgram(program);
4105}
4106
Geoff Lang69df2422017-07-05 12:42:31 -04004107// Test no attribute vertex shaders
4108TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
4109{
4110 const std::string vertexShader =
4111 "#version 300 es\n"
4112 "void main()\n"
4113 "{\n"
4114 "\n"
4115 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
4116 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
4117 "}";
Geoff Lang69df2422017-07-05 12:42:31 -04004118
Olli Etuaho5804dc82018-04-13 14:11:46 +03004119 ANGLE_GL_PROGRAM(program, vertexShader, essl3_shaders::fs::Red());
Geoff Lang69df2422017-07-05 12:42:31 -04004120 glUseProgram(program);
4121
4122 glDrawArrays(GL_TRIANGLES, 0, 6);
4123 ASSERT_GL_NO_ERROR();
Olli Etuaho5804dc82018-04-13 14:11:46 +03004124 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Geoff Lang69df2422017-07-05 12:42:31 -04004125}
4126
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004127// Tests bindAttribLocations for length limit
4128TEST_P(WebGL2CompatibilityTest, BindAttribLocationLimitation)
4129{
4130 constexpr int maxLocStringLength = 1024;
4131 const std::string tooLongString(maxLocStringLength + 1, '_');
4132
4133 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
4134
4135 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4136}
4137
Geoff Langc287ea62016-09-16 14:46:51 -04004138// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4139// tests should be run against.
4140ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
4141 ES2_D3D9(),
4142 ES2_D3D11(),
4143 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04004144 ES2_OPENGL(),
4145 ES3_OPENGL(),
4146 ES2_OPENGLES(),
4147 ES3_OPENGLES());
4148
Jamie Madill07be8bf2017-02-02 19:59:57 -05004149ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04004150} // namespace