blob: a7779e315e0eb399b598be48f936a7a832d126e9 [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");
2769 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2770 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
2771 }
2772
2773 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2774 {
2775 // Sized RGBA 32F
2776 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");
2803 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2804 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2805 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
2806 }
2807
2808 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2809 {
2810 // Sized RGBA 32F
2811 bool texture =
2812 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2813 extensionEnabled("GL_EXT_texture_storage"));
2814 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2815 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2816 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2817 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
2818 data);
2819 }
2820 }
2821}
2822
2823TEST_P(WebGLCompatibilityTest, R16FTextures)
2824{
2825 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
2826 const GLushort textureData[] = {
2827 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2828 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2829
2830 for (auto extension : FloatingPointTextureExtensions)
2831 {
2832 if (strlen(extension) > 0 && extensionRequestable(extension))
2833 {
2834 glRequestExtensionANGLE(extension);
2835 ASSERT_GL_NO_ERROR();
2836 }
2837
2838 // Unsized R 16F (OES)
2839 {
2840 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2841 extensionEnabled("GL_EXT_texture_rg");
2842 bool filter = getClientMajorVersion() >= 3 ||
2843 extensionEnabled("GL_OES_texture_half_float_linear");
2844 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2845 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2846 textureData, readPixelsData);
2847 }
2848
2849 // Unsized R 16F
2850 {
2851 bool texture = false;
2852 bool filter = false;
2853 bool render = false;
2854 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2855 textureData, readPixelsData);
2856 }
2857
2858 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2859 {
2860 // Sized R 16F
2861 bool texture = getClientMajorVersion() >= 3;
2862 bool filter = getClientMajorVersion() >= 3 ||
2863 extensionEnabled("GL_OES_texture_half_float_linear");
2864 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2865 extensionEnabled("GL_EXT_color_buffer_float");
2866 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2867 textureData, readPixelsData);
2868 }
2869 }
2870}
2871
2872TEST_P(WebGLCompatibilityTest, RG16FTextures)
2873{
2874 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
2875 const GLushort textureData[] = {
2876 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2877 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2878
2879 for (auto extension : FloatingPointTextureExtensions)
2880 {
2881 if (strlen(extension) > 0 && extensionRequestable(extension))
2882 {
2883 glRequestExtensionANGLE(extension);
2884 ASSERT_GL_NO_ERROR();
2885 }
2886
2887 // Unsized RG 16F (OES)
2888 {
2889 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2890 extensionEnabled("GL_EXT_texture_rg");
2891 bool filter = getClientMajorVersion() >= 3 ||
2892 extensionEnabled("GL_OES_texture_half_float_linear");
2893 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
2894 extensionEnabled("GL_EXT_texture_rg");
2895 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2896 textureData, readPixelsData);
2897 }
2898
2899 // Unsized RG 16F
2900 {
2901 bool texture = false;
2902 bool filter = false;
2903 bool render = false;
2904 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2905 textureData, readPixelsData);
2906 }
2907
2908 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2909 {
2910 // Sized RG 16F
2911 bool texture = getClientMajorVersion() >= 3;
2912 bool filter = getClientMajorVersion() >= 3 ||
2913 extensionEnabled("GL_OES_texture_half_float_linear");
2914 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2915 extensionEnabled("GL_EXT_color_buffer_float");
2916 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2917 textureData, readPixelsData);
2918 }
2919 }
2920}
2921
2922TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2923{
Yunchao He9550c602018-02-13 14:47:05 +08002924 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002925
Geoff Lang677bb6f2017-04-05 12:40:40 -04002926 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2927 const GLushort textureData[] = {
2928 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2929 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2930
2931 for (auto extension : FloatingPointTextureExtensions)
2932 {
2933 if (strlen(extension) > 0 && extensionRequestable(extension))
2934 {
2935 glRequestExtensionANGLE(extension);
2936 ASSERT_GL_NO_ERROR();
2937 }
2938
2939 // Unsized RGB 16F (OES)
2940 {
2941 bool texture = extensionEnabled("GL_OES_texture_half_float");
2942 bool filter = getClientMajorVersion() >= 3 ||
2943 extensionEnabled("GL_OES_texture_half_float_linear");
2944 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2945 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2946 textureData, readPixelsData);
2947 }
2948
2949 // Unsized RGB 16F
2950 {
2951 bool texture = false;
2952 bool filter = false;
2953 bool render = false;
2954 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2955 textureData, readPixelsData);
2956 }
2957
2958 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2959 {
2960 // Sized RGB 16F
2961 bool texture = getClientMajorVersion() >= 3;
2962 bool filter = getClientMajorVersion() >= 3 ||
2963 extensionEnabled("GL_OES_texture_half_float_linear");
2964 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2965 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2966 textureData, readPixelsData);
2967 }
2968 }
2969}
2970
2971TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2972{
Yunchao He9550c602018-02-13 14:47:05 +08002973 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002974
Geoff Lang677bb6f2017-04-05 12:40:40 -04002975 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2976 const GLushort textureData[] = {
2977 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2978 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2979
2980 for (auto extension : FloatingPointTextureExtensions)
2981 {
2982 if (strlen(extension) > 0 && extensionRequestable(extension))
2983 {
2984 glRequestExtensionANGLE(extension);
2985 ASSERT_GL_NO_ERROR();
2986 }
2987
2988 // Unsized RGBA 16F (OES)
2989 {
2990 bool texture = extensionEnabled("GL_OES_texture_half_float");
2991 bool filter = getClientMajorVersion() >= 3 ||
2992 extensionEnabled("GL_OES_texture_half_float_linear");
2993 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2994 extensionEnabled("GL_EXT_color_buffer_float");
2995 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2996 textureData, readPixelsData);
2997 }
2998
2999 // Unsized RGBA 16F
3000 {
3001 bool texture = false;
3002 bool filter = false;
3003 bool render = false;
3004 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
3005 textureData, readPixelsData);
3006 }
3007
3008 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
3009 {
3010 // Sized RGBA 16F
3011 bool texture = getClientMajorVersion() >= 3;
3012 bool filter = getClientMajorVersion() >= 3 ||
3013 extensionEnabled("GL_OES_texture_half_float_linear");
3014 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
3015 extensionEnabled("GL_EXT_color_buffer_float");
3016 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
3017 textureData, readPixelsData);
3018 }
3019 }
3020}
3021
Geoff Lang6e898aa2017-06-02 11:17:26 -04003022// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
3023// accepted by glTexImage2D
3024TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
3025{
Yunchao He9550c602018-02-13 14:47:05 +08003026 // Test skipped because it is only valid for WebGL1 contexts.
3027 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
Geoff Lang6e898aa2017-06-02 11:17:26 -04003028
Yunchao He9550c602018-02-13 14:47:05 +08003029 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_OES_texture_float"));
3030
Geoff Lang6e898aa2017-06-02 11:17:26 -04003031 glRequestExtensionANGLE("GL_OES_texture_float");
3032 ASSERT_GL_NO_ERROR();
3033
3034 GLTexture texture;
3035 glBindTexture(GL_TEXTURE_2D, texture);
3036
3037 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3038 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3039
3040 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
3041 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3042
3043 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
3044 {
3045 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
3046 ASSERT_GL_NO_ERROR();
3047
3048 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3049 EXPECT_GL_NO_ERROR();
3050 }
3051
3052 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
3053 {
3054 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
3055 ASSERT_GL_NO_ERROR();
3056
3057 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
3058 EXPECT_GL_NO_ERROR();
3059 }
3060}
3061
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003062// Verify GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point.
3063TEST_P(WebGLCompatibilityTest, DepthStencilAttachment)
3064{
3065 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3066
3067 // Test that attaching a bound texture succeeds.
3068 GLTexture texture;
3069 glBindTexture(GL_TEXTURE_2D, texture);
3070
3071 GLFramebuffer fbo;
3072 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3073
3074 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture, 0);
3075
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003076 GLint attachmentType = 0;
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003077 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003078 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003079 EXPECT_GL_NO_ERROR();
3080 EXPECT_GLENUM_EQ(GL_TEXTURE, attachmentType);
3081
3082 // Test when if no attach object at the named attachment point and pname is not OBJECT_TYPE.
3083 GLFramebuffer fbo2;
3084 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
3085
3086 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003087 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003088 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3089}
3090
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003091// Verify framebuffer attachments return expected types when in an inconsistant state.
3092TEST_P(WebGLCompatibilityTest, FramebufferAttachmentConsistancy)
3093{
3094 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3095
3096 GLFramebuffer fbo;
3097 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3098
3099 GLRenderbuffer rb1;
3100 glBindRenderbuffer(GL_RENDERBUFFER, rb1);
3101
3102 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb1);
3103
3104 GLint attachmentType = 0;
3105 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3106 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3107
3108 EXPECT_GL_NO_ERROR();
3109 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3110
3111 GLRenderbuffer rb2;
3112 glBindRenderbuffer(GL_RENDERBUFFER, rb2);
3113
3114 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3115
3116 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
3117 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3118
3119 EXPECT_GL_NO_ERROR();
3120 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)5f198102017-12-12 14:21:39 -08003121
3122 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb2);
3123
3124 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3125 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3126
3127 EXPECT_GL_NO_ERROR();
3128 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3129
3130 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3131
3132 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3133 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3134
3135 EXPECT_GL_NO_ERROR();
3136 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003137}
3138
Jamie Madill07be8bf2017-02-02 19:59:57 -05003139// This tests that rendering feedback loops works as expected with WebGL 2.
3140// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
3141TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
3142{
3143 const std::string vertexShader =
3144 "#version 300 es\n"
3145 "in vec4 aPosition;\n"
3146 "out vec2 texCoord;\n"
3147 "void main() {\n"
3148 " gl_Position = aPosition;\n"
3149 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3150 "}\n";
3151
3152 const std::string fragmentShader =
3153 "#version 300 es\n"
3154 "precision mediump float;\n"
3155 "uniform sampler2D tex;\n"
3156 "in vec2 texCoord;\n"
3157 "out vec4 oColor;\n"
3158 "void main() {\n"
3159 " oColor = texture(tex, texCoord);\n"
3160 "}\n";
3161
3162 GLsizei width = 8;
3163 GLsizei height = 8;
3164
3165 GLint maxDrawBuffers = 0;
3166 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3167 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
3168 ASSERT_GE(maxDrawBuffers, 2);
3169
3170 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3171 glUseProgram(program.get());
3172 glViewport(0, 0, width, height);
3173
3174 GLTexture tex0;
3175 GLTexture tex1;
3176 GLFramebuffer fbo;
3177 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3178 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3179 ASSERT_GL_NO_ERROR();
3180
3181 glBindTexture(GL_TEXTURE_2D, tex1.get());
3182 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3183 ASSERT_NE(-1, texLoc);
3184 glUniform1i(texLoc, 0);
3185
3186 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
3187 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3188 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3189 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
3190 ASSERT_GL_NO_ERROR();
3191
3192 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
3193 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
3194 GL_INVALID_OPERATION);
3195 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
3196}
3197
Jamie Madill1d37bc52017-02-02 19:59:58 -05003198// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
3199// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
3200TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
3201{
3202 const std::string vertexShader =
3203 "#version 300 es\n"
3204 "in vec4 aPosition;\n"
3205 "out vec2 texCoord;\n"
3206 "void main() {\n"
3207 " gl_Position = aPosition;\n"
3208 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3209 "}\n";
3210
3211 const std::string fragmentShader =
3212 "#version 300 es\n"
3213 "precision mediump float;\n"
3214 "uniform sampler2D tex;\n"
3215 "in vec2 texCoord;\n"
3216 "out vec4 oColor;\n"
3217 "void main() {\n"
3218 " oColor = texture(tex, texCoord);\n"
3219 "}\n";
3220
3221 GLsizei width = 8;
3222 GLsizei height = 8;
3223
3224 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3225 glUseProgram(program.get());
3226
3227 glViewport(0, 0, width, height);
3228
3229 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3230 glUniform1i(texLoc, 0);
3231
3232 // Create textures and allocate storage
3233 GLTexture tex0;
3234 GLTexture tex1;
3235 GLRenderbuffer rb;
3236 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3237 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
3238 GL_UNSIGNED_INT);
3239 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
3240 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
3241 ASSERT_GL_NO_ERROR();
3242
3243 GLFramebuffer fbo;
3244 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3245 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3246
3247 // Test rendering and sampling feedback loop for depth buffer
3248 glBindTexture(GL_TEXTURE_2D, tex1.get());
3249 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
3250 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3251
3252 // The same image is used as depth buffer during rendering.
3253 glEnable(GL_DEPTH_TEST);
3254 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3255 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3256
3257 // The same image is used as depth buffer. But depth mask is false.
3258 glDepthMask(GL_FALSE);
3259 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3260 EXPECT_GL_NO_ERROR();
3261
3262 // The same image is used as depth buffer. But depth test is not enabled during rendering.
3263 glDepthMask(GL_TRUE);
3264 glDisable(GL_DEPTH_TEST);
3265 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3266 EXPECT_GL_NO_ERROR();
3267
3268 // Test rendering and sampling feedback loop for stencil buffer
3269 glBindTexture(GL_RENDERBUFFER, rb.get());
3270 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
3271 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
3272 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3273 constexpr GLint stencilClearValue = 0x40;
3274 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
3275
3276 // The same image is used as stencil buffer during rendering.
3277 glEnable(GL_STENCIL_TEST);
3278 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3279 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3280
3281 // The same image is used as stencil buffer. But stencil mask is zero.
3282 glStencilMask(0x0);
3283 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3284 EXPECT_GL_NO_ERROR();
3285
3286 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
3287 glStencilMask(0xffff);
3288 glDisable(GL_STENCIL_TEST);
3289 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3290 EXPECT_GL_NO_ERROR();
3291}
3292
Jamie Madillfd3dd432017-02-02 19:59:59 -05003293// The source and the target for CopyTexSubImage3D are the same 3D texture.
3294// But the level of the 3D texture != the level of the read attachment.
3295TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
3296{
3297 GLTexture texture;
3298 GLFramebuffer framebuffer;
3299
3300 glBindTexture(GL_TEXTURE_3D, texture.get());
3301 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3302
3303 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3304 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3305 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
3306 ASSERT_GL_NO_ERROR();
3307
3308 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3309 EXPECT_GL_NO_ERROR();
3310}
3311
3312// The source and the target for CopyTexSubImage3D are the same 3D texture.
3313// But the zoffset of the 3D texture != the layer of the read attachment.
3314TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
3315{
3316 GLTexture texture;
3317 GLFramebuffer framebuffer;
3318
3319 glBindTexture(GL_TEXTURE_3D, texture.get());
3320 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3321
3322 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3323 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
3324 ASSERT_GL_NO_ERROR();
3325
3326 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
3327 EXPECT_GL_NO_ERROR();
3328}
3329
3330// The source and the target for CopyTexSubImage3D are the same 3D texture.
3331// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
3332TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
3333{
3334 GLTexture texture;
3335 GLFramebuffer framebuffer;
3336
3337 glBindTexture(GL_TEXTURE_3D, texture.get());
3338 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3339
3340 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3341 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3342 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3343 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
3344 ASSERT_GL_NO_ERROR();
3345
3346 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3347 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3348}
3349
Corentin Wallez59c41592017-07-11 13:19:54 -04003350// Verify that errors are generated when there isn't a defined conversion between the clear type and
3351// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04003352TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
3353{
Yunchao He9550c602018-02-13 14:47:05 +08003354 // Test skipped for D3D11 because it generates D3D11 runtime warnings.
3355 ANGLE_SKIP_TEST_IF(IsD3D11());
Geoff Lang76e65652017-03-27 14:58:02 -04003356
3357 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3358 constexpr int clearInt[] = {0, 0, 0, 0};
3359 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3360
3361 GLTexture texture;
3362 GLFramebuffer framebuffer;
3363
3364 glBindTexture(GL_TEXTURE_2D, texture.get());
3365 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3366
3367 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
3368 ASSERT_GL_NO_ERROR();
3369
3370 // Unsigned integer buffer
3371 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
3372 ASSERT_GL_NO_ERROR();
3373
3374 glClearBufferfv(GL_COLOR, 0, clearFloat);
3375 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3376
3377 glClearBufferiv(GL_COLOR, 0, clearInt);
3378 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3379
3380 glClearBufferuiv(GL_COLOR, 0, clearUint);
3381 EXPECT_GL_NO_ERROR();
3382
3383 glClear(GL_COLOR_BUFFER_BIT);
3384 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3385
3386 // Integer buffer
3387 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
3388 ASSERT_GL_NO_ERROR();
3389
3390 glClearBufferfv(GL_COLOR, 0, clearFloat);
3391 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3392
3393 glClearBufferiv(GL_COLOR, 0, clearInt);
3394 EXPECT_GL_NO_ERROR();
3395
3396 glClearBufferuiv(GL_COLOR, 0, clearUint);
3397 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3398
3399 glClear(GL_COLOR_BUFFER_BIT);
3400 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3401
3402 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04003403 if (extensionRequestable("GL_EXT_color_buffer_float"))
3404 {
3405 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3406 }
Geoff Lang76e65652017-03-27 14:58:02 -04003407
Geoff Lang677bb6f2017-04-05 12:40:40 -04003408 if (extensionEnabled("GL_EXT_color_buffer_float"))
3409 {
3410 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3411 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003412
Geoff Lang677bb6f2017-04-05 12:40:40 -04003413 glClearBufferfv(GL_COLOR, 0, clearFloat);
3414 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003415
Geoff Lang677bb6f2017-04-05 12:40:40 -04003416 glClearBufferiv(GL_COLOR, 0, clearInt);
3417 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04003418
Geoff Lang677bb6f2017-04-05 12:40:40 -04003419 glClearBufferuiv(GL_COLOR, 0, clearUint);
3420 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3421
3422 glClear(GL_COLOR_BUFFER_BIT);
3423 EXPECT_GL_NO_ERROR();
3424 }
Geoff Lang76e65652017-03-27 14:58:02 -04003425
3426 // Normalized uint buffer
3427 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3428 ASSERT_GL_NO_ERROR();
3429
3430 glClearBufferfv(GL_COLOR, 0, clearFloat);
3431 EXPECT_GL_NO_ERROR();
3432
3433 glClearBufferiv(GL_COLOR, 0, clearInt);
3434 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3435
3436 glClearBufferuiv(GL_COLOR, 0, clearUint);
3437 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3438
3439 glClear(GL_COLOR_BUFFER_BIT);
3440 EXPECT_GL_NO_ERROR();
3441}
3442
Corentin Wallez59c41592017-07-11 13:19:54 -04003443// Test the interaction of WebGL compatibility clears with default framebuffers
3444TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
3445{
3446 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3447 constexpr int clearInt[] = {0, 0, 0, 0};
3448 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3449
3450 // glClear works as usual, this is also a regression test for a bug where we
3451 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
3452 glClear(GL_COLOR_BUFFER_BIT);
3453 EXPECT_GL_NO_ERROR();
3454
3455 // Default framebuffers are normalized uints, so only glClearBufferfv works.
3456 glClearBufferfv(GL_COLOR, 0, clearFloat);
3457 EXPECT_GL_NO_ERROR();
3458
3459 glClearBufferiv(GL_COLOR, 0, clearInt);
3460 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3461
3462 glClearBufferuiv(GL_COLOR, 0, clearUint);
3463 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3464}
3465
Geoff Lange4915782017-04-12 15:19:07 -04003466// Verify that errors are generate when trying to blit from an image to itself
3467TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
3468{
3469 GLTexture textures[2];
3470 glBindTexture(GL_TEXTURE_2D, textures[0]);
3471 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3472 glBindTexture(GL_TEXTURE_2D, textures[1]);
3473 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3474
3475 GLRenderbuffer renderbuffers[2];
3476 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
3477 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3478 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
3479 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3480
3481 GLFramebuffer framebuffers[2];
3482 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
3483 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
3484
3485 ASSERT_GL_NO_ERROR();
3486
3487 // Same texture
3488 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3489 0);
3490 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3491 0);
3492 ASSERT_GL_NO_ERROR();
3493 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3494 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3495
3496 // Same textures but different renderbuffers
3497 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3498 renderbuffers[0]);
3499 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3500 renderbuffers[1]);
3501 ASSERT_GL_NO_ERROR();
3502 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3503 ASSERT_GL_NO_ERROR();
3504 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3505 GL_NEAREST);
3506 ASSERT_GL_NO_ERROR();
3507 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3508 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3509 GL_NEAREST);
3510 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3511
3512 // Same renderbuffers but different textures
3513 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3514 0);
3515 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
3516 0);
3517 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3518 renderbuffers[0]);
3519 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3520 renderbuffers[0]);
3521 ASSERT_GL_NO_ERROR();
3522 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3523 ASSERT_GL_NO_ERROR();
3524 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3525 GL_NEAREST);
3526 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3527 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3528 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3529 GL_NEAREST);
3530 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3531}
3532
Geoff Lange0cff192017-05-30 13:04:56 -04003533// Verify that errors are generated when the fragment shader output doesn't match the bound color
3534// buffer types
3535TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
3536{
3537 const std::string vertexShader =
3538 "#version 300 es\n"
3539 "void main() {\n"
3540 " gl_Position = vec4(0, 0, 0, 1);\n"
3541 "}\n";
3542
3543 const std::string fragmentShader =
3544 "#version 300 es\n"
3545 "precision mediump float;\n"
3546 "layout(location = 0) out vec4 floatOutput;\n"
3547 "layout(location = 1) out uvec4 uintOutput;\n"
3548 "layout(location = 2) out ivec4 intOutput;\n"
3549 "void main() {\n"
3550 " floatOutput = vec4(0, 0, 0, 1);\n"
3551 " uintOutput = uvec4(0, 0, 0, 1);\n"
3552 " intOutput = ivec4(0, 0, 0, 1);\n"
3553 "}\n";
3554
3555 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3556 glUseProgram(program.get());
3557
3558 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
3559 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
3560 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
3561
3562 GLFramebuffer fbo;
3563 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3564
3565 GLRenderbuffer floatRenderbuffer;
3566 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
3567 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
3568 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3569 floatRenderbuffer);
3570
3571 GLRenderbuffer uintRenderbuffer;
3572 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
3573 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
3574 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3575 uintRenderbuffer);
3576
3577 GLRenderbuffer intRenderbuffer;
3578 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
3579 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
3580 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3581 intRenderbuffer);
3582
3583 ASSERT_GL_NO_ERROR();
3584
3585 GLint maxDrawBuffers = 0;
3586 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3587 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
3588 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
3589 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
3590 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
3591
3592 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
3593
3594 // Check that the correct case generates no errors
3595 glDrawArrays(GL_TRIANGLES, 0, 6);
3596 EXPECT_GL_NO_ERROR();
3597
3598 // Unbind some buffers and verify that there are still no errors
3599 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3600 0);
3601 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3602 0);
3603 glDrawArrays(GL_TRIANGLES, 0, 6);
3604 EXPECT_GL_NO_ERROR();
3605
3606 // Swap the int and uint buffers to and verify that an error is generated
3607 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3608 intRenderbuffer);
3609 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3610 uintRenderbuffer);
3611 glDrawArrays(GL_TRIANGLES, 0, 6);
3612 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3613
3614 // Swap the float and uint buffers to and verify that an error is generated
3615 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3616 floatRenderbuffer);
3617 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3618 uintRenderbuffer);
3619 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3620 intRenderbuffer);
3621 glDrawArrays(GL_TRIANGLES, 0, 6);
3622 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3623}
3624
Geoff Lang9ab5b822017-05-30 16:19:23 -04003625// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
3626// types
Corentin Wallezc3bc9842017-10-11 15:15:59 -04003627TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch)
Geoff Lang9ab5b822017-05-30 16:19:23 -04003628{
3629 const std::string vertexShader =
3630 "#version 300 es\n"
3631 "in vec4 floatInput;\n"
3632 "in uvec4 uintInput;\n"
3633 "in ivec4 intInput;\n"
3634 "void main() {\n"
3635 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
3636 "}\n";
3637
3638 const std::string fragmentShader =
3639 "#version 300 es\n"
3640 "precision mediump float;\n"
3641 "out vec4 outputColor;\n"
3642 "void main() {\n"
3643 " outputColor = vec4(0, 0, 0, 1);"
3644 "}\n";
3645
3646 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3647 glUseProgram(program.get());
3648
3649 GLint floatLocation = glGetAttribLocation(program, "floatInput");
3650 GLint uintLocation = glGetAttribLocation(program, "uintInput");
3651 GLint intLocation = glGetAttribLocation(program, "intInput");
3652
3653 // Default attributes are of float types
3654 glDrawArrays(GL_TRIANGLES, 0, 6);
3655 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3656
3657 // Set the default attributes to the correct types, should succeed
3658 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
3659 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
3660 glDrawArrays(GL_TRIANGLES, 0, 6);
3661 EXPECT_GL_NO_ERROR();
3662
3663 // Change the default float attribute to an integer, should fail
3664 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
3665 glDrawArrays(GL_TRIANGLES, 0, 6);
3666 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3667
3668 // Use a buffer for some attributes
3669 GLBuffer buffer;
3670 glBindBuffer(GL_ARRAY_BUFFER, buffer);
3671 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
3672 glEnableVertexAttribArray(floatLocation);
3673 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3674 glDrawArrays(GL_TRIANGLES, 0, 6);
3675 EXPECT_GL_NO_ERROR();
3676
3677 // Use a float pointer attrib for a uint input
3678 glEnableVertexAttribArray(uintLocation);
3679 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3680 glDrawArrays(GL_TRIANGLES, 0, 6);
3681 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3682
3683 // Use a uint pointer for the uint input
3684 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
3685 glDrawArrays(GL_TRIANGLES, 0, 6);
3686 EXPECT_GL_NO_ERROR();
3687}
3688
Geoff Langfa125c92017-10-24 13:01:46 -04003689// Test that it's not possible to query the non-zero color attachments without the drawbuffers
3690// extension in WebGL1
3691TEST_P(WebGLCompatibilityTest, FramebufferAttachmentQuery)
3692{
3693 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3694 ANGLE_SKIP_TEST_IF(extensionEnabled("GL_EXT_draw_buffers"));
3695
3696 GLFramebuffer fbo;
3697 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3698 EXPECT_GL_NO_ERROR();
3699
3700 GLint result;
3701 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
3702 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &result);
3703 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3704
3705 GLRenderbuffer renderbuffer;
3706 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
3707 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
3708 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderbuffer);
3709 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3710}
3711
Corentin Walleze7557742017-06-01 13:09:57 -04003712// Tests the WebGL removal of undefined behavior when attachments aren't written to.
3713TEST_P(WebGLCompatibilityTest, DrawBuffers)
3714{
Corentin Walleze7557742017-06-01 13:09:57 -04003715 // Make sure we can use at least 4 attachments for the tests.
3716 bool useEXT = false;
3717 if (getClientMajorVersion() < 3)
3718 {
Yunchao He9550c602018-02-13 14:47:05 +08003719 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_EXT_draw_buffers"));
Corentin Walleze7557742017-06-01 13:09:57 -04003720
3721 glRequestExtensionANGLE("GL_EXT_draw_buffers");
3722 useEXT = true;
3723 EXPECT_GL_NO_ERROR();
3724 }
3725
3726 GLint maxDrawBuffers = 0;
3727 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
Yunchao He9550c602018-02-13 14:47:05 +08003728 // Test skipped because MAX_DRAW_BUFFERS is too small.
3729 ANGLE_SKIP_TEST_IF(maxDrawBuffers < 4);
Corentin Walleze7557742017-06-01 13:09:57 -04003730
3731 // Clears all the renderbuffers to red.
3732 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
3733 GLFramebuffer clearFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003734 glBindFramebuffer(GL_FRAMEBUFFER, clearFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003735
3736 glClearColor(1, 0, 0, 1);
3737 for (int i = 0; i < 4; ++i)
3738 {
Geoff Lange8afa902017-09-27 15:00:43 -04003739 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003740 renderbuffers[i]);
3741 glClear(GL_COLOR_BUFFER_BIT);
3742 }
3743 ASSERT_GL_NO_ERROR();
3744 };
3745
3746 // Checks that the renderbuffers specified by mask have the correct color
3747 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
3748 GLFramebuffer readFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003749 glBindFramebuffer(GL_FRAMEBUFFER, readFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003750
3751 for (int i = 0; i < 4; ++i)
3752 {
3753 if (mask & (1 << i))
3754 {
Geoff Lange8afa902017-09-27 15:00:43 -04003755 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3756 renderbuffers[i]);
Corentin Walleze7557742017-06-01 13:09:57 -04003757 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
3758 }
3759 }
3760 ASSERT_GL_NO_ERROR();
3761 };
3762
3763 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
3764 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
3765 if (useEXT)
3766 {
3767 glDrawBuffersEXT(numBuffers, buffers);
3768 }
3769 else
3770 {
3771 glDrawBuffers(numBuffers, buffers);
3772 }
3773 };
3774
3775 // Initialized the test framebuffer
3776 GLFramebuffer drawFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003777 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003778
3779 GLRenderbuffer renderbuffers[4];
3780 for (int i = 0; i < 4; ++i)
3781 {
3782 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
Geoff Langd84a00b2017-10-27 17:27:26 -04003783 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
Geoff Lange8afa902017-09-27 15:00:43 -04003784 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003785 renderbuffers[i]);
3786 }
3787
3788 ASSERT_GL_NO_ERROR();
3789
Corentin Walleze7557742017-06-01 13:09:57 -04003790 GLenum allDrawBuffers[] = {
3791 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3792 };
3793
3794 GLenum halfDrawBuffers[] = {
3795 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3796 };
3797
3798 // Test that when using gl_FragColor, only the first attachment is written to.
3799 const char *fragESSL1 =
3800 "precision highp float;\n"
3801 "void main()\n"
3802 "{\n"
3803 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3804 "}\n";
Olli Etuaho5804dc82018-04-13 14:11:46 +03003805 ANGLE_GL_PROGRAM(programESSL1, essl1_shaders::vs::Simple(), fragESSL1);
Corentin Walleze7557742017-06-01 13:09:57 -04003806
3807 {
3808 ClearEverythingToRed(renderbuffers);
3809
Geoff Lange8afa902017-09-27 15:00:43 -04003810 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003811 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003812 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003813 ASSERT_GL_NO_ERROR();
3814
3815 CheckColors(renderbuffers, 0b0001, GLColor::green);
3816 CheckColors(renderbuffers, 0b1110, GLColor::red);
3817 }
3818
3819 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
3820 // written to.
3821 {
3822 ClearEverythingToRed(renderbuffers);
3823
Geoff Lange8afa902017-09-27 15:00:43 -04003824 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003825 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003826 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003827 ASSERT_GL_NO_ERROR();
3828
3829 CheckColors(renderbuffers, 0b1111, GLColor::red);
3830 }
3831
3832 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
3833 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
3834 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
3835 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
3836 // attachments not declared in the shader should not be written to.
Olli Etuaho5804dc82018-04-13 14:11:46 +03003837 const char *positionAttrib;
Corentin Walleze7557742017-06-01 13:09:57 -04003838 const char *writeOddOutputsVert;
3839 const char *writeOddOutputsFrag;
3840 GLColor unwrittenColor;
3841 if (useEXT)
3842 {
3843 // In the extension, when an attachment isn't written to, it should get 0's
3844 unwrittenColor = GLColor(0, 0, 0, 0);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003845 positionAttrib = essl1_shaders::PositionAttrib();
3846 writeOddOutputsVert = essl1_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003847 writeOddOutputsFrag =
3848 "#extension GL_EXT_draw_buffers : require\n"
3849 "precision highp float;\n"
3850 "void main()\n"
3851 "{\n"
3852 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3853 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3854 "}\n";
3855 }
3856 else
3857 {
3858 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
3859 // because of the preceding clears.
3860 unwrittenColor = GLColor::red;
Olli Etuaho5804dc82018-04-13 14:11:46 +03003861 positionAttrib = essl3_shaders::PositionAttrib();
3862 writeOddOutputsVert = essl3_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003863 writeOddOutputsFrag =
3864 "#version 300 es\n"
3865 "precision highp float;\n"
3866 "layout(location = 1) out vec4 output1;"
3867 "layout(location = 3) out vec4 output2;"
3868 "void main()\n"
3869 "{\n"
3870 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3871 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3872 "}\n";
3873 }
3874 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
3875
3876 // Test that attachments not written to get the "unwritten" color
3877 {
3878 ClearEverythingToRed(renderbuffers);
3879
Geoff Lange8afa902017-09-27 15:00:43 -04003880 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003881 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003882 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003883 ASSERT_GL_NO_ERROR();
3884
3885 CheckColors(renderbuffers, 0b1010, GLColor::green);
3886 CheckColors(renderbuffers, 0b0101, unwrittenColor);
3887 }
3888
3889 // Test that attachments not written to get the "unwritten" color but that even when the
3890 // extension is used, disabled attachments are not written at all and stay red.
3891 {
3892 ClearEverythingToRed(renderbuffers);
3893
Geoff Lange8afa902017-09-27 15:00:43 -04003894 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003895 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003896 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003897 ASSERT_GL_NO_ERROR();
3898
3899 CheckColors(renderbuffers, 0b1000, GLColor::green);
3900 CheckColors(renderbuffers, 0b0100, unwrittenColor);
3901 CheckColors(renderbuffers, 0b0011, GLColor::red);
3902 }
3903}
3904
Geoff Lang536eca12017-09-13 11:23:35 -04003905// Test that it's possible to generate mipmaps on unsized floating point textures once the
3906// extensions have been enabled
3907TEST_P(WebGLCompatibilityTest, GenerateMipmapUnsizedFloatingPointTexture)
3908{
3909 if (extensionRequestable("GL_OES_texture_float"))
3910 {
3911 glRequestExtensionANGLE("GL_OES_texture_float");
3912 }
3913 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3914
3915 GLTexture texture;
3916 glBindTexture(GL_TEXTURE_2D, texture);
3917
3918 constexpr GLColor32F data[4] = {
3919 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3920 };
3921 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_FLOAT, data);
3922 ASSERT_GL_NO_ERROR();
3923
3924 glGenerateMipmap(GL_TEXTURE_2D);
3925 EXPECT_GL_NO_ERROR();
3926}
3927// Test that it's possible to generate mipmaps on unsized floating point textures once the
3928// extensions have been enabled
3929TEST_P(WebGLCompatibilityTest, GenerateMipmapSizedFloatingPointTexture)
3930{
3931 if (extensionRequestable("GL_OES_texture_float"))
3932 {
3933 glRequestExtensionANGLE("GL_OES_texture_float");
3934 }
3935 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3936
3937 if (extensionRequestable("GL_EXT_texture_storage"))
3938 {
3939 glRequestExtensionANGLE("GL_EXT_texture_storage");
3940 }
3941 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage"));
3942
3943 GLTexture texture;
3944 glBindTexture(GL_TEXTURE_2D, texture);
3945
3946 constexpr GLColor32F data[4] = {
3947 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3948 };
3949 glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA32F, 2, 2);
3950 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_FLOAT, data);
3951 ASSERT_GL_NO_ERROR();
3952
3953 glGenerateMipmap(GL_TEXTURE_2D);
3954 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3955
3956 if (extensionRequestable("GL_EXT_color_buffer_float"))
3957 {
3958 // Format is renderable but not filterable
3959 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3960 glGenerateMipmap(GL_TEXTURE_2D);
3961 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3962 }
3963
3964 if (extensionRequestable("GL_EXT_color_buffer_float_linear"))
3965 {
3966 // Format is renderable but not filterable
3967 glRequestExtensionANGLE("GL_EXT_color_buffer_float_linear");
3968
3969 if (extensionEnabled("GL_EXT_color_buffer_float"))
3970 {
3971 // Format is filterable and renderable
3972 glGenerateMipmap(GL_TEXTURE_2D);
3973 EXPECT_GL_NO_ERROR();
3974 }
3975 else
3976 {
3977 // Format is filterable but not renderable
3978 glGenerateMipmap(GL_TEXTURE_2D);
3979 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3980 }
3981 }
3982}
3983
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003984// Verify that a texture format is only allowed with extension enabled.
3985void WebGLCompatibilityTest::validateTexImageExtensionFormat(GLenum format,
3986 const std::string &extName)
3987{
3988 // Verify texture format fails by default.
3989 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3990 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3991
3992 if (extensionRequestable(extName))
3993 {
3994 // Verify texture format is allowed once extension is enabled.
3995 glRequestExtensionANGLE(extName.c_str());
3996 EXPECT_TRUE(extensionEnabled(extName));
3997
3998 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3999 ASSERT_GL_NO_ERROR();
4000 }
4001}
4002
Geoff Lang86f81162017-10-30 15:10:45 -04004003// Test enabling various non-compressed texture format extensions
4004TEST_P(WebGLCompatibilityTest, EnableTextureFormatExtensions)
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07004005{
Geoff Lang2c5c41f2017-10-31 10:58:09 -04004006 ANGLE_SKIP_TEST_IF(IsOzone());
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07004007 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
4008
4009 GLTexture texture;
4010 glBindTexture(GL_TEXTURE_2D, texture.get());
4011
4012 // Verify valid format is allowed.
4013 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
4014 ASSERT_GL_NO_ERROR();
4015
4016 // Verify invalid format fails.
4017 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA32F, GL_UNSIGNED_BYTE, nullptr);
4018 EXPECT_GL_ERROR(GL_INVALID_ENUM);
4019
4020 // Verify formats from enableable extensions.
Geoff Lang660b28c2017-10-30 12:58:56 -04004021 if (!IsOpenGLES())
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07004022 {
4023 validateTexImageExtensionFormat(GL_RED_EXT, "GL_EXT_texture_rg");
4024 }
4025
4026 validateTexImageExtensionFormat(GL_SRGB_EXT, "GL_EXT_texture_sRGB");
4027 validateTexImageExtensionFormat(GL_BGRA_EXT, "GL_EXT_texture_format_BGRA8888");
4028}
4029
Geoff Lang86f81162017-10-30 15:10:45 -04004030void WebGLCompatibilityTest::validateCompressedTexImageExtensionFormat(GLenum format,
4031 GLsizei width,
4032 GLsizei height,
4033 GLsizei blockSize,
4034 const std::string &extName,
4035 bool subImageAllowed)
4036{
4037 std::vector<GLubyte> data(blockSize, 0u);
4038
4039 GLTexture texture;
4040 glBindTexture(GL_TEXTURE_2D, texture.get());
4041
4042 // Verify texture format fails by default.
4043 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
4044 EXPECT_GL_ERROR(GL_INVALID_ENUM);
4045
4046 if (extensionRequestable(extName))
4047 {
4048 // Verify texture format is allowed once extension is enabled.
4049 glRequestExtensionANGLE(extName.c_str());
4050 EXPECT_TRUE(extensionEnabled(extName));
4051
4052 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
4053 EXPECT_GL_NO_ERROR();
4054
4055 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, blockSize,
4056 data.data());
4057 if (subImageAllowed)
4058 {
4059 EXPECT_GL_NO_ERROR();
4060 }
4061 else
4062 {
4063 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4064 }
4065 }
4066}
4067
4068// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGB_S3TC_DXT1_EXT
4069TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGB)
4070{
4071 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 8,
4072 "GL_EXT_texture_compression_dxt1", true);
4073}
4074
4075// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
4076TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGBA)
4077{
4078 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 8,
4079 "GL_EXT_texture_compression_dxt1", true);
4080}
4081
4082// Test enabling GL_ANGLE_texture_compression_dxt3
4083TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3)
4084{
4085 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 16,
4086 "GL_ANGLE_texture_compression_dxt3", true);
4087}
4088
4089// Test enabling GL_ANGLE_texture_compression_dxt5
4090TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5)
4091{
4092 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 16,
4093 "GL_ANGLE_texture_compression_dxt5", true);
4094}
4095
4096// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
4097TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGB)
4098{
4099 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 8,
4100 "GL_EXT_texture_compression_s3tc_srgb", true);
4101}
4102
4103// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
4104TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGBA)
4105{
4106 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 8,
4107 "GL_EXT_texture_compression_s3tc_srgb", true);
4108}
4109
4110// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
4111TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3SRGBA)
4112{
4113 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 16,
4114 "GL_EXT_texture_compression_s3tc_srgb", true);
4115}
4116
4117// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
4118TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5SRGBA)
4119{
4120 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 16,
4121 "GL_EXT_texture_compression_s3tc_srgb", true);
4122}
4123
4124// Test enabling GL_OES_compressed_ETC1_RGB8_texture
4125TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionETC1)
4126{
4127 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_OES, 4, 4, 8,
4128 "GL_OES_compressed_ETC1_RGB8_texture", false);
4129}
4130
4131// Test enabling GL_ANGLE_lossy_etc_decode
4132TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionLossyDecode)
4133{
4134 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 8,
4135 "GL_ANGLE_lossy_etc_decode", true);
4136}
4137
Frank Henigmanfccbac22017-05-28 17:29:26 -04004138// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
4139// qualifiers.
4140TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
4141{
4142 const std::string vertexShader =
4143 "#version 300 es\n"
4144 "uniform Block { mediump vec4 val; };\n"
4145 "void main() { gl_Position = val; }\n";
4146 const std::string fragmentShader =
4147 "#version 300 es\n"
4148 "uniform Block { highp vec4 val; };\n"
4149 "out highp vec4 out_FragColor;\n"
4150 "void main() { out_FragColor = val; }\n";
4151
4152 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
4153 ASSERT_NE(0u, vs);
4154 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
4155 ASSERT_NE(0u, fs);
4156
4157 GLuint program = glCreateProgram();
4158
4159 glAttachShader(program, vs);
4160 glDeleteShader(vs);
4161 glAttachShader(program, fs);
4162 glDeleteShader(fs);
4163
4164 glLinkProgram(program);
4165 GLint linkStatus;
4166 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
4167 ASSERT_EQ(0, linkStatus);
4168
4169 glDeleteProgram(program);
4170}
4171
Geoff Lang69df2422017-07-05 12:42:31 -04004172// Test no attribute vertex shaders
4173TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
4174{
4175 const std::string vertexShader =
4176 "#version 300 es\n"
4177 "void main()\n"
4178 "{\n"
4179 "\n"
4180 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
4181 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
4182 "}";
Geoff Lang69df2422017-07-05 12:42:31 -04004183
Olli Etuaho5804dc82018-04-13 14:11:46 +03004184 ANGLE_GL_PROGRAM(program, vertexShader, essl3_shaders::fs::Red());
Geoff Lang69df2422017-07-05 12:42:31 -04004185 glUseProgram(program);
4186
4187 glDrawArrays(GL_TRIANGLES, 0, 6);
4188 ASSERT_GL_NO_ERROR();
Olli Etuaho5804dc82018-04-13 14:11:46 +03004189 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Geoff Lang69df2422017-07-05 12:42:31 -04004190}
4191
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004192// Tests bindAttribLocations for length limit
4193TEST_P(WebGL2CompatibilityTest, BindAttribLocationLimitation)
4194{
4195 constexpr int maxLocStringLength = 1024;
4196 const std::string tooLongString(maxLocStringLength + 1, '_');
4197
4198 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
4199
4200 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4201}
4202
Jamie Madill629bb252018-04-20 11:01:33 -04004203// Covers a bug in transform feedback loop detection.
4204TEST_P(WebGL2CompatibilityTest, TransformFeedbackCheckNullDeref)
4205{
4206 constexpr char kVS[] = R"(attribute vec4 color; void main() { color.r; })";
4207 constexpr char kFS[] = R"(void main(){})";
4208 ANGLE_GL_PROGRAM(program, kVS, kFS);
4209 glUseProgram(program);
4210
Jamie Madill629bb252018-04-20 11:01:33 -04004211 glEnableVertexAttribArray(0);
4212 glDrawArrays(GL_POINTS, 0, 1);
4213
Jamie Madilldc358af2018-07-31 11:22:13 -04004214 // This should fail because it is trying to pull a vertex with no buffer.
4215 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4216
4217 GLBuffer buffer;
4218 glBindBuffer(GL_ARRAY_BUFFER, buffer);
4219 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
4220
4221 // This should fail because it is trying to pull a vertex from an empty buffer.
4222 glDrawArrays(GL_POINTS, 0, 1);
Jamie Madill629bb252018-04-20 11:01:33 -04004223 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4224}
4225
Geoff Langc287ea62016-09-16 14:46:51 -04004226// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4227// tests should be run against.
4228ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
4229 ES2_D3D9(),
4230 ES2_D3D11(),
4231 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04004232 ES2_OPENGL(),
4233 ES3_OPENGL(),
4234 ES2_OPENGLES(),
4235 ES3_OPENGLES());
4236
Jamie Madill07be8bf2017-02-02 19:59:57 -05004237ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04004238} // namespace