blob: 1b7eb884685a22b15b34362e432cfb6ca4cc6a8b [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
Geoff Lang23633562018-07-17 15:02:36 -04001473// Test that index values outside of the 32-bit integer range do not read out of bounds
1474TEST_P(WebGLCompatibilityTest, LargeIndexRange)
1475{
1476 ANGLE_SKIP_TEST_IF(!ensureExtensionEnabled("GL_OES_element_index_uint"));
1477
1478 const std::string &vert =
1479 "attribute vec4 a_Position;\n"
1480 "void main()\n"
1481 "{\n"
1482 " gl_Position = a_Position;\n"
1483 "}\n";
1484
1485 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
1486 glUseProgram(program.get());
1487
1488 glEnableVertexAttribArray(glGetAttribLocation(program, "a_Position"));
1489
1490 constexpr float kVertexData[] = {
1491 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1492 };
1493
1494 GLBuffer vertexBuffer;
1495 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
1496 glBufferData(GL_ARRAY_BUFFER, sizeof(kVertexData), kVertexData, GL_STREAM_DRAW);
1497
1498 constexpr GLuint kMaxIntAsGLuint = static_cast<GLuint>(std::numeric_limits<GLint>::max());
1499 constexpr GLuint kIndexData[] = {
1500 kMaxIntAsGLuint, kMaxIntAsGLuint + 1, kMaxIntAsGLuint + 2, kMaxIntAsGLuint + 3,
1501 };
1502
1503 GLBuffer indexBuffer;
1504 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexBuffer);
1505 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(kIndexData), kIndexData, GL_DYNAMIC_DRAW);
1506
1507 EXPECT_GL_NO_ERROR();
1508
1509 // First index is representable as 32-bit int but second is not
1510 glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, 0);
1511 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1512
1513 // Neither index is representable as 32-bit int
1514 glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, reinterpret_cast<void *>(sizeof(GLuint) * 2));
1515 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1516}
1517
Brandon Jones2a018152018-06-08 15:59:26 -07001518// Test for drawing with a null index buffer
1519TEST_P(WebGLCompatibilityTest, NullIndexBuffer)
1520{
1521 const std::string &vert =
1522 "attribute float a_pos;\n"
1523 "void main()\n"
1524 "{\n"
1525 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1526 "}\n";
1527
1528 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
1529 glUseProgram(program.get());
1530
1531 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1532 glEnableVertexAttribArray(0);
1533
1534 glDrawElements(GL_TRIANGLES, 0, GL_UNSIGNED_BYTE, 0);
1535 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1536}
1537
Corentin Wallez91c8de82017-10-12 16:32:44 -04001538// Test the checks for OOB reads in the vertex buffers, instanced version
1539TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
1540{
1541 const std::string &vert =
1542 "attribute float a_pos;\n"
1543 "attribute float a_w;\n"
1544 "void main()\n"
1545 "{\n"
1546 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1547 "}\n";
1548
Olli Etuaho5804dc82018-04-13 14:11:46 +03001549 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez91c8de82017-10-12 16:32:44 -04001550 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1551 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1552 ASSERT_NE(-1, posLocation);
1553 ASSERT_NE(-1, wLocation);
1554 glUseProgram(program.get());
1555
1556 GLBuffer buffer;
1557 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1558 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1559
1560 glEnableVertexAttribArray(posLocation);
1561 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1562 glVertexAttribDivisor(posLocation, 0);
1563
1564 glEnableVertexAttribArray(wLocation);
1565 glVertexAttribDivisor(wLocation, 1);
1566
1567 const uint8_t* zeroOffset = nullptr;
1568
1569 // Test touching the last element is valid.
1570 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1571 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1572 ASSERT_GL_NO_ERROR();
1573
1574 // Test touching the last element + 1 is invalid.
1575 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1576 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1577 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1578
1579 // Test touching the last element is valid, using a stride.
1580 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1581 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1582 ASSERT_GL_NO_ERROR();
1583
1584 // Test touching the last element + 1 is invalid, using a stride.
1585 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1586 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1587 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1588
1589 // Test any offset is valid if no vertices are drawn.
1590 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1591 glDrawArraysInstanced(GL_POINTS, 0, 0, 1);
1592 ASSERT_GL_NO_ERROR();
1593
1594 // Test any offset is valid if no primitives are drawn.
1595 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1596 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1597 ASSERT_GL_NO_ERROR();
1598}
1599
1600// Test the checks for OOB reads in the vertex buffers, ANGLE_instanced_arrays version
1601TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsInstancedANGLE)
1602{
1603 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_ANGLE_instanced_arrays"));
1604 glRequestExtensionANGLE("GL_ANGLE_instanced_arrays");
1605 EXPECT_GL_NO_ERROR();
1606
1607 const std::string &vert =
1608 "attribute float a_pos;\n"
1609 "attribute float a_w;\n"
1610 "void main()\n"
1611 "{\n"
1612 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1613 "}\n";
1614
Olli Etuaho5804dc82018-04-13 14:11:46 +03001615 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez91c8de82017-10-12 16:32:44 -04001616 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1617 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1618 ASSERT_NE(-1, posLocation);
1619 ASSERT_NE(-1, wLocation);
1620 glUseProgram(program.get());
1621
1622 GLBuffer buffer;
1623 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1624 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1625
1626 glEnableVertexAttribArray(posLocation);
1627 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1628 glVertexAttribDivisorANGLE(posLocation, 0);
1629
1630 glEnableVertexAttribArray(wLocation);
1631 glVertexAttribDivisorANGLE(wLocation, 1);
1632
1633 const uint8_t* zeroOffset = nullptr;
1634
1635 // Test touching the last element is valid.
1636 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1637 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001638 ASSERT_GL_NO_ERROR() << "touching the last element.";
Corentin Wallez91c8de82017-10-12 16:32:44 -04001639
1640 // Test touching the last element + 1 is invalid.
1641 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1642 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001643 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "touching the last element + 1.";
Corentin Wallez91c8de82017-10-12 16:32:44 -04001644
1645 // Test touching the last element is valid, using a stride.
1646 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1647 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001648 ASSERT_GL_NO_ERROR() << "touching the last element using a stride.";
Corentin Wallez91c8de82017-10-12 16:32:44 -04001649
1650 // Test touching the last element + 1 is invalid, using a stride.
1651 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1652 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001653 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "touching the last element + 1 using a stride.";
Corentin Wallez91c8de82017-10-12 16:32:44 -04001654
1655 // Test any offset is valid if no vertices are drawn.
1656 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1657 glDrawArraysInstancedANGLE(GL_POINTS, 0, 0, 1);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001658 ASSERT_GL_NO_ERROR() << "any offset with no vertices.";
Corentin Wallez91c8de82017-10-12 16:32:44 -04001659
1660 // Test any offset is valid if no primitives are drawn.
1661 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1662 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 0);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001663 ASSERT_GL_NO_ERROR() << "any offset with primitives.";
Corentin Wallezfd456442016-12-21 17:57:00 -05001664}
1665
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001666// Test the checks for OOB reads in the index buffer
1667TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -05001668{
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001669 const std::string &vert =
1670 "attribute float a_pos;\n"
1671 "void main()\n"
1672 "{\n"
1673 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1674 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -05001675
Olli Etuaho5804dc82018-04-13 14:11:46 +03001676 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001677 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1678 ASSERT_NE(-1, posLocation);
1679 glUseProgram(program.get());
1680
1681 GLBuffer vertexBuffer;
1682 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1683 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1684
1685 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001686 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001687
1688 const uint8_t *zeroOffset = nullptr;
1689 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
1690
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001691 GLBuffer indexBuffer;
1692 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1693 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -05001694 ASSERT_GL_NO_ERROR();
1695
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001696 // Test touching the last index is valid
1697 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1698 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -05001699
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001700 // Test touching the last + 1 element is invalid
1701 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
1702 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -05001703
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001704 // Test any offset if valid if count is zero
1705 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
1706 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -05001707
1708 // Test touching the first index is valid
1709 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1710 ASSERT_GL_NO_ERROR();
1711
1712 // Test touching the first - 1 index is invalid
1713 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
1714 // the historic behavior of WebGL implementations
1715 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
1716 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -05001717}
1718
Corentin Wallez91c8de82017-10-12 16:32:44 -04001719// Test the checks for OOB in vertex buffers caused by indices, non-instanced version
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001720TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInVertexBuffer)
1721{
1722 const std::string &vert =
1723 "attribute float a_pos;\n"
1724 "void main()\n"
1725 "{\n"
1726 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1727 "}\n";
1728
Olli Etuaho5804dc82018-04-13 14:11:46 +03001729 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001730 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1731 ASSERT_NE(-1, posLocation);
1732 glUseProgram(program.get());
1733
1734 GLBuffer vertexBuffer;
1735 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1736 glBufferData(GL_ARRAY_BUFFER, 8, nullptr, GL_STATIC_DRAW);
1737
1738 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001739 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001740
1741 const uint8_t *zeroOffset = nullptr;
1742 const uint8_t testIndices[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 255};
1743
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001744 GLBuffer indexBuffer;
1745 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1746 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(testIndices), testIndices, GL_STATIC_DRAW);
1747 ASSERT_GL_NO_ERROR();
1748
1749 // Test touching the end of the vertex buffer is valid
1750 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 7);
1751 ASSERT_GL_NO_ERROR();
1752
1753 // Test touching just after the end of the vertex buffer is invalid
1754 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 8);
1755 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1756
1757 // Test touching the whole vertex buffer is valid
1758 glDrawElements(GL_POINTS, 8, GL_UNSIGNED_BYTE, zeroOffset + 0);
1759 ASSERT_GL_NO_ERROR();
1760
1761 // Test an index that would be negative
1762 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 9);
1763 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1764}
1765
Frank Henigman6137ddc2017-02-10 18:55:07 -05001766// Test depth range with 'near' more or less than 'far.'
1767TEST_P(WebGLCompatibilityTest, DepthRange)
1768{
1769 glDepthRangef(0, 1);
1770 ASSERT_GL_NO_ERROR();
1771
1772 glDepthRangef(.5, .5);
1773 ASSERT_GL_NO_ERROR();
1774
1775 glDepthRangef(1, 0);
1776 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1777}
1778
Frank Henigman146e8a12017-03-02 23:22:37 -05001779// Test all blend function combinations.
1780// In WebGL it is invalid to combine constant color with constant alpha.
1781TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
1782{
1783 constexpr GLenum srcFunc[] = {
1784 GL_ZERO,
1785 GL_ONE,
1786 GL_SRC_COLOR,
1787 GL_ONE_MINUS_SRC_COLOR,
1788 GL_DST_COLOR,
1789 GL_ONE_MINUS_DST_COLOR,
1790 GL_SRC_ALPHA,
1791 GL_ONE_MINUS_SRC_ALPHA,
1792 GL_DST_ALPHA,
1793 GL_ONE_MINUS_DST_ALPHA,
1794 GL_CONSTANT_COLOR,
1795 GL_ONE_MINUS_CONSTANT_COLOR,
1796 GL_CONSTANT_ALPHA,
1797 GL_ONE_MINUS_CONSTANT_ALPHA,
1798 GL_SRC_ALPHA_SATURATE,
1799 };
1800
1801 constexpr GLenum dstFunc[] = {
1802 GL_ZERO, GL_ONE,
1803 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1804 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1805 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1806 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
1807 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
1808 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
1809 };
1810
1811 for (GLenum src : srcFunc)
1812 {
1813 for (GLenum dst : dstFunc)
1814 {
1815 glBlendFunc(src, dst);
1816 CheckBlendFunctions(src, dst);
1817 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
1818 CheckBlendFunctions(src, dst);
1819 }
1820 }
1821}
1822
Geoff Langfc32e8b2017-05-31 14:16:59 -04001823// Test that binding/querying uniforms and attributes with invalid names generates errors
1824TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
1825{
1826 const std::string validAttribName =
1827 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
1828 const std::string validUniformName =
1829 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
Geoff Langa71a98e2017-06-19 15:15:00 -04001830 std::vector<char> invalidSet = {'"', '$', '`', '@', '\''};
1831 if (getClientMajorVersion() < 3)
1832 {
1833 invalidSet.push_back('\\');
1834 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04001835
1836 std::string vert = "attribute float ";
1837 vert += validAttribName;
1838 vert +=
1839 ";\n"
1840 "void main()\n"
1841 "{\n"
1842 " gl_Position = vec4(1.0);\n"
1843 "}\n";
1844
1845 std::string frag =
1846 "precision highp float;\n"
1847 "uniform vec4 ";
1848 frag += validUniformName;
Geoff Langcab92ee2017-07-19 17:32:07 -04001849 // Insert illegal characters into comments
Geoff Langfc32e8b2017-05-31 14:16:59 -04001850 frag +=
1851 ";\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001852 " // $ \" @ /*\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001853 "void main()\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001854 "{/*\n"
1855 " ` @ $\n"
1856 " */gl_FragColor = vec4(1.0);\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001857 "}\n";
1858
1859 ANGLE_GL_PROGRAM(program, vert, frag);
1860 EXPECT_GL_NO_ERROR();
1861
1862 for (char invalidChar : invalidSet)
1863 {
1864 std::string invalidName = validAttribName + invalidChar;
1865 glGetAttribLocation(program, invalidName.c_str());
1866 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1867 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1868
1869 glBindAttribLocation(program, 0, invalidName.c_str());
1870 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1871 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1872 }
1873
1874 for (char invalidChar : invalidSet)
1875 {
1876 std::string invalidName = validUniformName + invalidChar;
1877 glGetUniformLocation(program, invalidName.c_str());
1878 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1879 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1880 }
1881
1882 for (char invalidChar : invalidSet)
1883 {
1884 std::string invalidAttribName = validAttribName + invalidChar;
1885 const char *invalidVert[] = {
1886 "attribute float ",
1887 invalidAttribName.c_str(),
1888 ";\n",
1889 "void main()\n",
1890 "{\n",
1891 " gl_Position = vec4(1.0);\n",
1892 "}\n",
1893 };
1894
1895 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1896 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
1897 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1898 glDeleteShader(shader);
1899 }
1900}
1901
Geoff Langcab92ee2017-07-19 17:32:07 -04001902// Test that line continuation is handled correctly when valdiating shader source
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -07001903TEST_P(WebGLCompatibilityTest, ShaderSourceLineContinuation)
1904{
1905 // Verify that a line continuation character (i.e. backslash) cannot be used
1906 // within a preprocessor directive in a ES2 context.
1907 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
1908
1909 const char *validVert =
1910 "#define foo this is a test\n"
1911 "precision mediump float;\n"
1912 "void main()\n"
1913 "{\n"
1914 " gl_Position = vec4(1.0);\n"
1915 "}\n";
1916
1917 const char *invalidVert =
1918 "#define foo this \\n"
1919 " is a test\n"
1920 "precision mediump float;\n"
1921 "void main()\n"
1922 "{\n"
1923 " gl_Position = vec4(1.0);\n"
1924 "}\n";
1925
1926 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1927 glShaderSource(shader, 1, &validVert, nullptr);
1928 EXPECT_GL_NO_ERROR();
1929
1930 glShaderSource(shader, 1, &invalidVert, nullptr);
1931 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1932 glDeleteShader(shader);
1933}
1934
1935// Test that line continuation is handled correctly when valdiating shader source
Geoff Langcab92ee2017-07-19 17:32:07 -04001936TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
1937{
1938 const char *validVert =
1939 "#version 300 es\n"
1940 "precision mediump float;\n"
1941 "\n"
1942 "void main ()\n"
1943 "{\n"
1944 " float f\\\n"
1945 "oo = 1.0;\n"
1946 " gl_Position = vec4(foo);\n"
1947 "}\n";
1948
1949 const char *invalidVert =
1950 "#version 300 es\n"
1951 "precision mediump float;\n"
1952 "\n"
1953 "void main ()\n"
1954 "{\n"
1955 " float f\\$\n"
1956 "oo = 1.0;\n"
1957 " gl_Position = vec4(foo);\n"
1958 "}\n";
1959
1960 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1961 glShaderSource(shader, 1, &validVert, nullptr);
1962 EXPECT_GL_NO_ERROR();
1963 glShaderSource(shader, 1, &invalidVert, nullptr);
1964 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1965 glDeleteShader(shader);
1966}
1967
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001968// Tests bindAttribLocations for reserved prefixes and length limits
1969TEST_P(WebGLCompatibilityTest, BindAttribLocationLimitation)
1970{
1971 constexpr int maxLocStringLength = 256;
1972 const std::string tooLongString(maxLocStringLength + 1, '_');
1973
1974 glBindAttribLocation(0, 0, "_webgl_var");
1975
1976 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1977
1978 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
1979
1980 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1981}
1982
Corentin Wallez0dc97812017-06-22 14:38:44 -04001983// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001984TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1985{
1986 const std::string &vert =
1987 "attribute float a_pos;\n"
1988 "void main()\n"
1989 "{\n"
1990 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1991 "}\n";
1992
Olli Etuaho5804dc82018-04-13 14:11:46 +03001993 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Geoff Lang407d4e72017-04-12 14:54:11 -04001994
1995 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1996 ASSERT_NE(-1, posLocation);
1997
1998 glUseProgram(program.get());
1999
2000 GLBuffer buffer;
2001 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
2002 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
2003
2004 glEnableVertexAttribArray(posLocation);
2005 glVertexAttribDivisor(posLocation, 1);
2006
Geoff Lang407d4e72017-04-12 14:54:11 -04002007 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
2008 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04002009 ASSERT_GL_NO_ERROR();
2010}
2011
Corentin Wallez0844f2d2017-01-31 17:02:59 -05002012// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
2013TEST_P(WebGLCompatibilityTest, NPOT)
2014{
2015 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
2016
2017 // Create a texture and set an NPOT mip 0, should always be acceptable.
2018 GLTexture texture;
2019 glBindTexture(GL_TEXTURE_2D, texture.get());
2020 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2021 ASSERT_GL_NO_ERROR();
2022
2023 // Try setting an NPOT mip 1 and verify the error if WebGL 1
2024 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2025 if (getClientMajorVersion() < 3)
2026 {
2027 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2028 }
2029 else
2030 {
2031 ASSERT_GL_NO_ERROR();
2032 }
2033
2034 if (extensionRequestable("GL_OES_texture_npot"))
2035 {
2036 glRequestExtensionANGLE("GL_OES_texture_npot");
2037 ASSERT_GL_NO_ERROR();
2038
2039 // Try again to set NPOT mip 1
2040 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2041 ASSERT_GL_NO_ERROR();
2042 }
2043}
2044
Jamie Madillcad97ee2017-02-02 18:52:44 -05002045template <typename T>
2046void FillTexture2D(GLuint texture,
2047 GLsizei width,
2048 GLsizei height,
2049 const T &onePixelData,
2050 GLint level,
2051 GLint internalFormat,
2052 GLenum format,
2053 GLenum type)
2054{
2055 std::vector<T> allPixelsData(width * height, onePixelData);
2056
2057 glBindTexture(GL_TEXTURE_2D, texture);
2058 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
2059 allPixelsData.data());
2060 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2061 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2062 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2063 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2064}
2065
Frank Henigman875bbba2017-02-08 16:38:17 -05002066// Test that unset gl_Position defaults to (0,0,0,0).
2067TEST_P(WebGLCompatibilityTest, DefaultPosition)
2068{
2069 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
2070 // and green otherwise. The center of each quadrant will be red if and only if all
2071 // four corners are red.
2072 const std::string vertexShader =
2073 "attribute vec3 pos;\n"
2074 "varying vec4 color;\n"
2075 "void main() {\n"
2076 " if (gl_Position == vec4(0,0,0,0)) {\n"
2077 " color = vec4(1,0,0,1);\n"
2078 " } else {\n"
2079 " color = vec4(0,1,0,1);\n"
2080 " }\n"
2081 " gl_Position = vec4(pos,1);\n"
2082 "}\n";
2083
2084 const std::string fragmentShader =
2085 "precision mediump float;\n"
2086 "varying vec4 color;\n"
2087 "void main() {\n"
2088 " gl_FragColor = color;\n"
2089 "}\n";
2090
2091 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2092 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
2093 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
2094 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
2095 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
2096 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
2097}
2098
Jamie Madilla4595b82017-01-11 17:36:34 -05002099// Tests that a rendering feedback loop triggers a GL error under WebGL.
2100// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
2101TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
2102{
2103 const std::string vertexShader =
2104 "attribute vec4 a_position;\n"
2105 "varying vec2 v_texCoord;\n"
2106 "void main() {\n"
2107 " gl_Position = a_position;\n"
2108 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
2109 "}\n";
2110
2111 const std::string fragmentShader =
2112 "precision mediump float;\n"
2113 "varying vec2 v_texCoord;\n"
2114 "uniform sampler2D u_texture;\n"
2115 "void main() {\n"
2116 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
2117 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
2118 "}\n";
2119
2120 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05002121 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05002122
2123 ASSERT_GL_NO_ERROR();
2124
2125 GLFramebuffer framebuffer;
2126 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2127 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2128
2129 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2130
2131 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2132
2133 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
2134 ASSERT_NE(-1, uniformLoc);
2135
2136 glUseProgram(program.get());
2137 glUniform1i(uniformLoc, 0);
2138 glDisable(GL_BLEND);
2139 glDisable(GL_DEPTH_TEST);
2140 ASSERT_GL_NO_ERROR();
2141
2142 // Drawing with a texture that is also bound to the current framebuffer should fail
2143 glBindTexture(GL_TEXTURE_2D, texture.get());
2144 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2145 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2146
2147 // Ensure that the texture contents did not change after the previous render
2148 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2149 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2150 ASSERT_GL_NO_ERROR();
2151 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
2152
2153 // Drawing when texture is bound to an inactive uniform should succeed
2154 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05002155 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05002156
2157 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2158 glActiveTexture(GL_TEXTURE1);
2159 glBindTexture(GL_TEXTURE_2D, texture.get());
2160 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2161 ASSERT_GL_NO_ERROR();
2162 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2163}
2164
Bryan Bernhart58806562017-01-05 13:09:31 -08002165// Test for the max draw buffers and color attachments.
2166TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
2167{
2168 // This test only applies to ES2.
2169 if (getClientMajorVersion() != 2)
2170 {
2171 return;
2172 }
2173
2174 GLFramebuffer fbo[2];
2175 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
2176
2177 // Test that is valid when we bind with a single attachment point.
2178 GLTexture texture;
2179 glBindTexture(GL_TEXTURE_2D, texture.get());
2180 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2181 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2182 ASSERT_GL_NO_ERROR();
2183
2184 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
2185 // attachment point.
2186 if (extensionRequestable("GL_EXT_draw_buffers"))
2187 {
2188 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2189 EXPECT_GL_NO_ERROR();
2190 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
2191
2192 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
2193
2194 GLTexture texture2;
2195 glBindTexture(GL_TEXTURE_2D, texture2.get());
2196 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2197 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
2198 0);
2199 ASSERT_GL_NO_ERROR();
2200 }
2201}
2202
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002203// Test that the offset in the index buffer is forced to be a multiple of the element size
2204TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
2205{
2206 const std::string &vert =
2207 "attribute vec3 a_pos;\n"
2208 "void main()\n"
2209 "{\n"
2210 " gl_Position = vec4(a_pos, 1.0);\n"
2211 "}\n";
2212
Olli Etuaho5804dc82018-04-13 14:11:46 +03002213 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002214
2215 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
2216 ASSERT_NE(-1, posLocation);
2217 glUseProgram(program.get());
2218
2219 const auto &vertices = GetQuadVertices();
2220
2221 GLBuffer vertexBuffer;
2222 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
2223 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
2224 GL_STATIC_DRAW);
2225
2226 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
2227 glEnableVertexAttribArray(posLocation);
2228
2229 GLBuffer indexBuffer;
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002230 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002231 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
2232 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
2233
2234 ASSERT_GL_NO_ERROR();
2235
2236 const char *zeroIndices = nullptr;
2237
2238 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
2239 ASSERT_GL_NO_ERROR();
2240
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002241 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002242 ASSERT_GL_NO_ERROR();
2243
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002244 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices + 1);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002245 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2246}
2247
2248// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
2249// size
2250TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
2251{
2252 const char *zeroOffset = nullptr;
2253
2254 // Base case, vector of two floats
2255 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
2256 ASSERT_GL_NO_ERROR();
2257
2258 // Test setting a non-multiple offset
2259 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
2260 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2261 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
2262 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2263 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
2264 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2265
2266 // Test setting a non-multiple stride
2267 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
2268 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2269 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
2270 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2271 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
2272 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2273}
2274
Jamie Madillcad97ee2017-02-02 18:52:44 -05002275void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
2276 const std::array<GLenum, 2> &drawBuffers,
2277 GLenum expectedError)
2278{
2279 glDrawBuffersEXT(2, drawBuffers.data());
2280
2281 // Make sure framebuffer is complete before feedback loop detection
2282 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2283
2284 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
2285
2286 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
2287 // it should be NO_ERROR"
2288 EXPECT_GL_ERROR(expectedError);
2289}
2290
2291// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
2292// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
2293TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
2294{
2295 const std::string vertexShader =
2296 "attribute vec4 aPosition;\n"
2297 "varying vec2 texCoord;\n"
2298 "void main() {\n"
2299 " gl_Position = aPosition;\n"
2300 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2301 "}\n";
2302
2303 const std::string fragmentShader =
2304 "#extension GL_EXT_draw_buffers : require\n"
2305 "precision mediump float;\n"
2306 "uniform sampler2D tex;\n"
2307 "varying vec2 texCoord;\n"
2308 "void main() {\n"
2309 " gl_FragData[0] = texture2D(tex, texCoord);\n"
2310 " gl_FragData[1] = texture2D(tex, texCoord);\n"
2311 "}\n";
2312
2313 GLsizei width = 8;
2314 GLsizei height = 8;
2315
2316 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
2317 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
2318 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
2319 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
2320 {
2321 // No WEBGL_draw_buffers support -- this is legal.
2322 return;
2323 }
2324
2325 GLint maxDrawBuffers = 0;
2326 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2327
Yunchao He9550c602018-02-13 14:47:05 +08002328 // Test skipped because MAX_DRAW_BUFFERS is too small.
2329 ANGLE_SKIP_TEST_IF(maxDrawBuffers < 2);
Jamie Madillcad97ee2017-02-02 18:52:44 -05002330
2331 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2332 glUseProgram(program.get());
2333 glViewport(0, 0, width, height);
2334
2335 GLTexture tex0;
2336 GLTexture tex1;
2337 GLFramebuffer fbo;
2338 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2339 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2340 ASSERT_GL_NO_ERROR();
2341
2342 glBindTexture(GL_TEXTURE_2D, tex1.get());
2343 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2344 ASSERT_NE(-1, texLoc);
2345 glUniform1i(texLoc, 0);
2346 ASSERT_GL_NO_ERROR();
2347
2348 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2349 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2350 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2351 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2352
2353 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
2354 GL_INVALID_OPERATION);
2355 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2356 GL_INVALID_OPERATION);
2357 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2358}
2359
Jamie Madill07be8bf2017-02-02 19:59:57 -05002360// Test tests that texture copying feedback loops are properly rejected in WebGL.
2361// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
2362TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
2363{
2364 GLTexture texture;
2365 glBindTexture(GL_TEXTURE_2D, texture.get());
2366 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2367 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2368 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2369 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2370 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2371
2372 GLTexture texture2;
2373 glBindTexture(GL_TEXTURE_2D, texture2.get());
2374 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2377 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2378 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2379
2380 GLFramebuffer framebuffer;
2381 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2382 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2383
2384 // framebuffer should be FRAMEBUFFER_COMPLETE.
2385 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2386 ASSERT_GL_NO_ERROR();
2387
2388 // testing copyTexImage2D
2389
2390 // copyTexImage2D to same texture but different level
2391 glBindTexture(GL_TEXTURE_2D, texture.get());
2392 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
2393 EXPECT_GL_NO_ERROR();
2394
2395 // copyTexImage2D to same texture same level, invalid feedback loop
2396 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2397 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2398
2399 // copyTexImage2D to different texture
2400 glBindTexture(GL_TEXTURE_2D, texture2.get());
2401 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2402 EXPECT_GL_NO_ERROR();
2403
2404 // testing copyTexSubImage2D
2405
2406 // copyTexSubImage2D to same texture but different level
2407 glBindTexture(GL_TEXTURE_2D, texture.get());
2408 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
2409 EXPECT_GL_NO_ERROR();
2410
2411 // copyTexSubImage2D to same texture same level, invalid feedback loop
2412 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2413 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2414
2415 // copyTexSubImage2D to different texture
2416 glBindTexture(GL_TEXTURE_2D, texture2.get());
2417 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2418 EXPECT_GL_NO_ERROR();
2419}
2420
2421void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
2422 const std::array<GLenum, 2> &drawBuffers,
2423 GLenum expectedError)
2424{
2425 glDrawBuffers(2, drawBuffers.data());
2426
2427 // Make sure framebuffer is complete before feedback loop detection
2428 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2429
2430 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
2431
2432 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
2433 // it should be NO_ERROR"
2434 EXPECT_GL_ERROR(expectedError);
2435}
2436
Yuly Novikov817232e2017-02-22 18:36:10 -05002437// Tests invariance matching rules between built in varyings.
2438// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
2439TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
2440{
2441 const std::string vertexShaderVariant =
2442 "varying vec4 v_varying;\n"
2443 "void main()\n"
2444 "{\n"
2445 " gl_PointSize = 1.0;\n"
2446 " gl_Position = v_varying;\n"
2447 "}";
2448 const std::string fragmentShaderInvariantGlFragCoord =
2449 "invariant gl_FragCoord;\n"
2450 "void main()\n"
2451 "{\n"
2452 " gl_FragColor = gl_FragCoord;\n"
2453 "}";
2454 const std::string fragmentShaderInvariantGlPointCoord =
2455 "invariant gl_PointCoord;\n"
2456 "void main()\n"
2457 "{\n"
2458 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
2459 "}";
2460
2461 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
2462 EXPECT_EQ(0u, program);
2463
2464 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
2465 EXPECT_EQ(0u, program);
2466}
2467
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04002468// Tests global namespace conflicts between uniforms and attributes.
2469// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
2470TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
2471{
2472 const std::string vertexShader =
2473 "attribute vec4 foo;\n"
2474 "void main()\n"
2475 "{\n"
2476 " gl_Position = foo;\n"
2477 "}";
2478 const std::string fragmentShader =
2479 "precision mediump float;\n"
2480 "uniform vec4 foo;\n"
2481 "void main()\n"
2482 "{\n"
2483 " gl_FragColor = foo;\n"
2484 "}";
2485
2486 GLuint program = CompileProgram(vertexShader, fragmentShader);
2487 EXPECT_EQ(0u, program);
2488}
2489
Geoff Lang966c9402017-04-18 12:38:27 -04002490// Test dimension and image size validation of compressed textures
2491TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
2492{
2493 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
2494 {
2495 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
2496 }
2497
Yunchao He9550c602018-02-13 14:47:05 +08002498 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_compression_dxt1"));
Geoff Lang966c9402017-04-18 12:38:27 -04002499
2500 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
2501
2502 GLTexture texture;
2503 glBindTexture(GL_TEXTURE_2D, texture);
2504
2505 // Regular case, verify that it works
2506 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2507 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2508 ASSERT_GL_NO_ERROR();
2509
2510 // Test various dimensions that are not valid
2511 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
2512 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2513 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2514
2515 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
2516 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2517 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2518
2519 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2520 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2521 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2522
2523 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2524 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2525 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2526
2527 // Test various image sizes that are not valid
2528 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2529 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
2530 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2531
2532 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2533 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
2534 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2535
2536 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
2537 CompressedImageDXT1);
2538 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2539
2540 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
2541 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2542 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2543
2544 // Fill a full mip chain and verify that it works
2545 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2546 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2547 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2548 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2549 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2550 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2551 ASSERT_GL_NO_ERROR();
2552
2553 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2554 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2555 ASSERT_GL_NO_ERROR();
2556
2557 // Test that non-block size sub-uploads are not valid for the 0 mip
2558 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2559 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2560 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2561
2562 // Test that non-block size sub-uploads are valid for if they fill the whole mip
2563 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2564 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2565 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2566 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2567 ASSERT_GL_NO_ERROR();
2568
2569 // Test that if the format miss-matches the texture, an error is generated
2570 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2571 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2572 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2573}
2574
Geoff Lang677bb6f2017-04-05 12:40:40 -04002575TEST_P(WebGLCompatibilityTest, L32FTextures)
2576{
2577 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
2578 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
2579
2580 for (auto extension : FloatingPointTextureExtensions)
2581 {
2582 if (strlen(extension) > 0 && extensionRequestable(extension))
2583 {
2584 glRequestExtensionANGLE(extension);
2585 ASSERT_GL_NO_ERROR();
2586 }
2587
2588 // Unsized L 32F
2589 {
2590 bool texture = extensionEnabled("GL_OES_texture_float");
2591 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2592 bool render = false;
2593 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
2594 textureData, readPixelData);
2595 }
2596
2597 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2598 {
2599 // Sized L 32F
2600 bool texture = extensionEnabled("GL_OES_texture_float") &&
2601 extensionEnabled("GL_EXT_texture_storage");
2602 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2603 bool render = false;
2604 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
2605 render, textureData, readPixelData);
2606 }
2607 }
2608}
2609
2610TEST_P(WebGLCompatibilityTest, A32FTextures)
2611{
2612 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
2613 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
2614
2615 for (auto extension : FloatingPointTextureExtensions)
2616 {
2617 if (strlen(extension) > 0 && extensionRequestable(extension))
2618 {
2619 glRequestExtensionANGLE(extension);
2620 ASSERT_GL_NO_ERROR();
2621 }
2622
2623 // Unsized A 32F
2624 {
2625 bool texture = extensionEnabled("GL_OES_texture_float");
2626 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2627 bool render = false;
2628 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
2629 textureData, readPixelData);
2630 }
2631
2632 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2633 {
2634 // Sized A 32F
2635 bool texture = extensionEnabled("GL_OES_texture_float") &&
2636 extensionEnabled("GL_EXT_texture_storage");
2637 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2638 bool render = false;
2639 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
2640 textureData, readPixelData);
2641 }
2642 }
2643}
2644
2645TEST_P(WebGLCompatibilityTest, LA32FTextures)
2646{
2647 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
2648 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
2649 textureData[1]};
2650
2651 for (auto extension : FloatingPointTextureExtensions)
2652 {
2653 if (strlen(extension) > 0 && extensionRequestable(extension))
2654 {
2655 glRequestExtensionANGLE(extension);
2656 ASSERT_GL_NO_ERROR();
2657 }
2658
2659 // Unsized LA 32F
2660 {
2661 bool texture = extensionEnabled("GL_OES_texture_float");
2662 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2663 bool render = false;
2664 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2665 filter, render, textureData, readPixelData);
2666 }
2667
2668 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2669 {
2670 // Sized LA 32F
2671 bool texture = extensionEnabled("GL_OES_texture_float") &&
2672 extensionEnabled("GL_EXT_texture_storage");
2673 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2674 bool render = false;
2675 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2676 filter, render, textureData, readPixelData);
2677 }
2678 }
2679}
2680
2681TEST_P(WebGLCompatibilityTest, R32FTextures)
2682{
2683 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
2684
2685 for (auto extension : FloatingPointTextureExtensions)
2686 {
2687 if (strlen(extension) > 0 && extensionRequestable(extension))
2688 {
2689 glRequestExtensionANGLE(extension);
2690 ASSERT_GL_NO_ERROR();
2691 }
2692
2693 // Unsized R 32F
2694 {
2695 bool texture =
2696 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
2697 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2698 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2699 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2700 }
2701
2702 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2703 {
2704 // Sized R 32F
2705 bool texture =
2706 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2707 extensionEnabled("GL_EXT_texture_rg") &&
2708 extensionEnabled("GL_EXT_texture_storage"));
2709 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2710 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2711 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2712 }
2713 }
2714}
2715
2716TEST_P(WebGLCompatibilityTest, RG32FTextures)
2717{
2718 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
2719
2720 for (auto extension : FloatingPointTextureExtensions)
2721 {
2722 if (strlen(extension) > 0 && extensionRequestable(extension))
2723 {
2724 glRequestExtensionANGLE(extension);
2725 ASSERT_GL_NO_ERROR();
2726 }
2727
2728 // Unsized RG 32F
2729 {
2730 bool texture =
2731 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
2732 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2733 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2734 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2735 }
2736
2737 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2738 {
2739 // Sized RG 32F
2740 bool texture =
2741 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2742 extensionEnabled("GL_EXT_texture_rg") &&
2743 extensionEnabled("GL_EXT_texture_storage"));
2744 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2745 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2746 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2747 }
2748 }
2749}
2750
2751TEST_P(WebGLCompatibilityTest, RGB32FTextures)
2752{
Yunchao He9550c602018-02-13 14:47:05 +08002753 ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002754
Geoff Lang677bb6f2017-04-05 12:40:40 -04002755 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
2756
2757 for (auto extension : FloatingPointTextureExtensions)
2758 {
2759 if (strlen(extension) > 0 && extensionRequestable(extension))
2760 {
2761 glRequestExtensionANGLE(extension);
2762 ASSERT_GL_NO_ERROR();
2763 }
2764
2765 // Unsized RGB 32F
2766 {
2767 bool texture = extensionEnabled("GL_OES_texture_float");
2768 bool filter = extensionEnabled("GL_OES_texture_float_linear");
Yuly Novikovd0828192018-06-15 15:51:07 -04002769 bool render = false;
Geoff Lang677bb6f2017-04-05 12:40:40 -04002770 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
2771 }
2772
2773 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2774 {
Yuly Novikovd0828192018-06-15 15:51:07 -04002775 // Sized RGB 32F
Geoff Lang677bb6f2017-04-05 12:40:40 -04002776 bool texture =
2777 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2778 extensionEnabled("GL_EXT_texture_storage"));
2779 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2780 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2781 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
2782 data);
2783 }
2784 }
2785}
2786
2787TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
2788{
2789 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2790
2791 for (auto extension : FloatingPointTextureExtensions)
2792 {
2793 if (strlen(extension) > 0 && extensionRequestable(extension))
2794 {
2795 glRequestExtensionANGLE(extension);
2796 ASSERT_GL_NO_ERROR();
2797 }
2798
2799 // Unsized RGBA 32F
2800 {
2801 bool texture = extensionEnabled("GL_OES_texture_float");
2802 bool filter = extensionEnabled("GL_OES_texture_float_linear");
Yuly Novikovd0828192018-06-15 15:51:07 -04002803 bool render = false;
Geoff Lang677bb6f2017-04-05 12:40:40 -04002804 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
2805 }
2806
2807 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2808 {
2809 // Sized RGBA 32F
2810 bool texture =
2811 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2812 extensionEnabled("GL_EXT_texture_storage"));
2813 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2814 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2815 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2816 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
2817 data);
2818 }
2819 }
2820}
2821
2822TEST_P(WebGLCompatibilityTest, R16FTextures)
2823{
2824 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
2825 const GLushort textureData[] = {
2826 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2827 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2828
2829 for (auto extension : FloatingPointTextureExtensions)
2830 {
2831 if (strlen(extension) > 0 && extensionRequestable(extension))
2832 {
2833 glRequestExtensionANGLE(extension);
2834 ASSERT_GL_NO_ERROR();
2835 }
2836
2837 // Unsized R 16F (OES)
2838 {
2839 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2840 extensionEnabled("GL_EXT_texture_rg");
Yuly Novikovd0828192018-06-15 15:51:07 -04002841 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
2842 bool render = false;
Geoff Lang677bb6f2017-04-05 12:40:40 -04002843 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2844 textureData, readPixelsData);
2845 }
2846
2847 // Unsized R 16F
2848 {
2849 bool texture = false;
2850 bool filter = false;
2851 bool render = false;
2852 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2853 textureData, readPixelsData);
2854 }
2855
Yuly Novikovd0828192018-06-15 15:51:07 -04002856 if (getClientMajorVersion() >= 3)
Geoff Lang677bb6f2017-04-05 12:40:40 -04002857 {
2858 // Sized R 16F
Yuly Novikovd0828192018-06-15 15:51:07 -04002859 bool texture = true;
2860 bool filter = true;
2861 bool render = extensionEnabled("GL_EXT_color_buffer_float");
Geoff Lang677bb6f2017-04-05 12:40:40 -04002862 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2863 textureData, readPixelsData);
2864 }
Yuly Novikovd0828192018-06-15 15:51:07 -04002865 else if (extensionEnabled("GL_EXT_texture_storage"))
2866 {
2867 // Sized R 16F (OES)
2868 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2869 extensionEnabled("GL_EXT_texture_rg");
2870 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
2871 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2872 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2873 textureData, readPixelsData);
2874 }
Geoff Lang677bb6f2017-04-05 12:40:40 -04002875 }
2876}
2877
2878TEST_P(WebGLCompatibilityTest, RG16FTextures)
2879{
2880 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
2881 const GLushort textureData[] = {
2882 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2883 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2884
2885 for (auto extension : FloatingPointTextureExtensions)
2886 {
2887 if (strlen(extension) > 0 && extensionRequestable(extension))
2888 {
2889 glRequestExtensionANGLE(extension);
2890 ASSERT_GL_NO_ERROR();
2891 }
2892
2893 // Unsized RG 16F (OES)
2894 {
2895 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2896 extensionEnabled("GL_EXT_texture_rg");
Yuly Novikovd0828192018-06-15 15:51:07 -04002897 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
2898 bool render = false;
Geoff Lang677bb6f2017-04-05 12:40:40 -04002899 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2900 textureData, readPixelsData);
2901 }
2902
2903 // Unsized RG 16F
2904 {
2905 bool texture = false;
2906 bool filter = false;
2907 bool render = false;
2908 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2909 textureData, readPixelsData);
2910 }
2911
Yuly Novikovd0828192018-06-15 15:51:07 -04002912 if (getClientMajorVersion() >= 3)
Geoff Lang677bb6f2017-04-05 12:40:40 -04002913 {
2914 // Sized RG 16F
Yuly Novikovd0828192018-06-15 15:51:07 -04002915 bool texture = true;
2916 bool filter = true;
2917 bool render = extensionEnabled("GL_EXT_color_buffer_float");
Geoff Lang677bb6f2017-04-05 12:40:40 -04002918 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2919 textureData, readPixelsData);
2920 }
Yuly Novikovd0828192018-06-15 15:51:07 -04002921 else if (extensionEnabled("GL_EXT_texture_storage"))
2922 {
2923 // Sized RG 16F (OES)
2924 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2925 extensionEnabled("GL_EXT_texture_rg");
2926 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
2927 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2928 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2929 textureData, readPixelsData);
2930 }
Geoff Lang677bb6f2017-04-05 12:40:40 -04002931 }
2932}
2933
2934TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2935{
Yunchao He9550c602018-02-13 14:47:05 +08002936 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002937
Geoff Lang677bb6f2017-04-05 12:40:40 -04002938 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2939 const GLushort textureData[] = {
2940 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2941 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2942
2943 for (auto extension : FloatingPointTextureExtensions)
2944 {
2945 if (strlen(extension) > 0 && extensionRequestable(extension))
2946 {
2947 glRequestExtensionANGLE(extension);
2948 ASSERT_GL_NO_ERROR();
2949 }
2950
2951 // Unsized RGB 16F (OES)
2952 {
2953 bool texture = extensionEnabled("GL_OES_texture_half_float");
Yuly Novikovd0828192018-06-15 15:51:07 -04002954 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
2955 bool render = false;
Geoff Lang677bb6f2017-04-05 12:40:40 -04002956 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2957 textureData, readPixelsData);
2958 }
2959
2960 // Unsized RGB 16F
2961 {
2962 bool texture = false;
2963 bool filter = false;
2964 bool render = false;
2965 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2966 textureData, readPixelsData);
2967 }
2968
Yuly Novikovd0828192018-06-15 15:51:07 -04002969 if (getClientMajorVersion() >= 3)
Geoff Lang677bb6f2017-04-05 12:40:40 -04002970 {
2971 // Sized RGB 16F
Yuly Novikovd0828192018-06-15 15:51:07 -04002972 bool texture = true;
2973 bool filter = true;
2974 // It is unclear how EXT_color_buffer_half_float applies to ES3.0 and above, however,
2975 // dEQP GLES3 es3fFboColorbufferTests.cpp verifies that texture attachment of GL_RGB16F
2976 // is possible, so assume that all GLES implementations support it.
Geoff Lang677bb6f2017-04-05 12:40:40 -04002977 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2978 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2979 textureData, readPixelsData);
2980 }
Yuly Novikovd0828192018-06-15 15:51:07 -04002981 else if (extensionEnabled("GL_EXT_texture_storage"))
2982 {
2983 // Sized RGB 16F (OES)
2984 bool texture = extensionEnabled("GL_OES_texture_half_float");
2985 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
2986 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2987 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2988 textureData, readPixelsData);
2989 }
Geoff Lang677bb6f2017-04-05 12:40:40 -04002990 }
2991}
2992
2993TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2994{
Yunchao He9550c602018-02-13 14:47:05 +08002995 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002996
Geoff Lang677bb6f2017-04-05 12:40:40 -04002997 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2998 const GLushort textureData[] = {
2999 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
3000 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
3001
3002 for (auto extension : FloatingPointTextureExtensions)
3003 {
3004 if (strlen(extension) > 0 && extensionRequestable(extension))
3005 {
3006 glRequestExtensionANGLE(extension);
3007 ASSERT_GL_NO_ERROR();
3008 }
3009
3010 // Unsized RGBA 16F (OES)
3011 {
3012 bool texture = extensionEnabled("GL_OES_texture_half_float");
Yuly Novikovd0828192018-06-15 15:51:07 -04003013 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
3014 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
Geoff Lang677bb6f2017-04-05 12:40:40 -04003015 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
3016 textureData, readPixelsData);
3017 }
3018
3019 // Unsized RGBA 16F
3020 {
3021 bool texture = false;
3022 bool filter = false;
3023 bool render = false;
3024 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
3025 textureData, readPixelsData);
3026 }
3027
Yuly Novikovd0828192018-06-15 15:51:07 -04003028 if (getClientMajorVersion() >= 3)
Geoff Lang677bb6f2017-04-05 12:40:40 -04003029 {
3030 // Sized RGBA 16F
Yuly Novikovd0828192018-06-15 15:51:07 -04003031 bool texture = true;
3032 bool filter = true;
3033 bool render = extensionEnabled("GL_EXT_color_buffer_float");
Geoff Lang677bb6f2017-04-05 12:40:40 -04003034 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
3035 textureData, readPixelsData);
3036 }
Yuly Novikovd0828192018-06-15 15:51:07 -04003037 else if (extensionEnabled("GL_EXT_texture_storage"))
3038 {
3039 // Sized RGBA 16F (OES)
3040 bool texture = extensionEnabled("GL_OES_texture_half_float");
3041 bool filter = extensionEnabled("GL_OES_texture_half_float_linear");
3042 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
3043 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
3044 textureData, readPixelsData);
3045 }
Geoff Lang677bb6f2017-04-05 12:40:40 -04003046 }
3047}
3048
Geoff Lang6e898aa2017-06-02 11:17:26 -04003049// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
3050// accepted by glTexImage2D
3051TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
3052{
Yunchao He9550c602018-02-13 14:47:05 +08003053 // Test skipped because it is only valid for WebGL1 contexts.
3054 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
Geoff Lang6e898aa2017-06-02 11:17:26 -04003055
Yunchao He9550c602018-02-13 14:47:05 +08003056 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_OES_texture_float"));
3057
Geoff Lang6e898aa2017-06-02 11:17:26 -04003058 glRequestExtensionANGLE("GL_OES_texture_float");
3059 ASSERT_GL_NO_ERROR();
3060
3061 GLTexture texture;
3062 glBindTexture(GL_TEXTURE_2D, texture);
3063
3064 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3065 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3066
3067 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
3068 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3069
3070 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
3071 {
3072 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
3073 ASSERT_GL_NO_ERROR();
3074
3075 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3076 EXPECT_GL_NO_ERROR();
3077 }
3078
3079 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
3080 {
3081 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
3082 ASSERT_GL_NO_ERROR();
3083
3084 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
3085 EXPECT_GL_NO_ERROR();
3086 }
3087}
3088
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003089// Verify GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point.
3090TEST_P(WebGLCompatibilityTest, DepthStencilAttachment)
3091{
3092 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3093
3094 // Test that attaching a bound texture succeeds.
3095 GLTexture texture;
3096 glBindTexture(GL_TEXTURE_2D, texture);
3097
3098 GLFramebuffer fbo;
3099 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3100
3101 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture, 0);
3102
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003103 GLint attachmentType = 0;
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003104 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003105 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003106 EXPECT_GL_NO_ERROR();
3107 EXPECT_GLENUM_EQ(GL_TEXTURE, attachmentType);
3108
3109 // Test when if no attach object at the named attachment point and pname is not OBJECT_TYPE.
3110 GLFramebuffer fbo2;
3111 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
3112
3113 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003114 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003115 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3116}
3117
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003118// Verify framebuffer attachments return expected types when in an inconsistant state.
3119TEST_P(WebGLCompatibilityTest, FramebufferAttachmentConsistancy)
3120{
3121 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3122
3123 GLFramebuffer fbo;
3124 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3125
3126 GLRenderbuffer rb1;
3127 glBindRenderbuffer(GL_RENDERBUFFER, rb1);
3128
3129 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb1);
3130
3131 GLint attachmentType = 0;
3132 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3133 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3134
3135 EXPECT_GL_NO_ERROR();
3136 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3137
3138 GLRenderbuffer rb2;
3139 glBindRenderbuffer(GL_RENDERBUFFER, rb2);
3140
3141 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3142
3143 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
3144 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3145
3146 EXPECT_GL_NO_ERROR();
3147 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)5f198102017-12-12 14:21:39 -08003148
3149 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb2);
3150
3151 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3152 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3153
3154 EXPECT_GL_NO_ERROR();
3155 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3156
3157 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3158
3159 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3160 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3161
3162 EXPECT_GL_NO_ERROR();
3163 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003164}
3165
Jamie Madill07be8bf2017-02-02 19:59:57 -05003166// This tests that rendering feedback loops works as expected with WebGL 2.
3167// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
3168TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
3169{
3170 const std::string vertexShader =
3171 "#version 300 es\n"
3172 "in vec4 aPosition;\n"
3173 "out vec2 texCoord;\n"
3174 "void main() {\n"
3175 " gl_Position = aPosition;\n"
3176 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3177 "}\n";
3178
3179 const std::string fragmentShader =
3180 "#version 300 es\n"
3181 "precision mediump float;\n"
3182 "uniform sampler2D tex;\n"
3183 "in vec2 texCoord;\n"
3184 "out vec4 oColor;\n"
3185 "void main() {\n"
3186 " oColor = texture(tex, texCoord);\n"
3187 "}\n";
3188
3189 GLsizei width = 8;
3190 GLsizei height = 8;
3191
3192 GLint maxDrawBuffers = 0;
3193 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3194 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
3195 ASSERT_GE(maxDrawBuffers, 2);
3196
3197 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3198 glUseProgram(program.get());
3199 glViewport(0, 0, width, height);
3200
3201 GLTexture tex0;
3202 GLTexture tex1;
3203 GLFramebuffer fbo;
3204 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3205 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3206 ASSERT_GL_NO_ERROR();
3207
3208 glBindTexture(GL_TEXTURE_2D, tex1.get());
3209 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3210 ASSERT_NE(-1, texLoc);
3211 glUniform1i(texLoc, 0);
3212
3213 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
3214 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3215 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3216 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
3217 ASSERT_GL_NO_ERROR();
3218
3219 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
3220 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
3221 GL_INVALID_OPERATION);
3222 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
3223}
3224
Jamie Madill1d37bc52017-02-02 19:59:58 -05003225// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
3226// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
3227TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
3228{
3229 const std::string vertexShader =
3230 "#version 300 es\n"
3231 "in vec4 aPosition;\n"
3232 "out vec2 texCoord;\n"
3233 "void main() {\n"
3234 " gl_Position = aPosition;\n"
3235 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3236 "}\n";
3237
3238 const std::string fragmentShader =
3239 "#version 300 es\n"
3240 "precision mediump float;\n"
3241 "uniform sampler2D tex;\n"
3242 "in vec2 texCoord;\n"
3243 "out vec4 oColor;\n"
3244 "void main() {\n"
3245 " oColor = texture(tex, texCoord);\n"
3246 "}\n";
3247
3248 GLsizei width = 8;
3249 GLsizei height = 8;
3250
3251 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3252 glUseProgram(program.get());
3253
3254 glViewport(0, 0, width, height);
3255
3256 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3257 glUniform1i(texLoc, 0);
3258
3259 // Create textures and allocate storage
3260 GLTexture tex0;
3261 GLTexture tex1;
Jamie Madill0fdb9562018-09-17 17:18:43 -04003262 GLTexture tex2;
Jamie Madill1d37bc52017-02-02 19:59:58 -05003263 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3264 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
3265 GL_UNSIGNED_INT);
Jamie Madill0fdb9562018-09-17 17:18:43 -04003266 FillTexture2D(tex2.get(), width, height, 0x40, 0, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL,
3267 GL_UNSIGNED_INT_24_8);
Jamie Madill1d37bc52017-02-02 19:59:58 -05003268 ASSERT_GL_NO_ERROR();
3269
3270 GLFramebuffer fbo;
3271 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3272 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3273
3274 // Test rendering and sampling feedback loop for depth buffer
3275 glBindTexture(GL_TEXTURE_2D, tex1.get());
3276 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
3277 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3278
3279 // The same image is used as depth buffer during rendering.
3280 glEnable(GL_DEPTH_TEST);
3281 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
Jamie Madill0fdb9562018-09-17 17:18:43 -04003282 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "Same image as depth buffer should fail";
Jamie Madill1d37bc52017-02-02 19:59:58 -05003283
3284 // The same image is used as depth buffer. But depth mask is false.
Jamie Madill38fe6842018-09-19 07:20:00 -04003285 // This is now considered a feedback loop and should generate an error. http://crbug.com/763695
Jamie Madill1d37bc52017-02-02 19:59:58 -05003286 glDepthMask(GL_FALSE);
3287 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
Jamie Madill38fe6842018-09-19 07:20:00 -04003288 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "Depth writes disabled should still fail";
Jamie Madill1d37bc52017-02-02 19:59:58 -05003289
3290 // The same image is used as depth buffer. But depth test is not enabled during rendering.
Jamie Madill38fe6842018-09-19 07:20:00 -04003291 // This is now considered a feedback loop and should generate an error. http://crbug.com/763695
Jamie Madill1d37bc52017-02-02 19:59:58 -05003292 glDepthMask(GL_TRUE);
3293 glDisable(GL_DEPTH_TEST);
3294 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
Jamie Madill38fe6842018-09-19 07:20:00 -04003295 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "Depth read disabled should still fail";
Jamie Madill1d37bc52017-02-02 19:59:58 -05003296
3297 // Test rendering and sampling feedback loop for stencil buffer
Jamie Madill0fdb9562018-09-17 17:18:43 -04003298 glBindTexture(GL_TEXTURE_2D, tex2.get());
Jamie Madill1d37bc52017-02-02 19:59:58 -05003299 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
Jamie Madill0fdb9562018-09-17 17:18:43 -04003300 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, tex2.get(), 0);
Jamie Madill1d37bc52017-02-02 19:59:58 -05003301 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3302 constexpr GLint stencilClearValue = 0x40;
3303 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
3304
3305 // The same image is used as stencil buffer during rendering.
3306 glEnable(GL_STENCIL_TEST);
3307 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
Jamie Madill0fdb9562018-09-17 17:18:43 -04003308 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "Same image as stencil buffer should fail";
Jamie Madill1d37bc52017-02-02 19:59:58 -05003309
3310 // The same image is used as stencil buffer. But stencil mask is zero.
Jamie Madill38fe6842018-09-19 07:20:00 -04003311 // This is now considered a feedback loop and should generate an error. http://crbug.com/763695
Jamie Madill1d37bc52017-02-02 19:59:58 -05003312 glStencilMask(0x0);
3313 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
Jamie Madill38fe6842018-09-19 07:20:00 -04003314 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "Stencil mask zero should still fail";
Jamie Madill1d37bc52017-02-02 19:59:58 -05003315
3316 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
Jamie Madill38fe6842018-09-19 07:20:00 -04003317 // This is now considered a feedback loop and should generate an error. http://crbug.com/763695
Jamie Madill1d37bc52017-02-02 19:59:58 -05003318 glStencilMask(0xffff);
3319 glDisable(GL_STENCIL_TEST);
3320 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
Jamie Madill38fe6842018-09-19 07:20:00 -04003321 EXPECT_GL_ERROR(GL_INVALID_OPERATION) << "Stencil test disabled should still fail";
Jamie Madill1d37bc52017-02-02 19:59:58 -05003322}
3323
Jamie Madillfd3dd432017-02-02 19:59:59 -05003324// The source and the target for CopyTexSubImage3D are the same 3D texture.
3325// But the level of the 3D texture != the level of the read attachment.
3326TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
3327{
3328 GLTexture texture;
3329 GLFramebuffer framebuffer;
3330
3331 glBindTexture(GL_TEXTURE_3D, texture.get());
3332 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3333
3334 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3335 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3336 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
3337 ASSERT_GL_NO_ERROR();
3338
3339 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3340 EXPECT_GL_NO_ERROR();
3341}
3342
3343// The source and the target for CopyTexSubImage3D are the same 3D texture.
3344// But the zoffset of the 3D texture != the layer of the read attachment.
3345TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
3346{
3347 GLTexture texture;
3348 GLFramebuffer framebuffer;
3349
3350 glBindTexture(GL_TEXTURE_3D, texture.get());
3351 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3352
3353 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3354 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
3355 ASSERT_GL_NO_ERROR();
3356
3357 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
3358 EXPECT_GL_NO_ERROR();
3359}
3360
3361// The source and the target for CopyTexSubImage3D are the same 3D texture.
3362// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
3363TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
3364{
3365 GLTexture texture;
3366 GLFramebuffer framebuffer;
3367
3368 glBindTexture(GL_TEXTURE_3D, texture.get());
3369 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3370
3371 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3372 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3373 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3374 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
3375 ASSERT_GL_NO_ERROR();
3376
3377 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3378 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3379}
3380
Corentin Wallez59c41592017-07-11 13:19:54 -04003381// Verify that errors are generated when there isn't a defined conversion between the clear type and
3382// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04003383TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
3384{
Yunchao He9550c602018-02-13 14:47:05 +08003385 // Test skipped for D3D11 because it generates D3D11 runtime warnings.
3386 ANGLE_SKIP_TEST_IF(IsD3D11());
Geoff Lang76e65652017-03-27 14:58:02 -04003387
3388 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3389 constexpr int clearInt[] = {0, 0, 0, 0};
3390 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3391
3392 GLTexture texture;
3393 GLFramebuffer framebuffer;
3394
3395 glBindTexture(GL_TEXTURE_2D, texture.get());
3396 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3397
3398 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
3399 ASSERT_GL_NO_ERROR();
3400
3401 // Unsigned integer buffer
3402 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
3403 ASSERT_GL_NO_ERROR();
3404
3405 glClearBufferfv(GL_COLOR, 0, clearFloat);
3406 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3407
3408 glClearBufferiv(GL_COLOR, 0, clearInt);
3409 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3410
3411 glClearBufferuiv(GL_COLOR, 0, clearUint);
3412 EXPECT_GL_NO_ERROR();
3413
3414 glClear(GL_COLOR_BUFFER_BIT);
3415 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3416
3417 // Integer buffer
3418 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
3419 ASSERT_GL_NO_ERROR();
3420
3421 glClearBufferfv(GL_COLOR, 0, clearFloat);
3422 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3423
3424 glClearBufferiv(GL_COLOR, 0, clearInt);
3425 EXPECT_GL_NO_ERROR();
3426
3427 glClearBufferuiv(GL_COLOR, 0, clearUint);
3428 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3429
3430 glClear(GL_COLOR_BUFFER_BIT);
3431 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3432
3433 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04003434 if (extensionRequestable("GL_EXT_color_buffer_float"))
3435 {
3436 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3437 }
Geoff Lang76e65652017-03-27 14:58:02 -04003438
Geoff Lang677bb6f2017-04-05 12:40:40 -04003439 if (extensionEnabled("GL_EXT_color_buffer_float"))
3440 {
3441 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3442 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003443
Geoff Lang677bb6f2017-04-05 12:40:40 -04003444 glClearBufferfv(GL_COLOR, 0, clearFloat);
3445 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003446
Geoff Lang677bb6f2017-04-05 12:40:40 -04003447 glClearBufferiv(GL_COLOR, 0, clearInt);
3448 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04003449
Geoff Lang677bb6f2017-04-05 12:40:40 -04003450 glClearBufferuiv(GL_COLOR, 0, clearUint);
3451 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3452
3453 glClear(GL_COLOR_BUFFER_BIT);
3454 EXPECT_GL_NO_ERROR();
3455 }
Geoff Lang76e65652017-03-27 14:58:02 -04003456
3457 // Normalized uint buffer
3458 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3459 ASSERT_GL_NO_ERROR();
3460
3461 glClearBufferfv(GL_COLOR, 0, clearFloat);
3462 EXPECT_GL_NO_ERROR();
3463
3464 glClearBufferiv(GL_COLOR, 0, clearInt);
3465 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3466
3467 glClearBufferuiv(GL_COLOR, 0, clearUint);
3468 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3469
3470 glClear(GL_COLOR_BUFFER_BIT);
3471 EXPECT_GL_NO_ERROR();
3472}
3473
Corentin Wallez59c41592017-07-11 13:19:54 -04003474// Test the interaction of WebGL compatibility clears with default framebuffers
3475TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
3476{
3477 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3478 constexpr int clearInt[] = {0, 0, 0, 0};
3479 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3480
3481 // glClear works as usual, this is also a regression test for a bug where we
3482 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
3483 glClear(GL_COLOR_BUFFER_BIT);
3484 EXPECT_GL_NO_ERROR();
3485
3486 // Default framebuffers are normalized uints, so only glClearBufferfv works.
3487 glClearBufferfv(GL_COLOR, 0, clearFloat);
3488 EXPECT_GL_NO_ERROR();
3489
3490 glClearBufferiv(GL_COLOR, 0, clearInt);
3491 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3492
3493 glClearBufferuiv(GL_COLOR, 0, clearUint);
3494 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3495}
3496
Geoff Lange4915782017-04-12 15:19:07 -04003497// Verify that errors are generate when trying to blit from an image to itself
3498TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
3499{
3500 GLTexture textures[2];
3501 glBindTexture(GL_TEXTURE_2D, textures[0]);
3502 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3503 glBindTexture(GL_TEXTURE_2D, textures[1]);
3504 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3505
3506 GLRenderbuffer renderbuffers[2];
3507 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
3508 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3509 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
3510 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3511
3512 GLFramebuffer framebuffers[2];
3513 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
3514 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
3515
3516 ASSERT_GL_NO_ERROR();
3517
3518 // Same texture
3519 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3520 0);
3521 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3522 0);
3523 ASSERT_GL_NO_ERROR();
3524 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3525 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3526
3527 // Same textures but different renderbuffers
3528 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3529 renderbuffers[0]);
3530 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3531 renderbuffers[1]);
3532 ASSERT_GL_NO_ERROR();
3533 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3534 ASSERT_GL_NO_ERROR();
3535 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3536 GL_NEAREST);
3537 ASSERT_GL_NO_ERROR();
3538 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3539 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3540 GL_NEAREST);
3541 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3542
3543 // Same renderbuffers but different textures
3544 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3545 0);
3546 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
3547 0);
3548 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3549 renderbuffers[0]);
3550 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3551 renderbuffers[0]);
3552 ASSERT_GL_NO_ERROR();
3553 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3554 ASSERT_GL_NO_ERROR();
3555 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3556 GL_NEAREST);
3557 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3558 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3559 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3560 GL_NEAREST);
3561 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3562}
3563
Geoff Lange0cff192017-05-30 13:04:56 -04003564// Verify that errors are generated when the fragment shader output doesn't match the bound color
3565// buffer types
3566TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
3567{
3568 const std::string vertexShader =
3569 "#version 300 es\n"
3570 "void main() {\n"
3571 " gl_Position = vec4(0, 0, 0, 1);\n"
3572 "}\n";
3573
3574 const std::string fragmentShader =
3575 "#version 300 es\n"
3576 "precision mediump float;\n"
3577 "layout(location = 0) out vec4 floatOutput;\n"
3578 "layout(location = 1) out uvec4 uintOutput;\n"
3579 "layout(location = 2) out ivec4 intOutput;\n"
3580 "void main() {\n"
3581 " floatOutput = vec4(0, 0, 0, 1);\n"
3582 " uintOutput = uvec4(0, 0, 0, 1);\n"
3583 " intOutput = ivec4(0, 0, 0, 1);\n"
3584 "}\n";
3585
3586 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3587 glUseProgram(program.get());
3588
3589 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
3590 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
3591 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
3592
3593 GLFramebuffer fbo;
3594 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3595
3596 GLRenderbuffer floatRenderbuffer;
3597 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
3598 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
3599 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3600 floatRenderbuffer);
3601
3602 GLRenderbuffer uintRenderbuffer;
3603 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
3604 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
3605 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3606 uintRenderbuffer);
3607
3608 GLRenderbuffer intRenderbuffer;
3609 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
3610 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
3611 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3612 intRenderbuffer);
3613
3614 ASSERT_GL_NO_ERROR();
3615
3616 GLint maxDrawBuffers = 0;
3617 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3618 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
3619 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
3620 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
3621 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
3622
3623 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
3624
3625 // Check that the correct case generates no errors
3626 glDrawArrays(GL_TRIANGLES, 0, 6);
3627 EXPECT_GL_NO_ERROR();
3628
3629 // Unbind some buffers and verify that there are still no errors
3630 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3631 0);
3632 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3633 0);
3634 glDrawArrays(GL_TRIANGLES, 0, 6);
3635 EXPECT_GL_NO_ERROR();
3636
3637 // Swap the int and uint buffers to and verify that an error is generated
3638 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3639 intRenderbuffer);
3640 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3641 uintRenderbuffer);
3642 glDrawArrays(GL_TRIANGLES, 0, 6);
3643 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3644
3645 // Swap the float and uint buffers to and verify that an error is generated
3646 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3647 floatRenderbuffer);
3648 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3649 uintRenderbuffer);
3650 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3651 intRenderbuffer);
3652 glDrawArrays(GL_TRIANGLES, 0, 6);
3653 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3654}
3655
Geoff Lang9ab5b822017-05-30 16:19:23 -04003656// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
3657// types
Corentin Wallezc3bc9842017-10-11 15:15:59 -04003658TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch)
Geoff Lang9ab5b822017-05-30 16:19:23 -04003659{
3660 const std::string vertexShader =
3661 "#version 300 es\n"
3662 "in vec4 floatInput;\n"
3663 "in uvec4 uintInput;\n"
3664 "in ivec4 intInput;\n"
3665 "void main() {\n"
3666 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
3667 "}\n";
3668
3669 const std::string fragmentShader =
3670 "#version 300 es\n"
3671 "precision mediump float;\n"
3672 "out vec4 outputColor;\n"
3673 "void main() {\n"
3674 " outputColor = vec4(0, 0, 0, 1);"
3675 "}\n";
3676
3677 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3678 glUseProgram(program.get());
3679
3680 GLint floatLocation = glGetAttribLocation(program, "floatInput");
3681 GLint uintLocation = glGetAttribLocation(program, "uintInput");
3682 GLint intLocation = glGetAttribLocation(program, "intInput");
3683
3684 // Default attributes are of float types
3685 glDrawArrays(GL_TRIANGLES, 0, 6);
3686 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3687
3688 // Set the default attributes to the correct types, should succeed
3689 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
3690 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
3691 glDrawArrays(GL_TRIANGLES, 0, 6);
3692 EXPECT_GL_NO_ERROR();
3693
3694 // Change the default float attribute to an integer, should fail
3695 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
3696 glDrawArrays(GL_TRIANGLES, 0, 6);
3697 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3698
3699 // Use a buffer for some attributes
3700 GLBuffer buffer;
3701 glBindBuffer(GL_ARRAY_BUFFER, buffer);
3702 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
3703 glEnableVertexAttribArray(floatLocation);
3704 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3705 glDrawArrays(GL_TRIANGLES, 0, 6);
3706 EXPECT_GL_NO_ERROR();
3707
3708 // Use a float pointer attrib for a uint input
3709 glEnableVertexAttribArray(uintLocation);
3710 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3711 glDrawArrays(GL_TRIANGLES, 0, 6);
3712 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3713
3714 // Use a uint pointer for the uint input
3715 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
3716 glDrawArrays(GL_TRIANGLES, 0, 6);
3717 EXPECT_GL_NO_ERROR();
3718}
3719
Geoff Langfa125c92017-10-24 13:01:46 -04003720// Test that it's not possible to query the non-zero color attachments without the drawbuffers
3721// extension in WebGL1
3722TEST_P(WebGLCompatibilityTest, FramebufferAttachmentQuery)
3723{
3724 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3725 ANGLE_SKIP_TEST_IF(extensionEnabled("GL_EXT_draw_buffers"));
3726
3727 GLFramebuffer fbo;
3728 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3729 EXPECT_GL_NO_ERROR();
3730
3731 GLint result;
3732 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
3733 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &result);
3734 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3735
3736 GLRenderbuffer renderbuffer;
3737 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
3738 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
3739 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderbuffer);
3740 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3741}
3742
Corentin Walleze7557742017-06-01 13:09:57 -04003743// Tests the WebGL removal of undefined behavior when attachments aren't written to.
3744TEST_P(WebGLCompatibilityTest, DrawBuffers)
3745{
Corentin Walleze7557742017-06-01 13:09:57 -04003746 // Make sure we can use at least 4 attachments for the tests.
3747 bool useEXT = false;
3748 if (getClientMajorVersion() < 3)
3749 {
Yunchao He9550c602018-02-13 14:47:05 +08003750 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_EXT_draw_buffers"));
Corentin Walleze7557742017-06-01 13:09:57 -04003751
3752 glRequestExtensionANGLE("GL_EXT_draw_buffers");
3753 useEXT = true;
3754 EXPECT_GL_NO_ERROR();
3755 }
3756
3757 GLint maxDrawBuffers = 0;
3758 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
Yunchao He9550c602018-02-13 14:47:05 +08003759 // Test skipped because MAX_DRAW_BUFFERS is too small.
3760 ANGLE_SKIP_TEST_IF(maxDrawBuffers < 4);
Corentin Walleze7557742017-06-01 13:09:57 -04003761
3762 // Clears all the renderbuffers to red.
3763 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
3764 GLFramebuffer clearFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003765 glBindFramebuffer(GL_FRAMEBUFFER, clearFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003766
3767 glClearColor(1, 0, 0, 1);
3768 for (int i = 0; i < 4; ++i)
3769 {
Geoff Lange8afa902017-09-27 15:00:43 -04003770 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003771 renderbuffers[i]);
3772 glClear(GL_COLOR_BUFFER_BIT);
3773 }
3774 ASSERT_GL_NO_ERROR();
3775 };
3776
3777 // Checks that the renderbuffers specified by mask have the correct color
3778 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
3779 GLFramebuffer readFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003780 glBindFramebuffer(GL_FRAMEBUFFER, readFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003781
3782 for (int i = 0; i < 4; ++i)
3783 {
3784 if (mask & (1 << i))
3785 {
Geoff Lange8afa902017-09-27 15:00:43 -04003786 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3787 renderbuffers[i]);
Corentin Walleze7557742017-06-01 13:09:57 -04003788 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
3789 }
3790 }
3791 ASSERT_GL_NO_ERROR();
3792 };
3793
3794 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
3795 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
3796 if (useEXT)
3797 {
3798 glDrawBuffersEXT(numBuffers, buffers);
3799 }
3800 else
3801 {
3802 glDrawBuffers(numBuffers, buffers);
3803 }
3804 };
3805
3806 // Initialized the test framebuffer
3807 GLFramebuffer drawFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003808 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003809
3810 GLRenderbuffer renderbuffers[4];
3811 for (int i = 0; i < 4; ++i)
3812 {
3813 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
Geoff Langd84a00b2017-10-27 17:27:26 -04003814 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
Geoff Lange8afa902017-09-27 15:00:43 -04003815 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003816 renderbuffers[i]);
3817 }
3818
3819 ASSERT_GL_NO_ERROR();
3820
Corentin Walleze7557742017-06-01 13:09:57 -04003821 GLenum allDrawBuffers[] = {
3822 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3823 };
3824
3825 GLenum halfDrawBuffers[] = {
3826 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3827 };
3828
3829 // Test that when using gl_FragColor, only the first attachment is written to.
3830 const char *fragESSL1 =
3831 "precision highp float;\n"
3832 "void main()\n"
3833 "{\n"
3834 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3835 "}\n";
Olli Etuaho5804dc82018-04-13 14:11:46 +03003836 ANGLE_GL_PROGRAM(programESSL1, essl1_shaders::vs::Simple(), fragESSL1);
Corentin Walleze7557742017-06-01 13:09:57 -04003837
3838 {
3839 ClearEverythingToRed(renderbuffers);
3840
Geoff Lange8afa902017-09-27 15:00:43 -04003841 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003842 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003843 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003844 ASSERT_GL_NO_ERROR();
3845
3846 CheckColors(renderbuffers, 0b0001, GLColor::green);
3847 CheckColors(renderbuffers, 0b1110, GLColor::red);
3848 }
3849
3850 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
3851 // written to.
3852 {
3853 ClearEverythingToRed(renderbuffers);
3854
Geoff Lange8afa902017-09-27 15:00:43 -04003855 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003856 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003857 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003858 ASSERT_GL_NO_ERROR();
3859
3860 CheckColors(renderbuffers, 0b1111, GLColor::red);
3861 }
3862
3863 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
3864 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
3865 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
3866 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
3867 // attachments not declared in the shader should not be written to.
Olli Etuaho5804dc82018-04-13 14:11:46 +03003868 const char *positionAttrib;
Corentin Walleze7557742017-06-01 13:09:57 -04003869 const char *writeOddOutputsVert;
3870 const char *writeOddOutputsFrag;
3871 GLColor unwrittenColor;
3872 if (useEXT)
3873 {
3874 // In the extension, when an attachment isn't written to, it should get 0's
3875 unwrittenColor = GLColor(0, 0, 0, 0);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003876 positionAttrib = essl1_shaders::PositionAttrib();
3877 writeOddOutputsVert = essl1_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003878 writeOddOutputsFrag =
3879 "#extension GL_EXT_draw_buffers : require\n"
3880 "precision highp float;\n"
3881 "void main()\n"
3882 "{\n"
3883 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3884 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3885 "}\n";
3886 }
3887 else
3888 {
3889 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
3890 // because of the preceding clears.
3891 unwrittenColor = GLColor::red;
Olli Etuaho5804dc82018-04-13 14:11:46 +03003892 positionAttrib = essl3_shaders::PositionAttrib();
3893 writeOddOutputsVert = essl3_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003894 writeOddOutputsFrag =
3895 "#version 300 es\n"
3896 "precision highp float;\n"
3897 "layout(location = 1) out vec4 output1;"
3898 "layout(location = 3) out vec4 output2;"
3899 "void main()\n"
3900 "{\n"
3901 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3902 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3903 "}\n";
3904 }
3905 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
3906
3907 // Test that attachments not written to get the "unwritten" color
3908 {
3909 ClearEverythingToRed(renderbuffers);
3910
Geoff Lange8afa902017-09-27 15:00:43 -04003911 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003912 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003913 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003914 ASSERT_GL_NO_ERROR();
3915
3916 CheckColors(renderbuffers, 0b1010, GLColor::green);
3917 CheckColors(renderbuffers, 0b0101, unwrittenColor);
3918 }
3919
3920 // Test that attachments not written to get the "unwritten" color but that even when the
3921 // extension is used, disabled attachments are not written at all and stay red.
3922 {
3923 ClearEverythingToRed(renderbuffers);
3924
Geoff Lange8afa902017-09-27 15:00:43 -04003925 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003926 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003927 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003928 ASSERT_GL_NO_ERROR();
3929
3930 CheckColors(renderbuffers, 0b1000, GLColor::green);
3931 CheckColors(renderbuffers, 0b0100, unwrittenColor);
3932 CheckColors(renderbuffers, 0b0011, GLColor::red);
3933 }
3934}
3935
Geoff Lang536eca12017-09-13 11:23:35 -04003936// Test that it's possible to generate mipmaps on unsized floating point textures once the
3937// extensions have been enabled
3938TEST_P(WebGLCompatibilityTest, GenerateMipmapUnsizedFloatingPointTexture)
3939{
3940 if (extensionRequestable("GL_OES_texture_float"))
3941 {
3942 glRequestExtensionANGLE("GL_OES_texture_float");
3943 }
3944 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3945
3946 GLTexture texture;
3947 glBindTexture(GL_TEXTURE_2D, texture);
3948
3949 constexpr GLColor32F data[4] = {
3950 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3951 };
3952 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_FLOAT, data);
3953 ASSERT_GL_NO_ERROR();
3954
3955 glGenerateMipmap(GL_TEXTURE_2D);
3956 EXPECT_GL_NO_ERROR();
3957}
3958// Test that it's possible to generate mipmaps on unsized floating point textures once the
3959// extensions have been enabled
3960TEST_P(WebGLCompatibilityTest, GenerateMipmapSizedFloatingPointTexture)
3961{
3962 if (extensionRequestable("GL_OES_texture_float"))
3963 {
3964 glRequestExtensionANGLE("GL_OES_texture_float");
3965 }
3966 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3967
3968 if (extensionRequestable("GL_EXT_texture_storage"))
3969 {
3970 glRequestExtensionANGLE("GL_EXT_texture_storage");
3971 }
3972 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage"));
3973
3974 GLTexture texture;
3975 glBindTexture(GL_TEXTURE_2D, texture);
3976
3977 constexpr GLColor32F data[4] = {
3978 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3979 };
3980 glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA32F, 2, 2);
3981 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_FLOAT, data);
3982 ASSERT_GL_NO_ERROR();
3983
3984 glGenerateMipmap(GL_TEXTURE_2D);
3985 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3986
3987 if (extensionRequestable("GL_EXT_color_buffer_float"))
3988 {
3989 // Format is renderable but not filterable
3990 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3991 glGenerateMipmap(GL_TEXTURE_2D);
3992 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3993 }
3994
3995 if (extensionRequestable("GL_EXT_color_buffer_float_linear"))
3996 {
3997 // Format is renderable but not filterable
3998 glRequestExtensionANGLE("GL_EXT_color_buffer_float_linear");
3999
4000 if (extensionEnabled("GL_EXT_color_buffer_float"))
4001 {
4002 // Format is filterable and renderable
4003 glGenerateMipmap(GL_TEXTURE_2D);
4004 EXPECT_GL_NO_ERROR();
4005 }
4006 else
4007 {
4008 // Format is filterable but not renderable
4009 glGenerateMipmap(GL_TEXTURE_2D);
4010 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4011 }
4012 }
4013}
4014
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07004015// Verify that a texture format is only allowed with extension enabled.
4016void WebGLCompatibilityTest::validateTexImageExtensionFormat(GLenum format,
4017 const std::string &extName)
4018{
4019 // Verify texture format fails by default.
4020 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
4021 EXPECT_GL_ERROR(GL_INVALID_ENUM);
4022
4023 if (extensionRequestable(extName))
4024 {
4025 // Verify texture format is allowed once extension is enabled.
4026 glRequestExtensionANGLE(extName.c_str());
4027 EXPECT_TRUE(extensionEnabled(extName));
4028
4029 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
4030 ASSERT_GL_NO_ERROR();
4031 }
4032}
4033
Geoff Lang86f81162017-10-30 15:10:45 -04004034// Test enabling various non-compressed texture format extensions
4035TEST_P(WebGLCompatibilityTest, EnableTextureFormatExtensions)
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07004036{
Geoff Lang2c5c41f2017-10-31 10:58:09 -04004037 ANGLE_SKIP_TEST_IF(IsOzone());
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07004038 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
4039
4040 GLTexture texture;
4041 glBindTexture(GL_TEXTURE_2D, texture.get());
4042
4043 // Verify valid format is allowed.
4044 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4045 ASSERT_GL_NO_ERROR();
4046
4047 // Verify invalid format fails.
4048 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA32F, GL_UNSIGNED_BYTE, nullptr);
4049 EXPECT_GL_ERROR(GL_INVALID_ENUM);
4050
4051 // Verify formats from enableable extensions.
Geoff Lang660b28c2017-10-30 12:58:56 -04004052 if (!IsOpenGLES())
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07004053 {
4054 validateTexImageExtensionFormat(GL_RED_EXT, "GL_EXT_texture_rg");
4055 }
4056
4057 validateTexImageExtensionFormat(GL_SRGB_EXT, "GL_EXT_texture_sRGB");
4058 validateTexImageExtensionFormat(GL_BGRA_EXT, "GL_EXT_texture_format_BGRA8888");
4059}
4060
Geoff Lang86f81162017-10-30 15:10:45 -04004061void WebGLCompatibilityTest::validateCompressedTexImageExtensionFormat(GLenum format,
4062 GLsizei width,
4063 GLsizei height,
4064 GLsizei blockSize,
4065 const std::string &extName,
4066 bool subImageAllowed)
4067{
4068 std::vector<GLubyte> data(blockSize, 0u);
4069
4070 GLTexture texture;
4071 glBindTexture(GL_TEXTURE_2D, texture.get());
4072
4073 // Verify texture format fails by default.
4074 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
4075 EXPECT_GL_ERROR(GL_INVALID_ENUM);
4076
4077 if (extensionRequestable(extName))
4078 {
4079 // Verify texture format is allowed once extension is enabled.
4080 glRequestExtensionANGLE(extName.c_str());
4081 EXPECT_TRUE(extensionEnabled(extName));
4082
4083 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
4084 EXPECT_GL_NO_ERROR();
4085
4086 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, blockSize,
4087 data.data());
4088 if (subImageAllowed)
4089 {
4090 EXPECT_GL_NO_ERROR();
4091 }
4092 else
4093 {
4094 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4095 }
4096 }
4097}
4098
4099// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGB_S3TC_DXT1_EXT
4100TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGB)
4101{
4102 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 8,
4103 "GL_EXT_texture_compression_dxt1", true);
4104}
4105
4106// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
4107TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGBA)
4108{
4109 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 8,
4110 "GL_EXT_texture_compression_dxt1", true);
4111}
4112
4113// Test enabling GL_ANGLE_texture_compression_dxt3
4114TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3)
4115{
4116 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 16,
4117 "GL_ANGLE_texture_compression_dxt3", true);
4118}
4119
4120// Test enabling GL_ANGLE_texture_compression_dxt5
4121TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5)
4122{
4123 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 16,
4124 "GL_ANGLE_texture_compression_dxt5", true);
4125}
4126
4127// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
4128TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGB)
4129{
4130 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 8,
4131 "GL_EXT_texture_compression_s3tc_srgb", true);
4132}
4133
4134// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
4135TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGBA)
4136{
4137 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 8,
4138 "GL_EXT_texture_compression_s3tc_srgb", true);
4139}
4140
4141// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
4142TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3SRGBA)
4143{
4144 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 16,
4145 "GL_EXT_texture_compression_s3tc_srgb", true);
4146}
4147
4148// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
4149TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5SRGBA)
4150{
4151 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 16,
4152 "GL_EXT_texture_compression_s3tc_srgb", true);
4153}
4154
4155// Test enabling GL_OES_compressed_ETC1_RGB8_texture
4156TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionETC1)
4157{
4158 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_OES, 4, 4, 8,
4159 "GL_OES_compressed_ETC1_RGB8_texture", false);
4160}
4161
4162// Test enabling GL_ANGLE_lossy_etc_decode
4163TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionLossyDecode)
4164{
4165 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 8,
4166 "GL_ANGLE_lossy_etc_decode", true);
4167}
4168
Frank Henigmanfccbac22017-05-28 17:29:26 -04004169// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
4170// qualifiers.
4171TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
4172{
4173 const std::string vertexShader =
4174 "#version 300 es\n"
4175 "uniform Block { mediump vec4 val; };\n"
4176 "void main() { gl_Position = val; }\n";
4177 const std::string fragmentShader =
4178 "#version 300 es\n"
4179 "uniform Block { highp vec4 val; };\n"
4180 "out highp vec4 out_FragColor;\n"
4181 "void main() { out_FragColor = val; }\n";
4182
4183 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
4184 ASSERT_NE(0u, vs);
4185 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
4186 ASSERT_NE(0u, fs);
4187
4188 GLuint program = glCreateProgram();
4189
4190 glAttachShader(program, vs);
4191 glDeleteShader(vs);
4192 glAttachShader(program, fs);
4193 glDeleteShader(fs);
4194
4195 glLinkProgram(program);
4196 GLint linkStatus;
4197 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
4198 ASSERT_EQ(0, linkStatus);
4199
4200 glDeleteProgram(program);
4201}
4202
Geoff Lang69df2422017-07-05 12:42:31 -04004203// Test no attribute vertex shaders
4204TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
4205{
4206 const std::string vertexShader =
4207 "#version 300 es\n"
4208 "void main()\n"
4209 "{\n"
4210 "\n"
4211 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
4212 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
4213 "}";
Geoff Lang69df2422017-07-05 12:42:31 -04004214
Olli Etuaho5804dc82018-04-13 14:11:46 +03004215 ANGLE_GL_PROGRAM(program, vertexShader, essl3_shaders::fs::Red());
Geoff Lang69df2422017-07-05 12:42:31 -04004216 glUseProgram(program);
4217
4218 glDrawArrays(GL_TRIANGLES, 0, 6);
4219 ASSERT_GL_NO_ERROR();
Olli Etuaho5804dc82018-04-13 14:11:46 +03004220 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Geoff Lang69df2422017-07-05 12:42:31 -04004221}
4222
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004223// Tests bindAttribLocations for length limit
4224TEST_P(WebGL2CompatibilityTest, BindAttribLocationLimitation)
4225{
4226 constexpr int maxLocStringLength = 1024;
4227 const std::string tooLongString(maxLocStringLength + 1, '_');
4228
4229 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
4230
4231 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4232}
4233
Jamie Madill629bb252018-04-20 11:01:33 -04004234// Covers a bug in transform feedback loop detection.
4235TEST_P(WebGL2CompatibilityTest, TransformFeedbackCheckNullDeref)
4236{
4237 constexpr char kVS[] = R"(attribute vec4 color; void main() { color.r; })";
4238 constexpr char kFS[] = R"(void main(){})";
4239 ANGLE_GL_PROGRAM(program, kVS, kFS);
4240 glUseProgram(program);
4241
Jamie Madill629bb252018-04-20 11:01:33 -04004242 glEnableVertexAttribArray(0);
4243 glDrawArrays(GL_POINTS, 0, 1);
4244
Jamie Madilldc358af2018-07-31 11:22:13 -04004245 // This should fail because it is trying to pull a vertex with no buffer.
4246 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4247
4248 GLBuffer buffer;
4249 glBindBuffer(GL_ARRAY_BUFFER, buffer);
4250 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
4251
4252 // This should fail because it is trying to pull a vertex from an empty buffer.
4253 glDrawArrays(GL_POINTS, 0, 1);
Jamie Madill629bb252018-04-20 11:01:33 -04004254 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4255}
4256
Bryan Bernhart22f7aaf2018-08-23 14:13:51 -07004257// Check the return type of a given parameter upon getting the active uniforms.
4258TEST_P(WebGL2CompatibilityTest, UniformVariablesReturnTypes)
4259{
4260 ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
4261
4262 std::vector<GLuint> validUniformIndices = {0};
4263 std::vector<GLint> uniformNameLengthBuf(validUniformIndices.size());
4264
4265 // This should fail because GL_UNIFORM_NAME_LENGTH cannot be used in WebGL2.
4266 glGetActiveUniformsiv(program, static_cast<GLsizei>(validUniformIndices.size()),
4267 &validUniformIndices[0], GL_UNIFORM_NAME_LENGTH,
4268 &uniformNameLengthBuf[0]);
4269 EXPECT_GL_ERROR(GL_INVALID_ENUM);
4270}
4271
Geoff Langc287ea62016-09-16 14:46:51 -04004272// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4273// tests should be run against.
4274ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
4275 ES2_D3D9(),
4276 ES2_D3D11(),
4277 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04004278 ES2_OPENGL(),
4279 ES3_OPENGL(),
4280 ES2_OPENGLES(),
4281 ES3_OPENGLES());
4282
Jamie Madill07be8bf2017-02-02 19:59:57 -05004283ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04004284} // namespace