blob: e55cba7012ebd246c08504559b461604e8d08203 [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
Brandon Jones2a018152018-06-08 15:59:26 -07001473// Test for drawing with a null index buffer
1474TEST_P(WebGLCompatibilityTest, NullIndexBuffer)
1475{
1476 const std::string &vert =
1477 "attribute float a_pos;\n"
1478 "void main()\n"
1479 "{\n"
1480 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1481 "}\n";
1482
1483 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
1484 glUseProgram(program.get());
1485
1486 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1487 glEnableVertexAttribArray(0);
1488
1489 glDrawElements(GL_TRIANGLES, 0, GL_UNSIGNED_BYTE, 0);
1490 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1491}
1492
Corentin Wallez91c8de82017-10-12 16:32:44 -04001493// Test the checks for OOB reads in the vertex buffers, instanced version
1494TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
1495{
1496 const std::string &vert =
1497 "attribute float a_pos;\n"
1498 "attribute float a_w;\n"
1499 "void main()\n"
1500 "{\n"
1501 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1502 "}\n";
1503
Olli Etuaho5804dc82018-04-13 14:11:46 +03001504 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez91c8de82017-10-12 16:32:44 -04001505 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1506 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1507 ASSERT_NE(-1, posLocation);
1508 ASSERT_NE(-1, wLocation);
1509 glUseProgram(program.get());
1510
1511 GLBuffer buffer;
1512 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1513 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1514
1515 glEnableVertexAttribArray(posLocation);
1516 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1517 glVertexAttribDivisor(posLocation, 0);
1518
1519 glEnableVertexAttribArray(wLocation);
1520 glVertexAttribDivisor(wLocation, 1);
1521
1522 const uint8_t* zeroOffset = nullptr;
1523
1524 // Test touching the last element is valid.
1525 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1526 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1527 ASSERT_GL_NO_ERROR();
1528
1529 // Test touching the last element + 1 is invalid.
1530 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1531 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1532 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1533
1534 // Test touching the last element is valid, using a stride.
1535 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1536 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1537 ASSERT_GL_NO_ERROR();
1538
1539 // Test touching the last element + 1 is invalid, using a stride.
1540 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1541 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1542 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1543
1544 // Test any offset is valid if no vertices are drawn.
1545 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1546 glDrawArraysInstanced(GL_POINTS, 0, 0, 1);
1547 ASSERT_GL_NO_ERROR();
1548
1549 // Test any offset is valid if no primitives are drawn.
1550 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1551 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1552 ASSERT_GL_NO_ERROR();
1553}
1554
1555// Test the checks for OOB reads in the vertex buffers, ANGLE_instanced_arrays version
1556TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsInstancedANGLE)
1557{
1558 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_ANGLE_instanced_arrays"));
1559 glRequestExtensionANGLE("GL_ANGLE_instanced_arrays");
1560 EXPECT_GL_NO_ERROR();
1561
1562 const std::string &vert =
1563 "attribute float a_pos;\n"
1564 "attribute float a_w;\n"
1565 "void main()\n"
1566 "{\n"
1567 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
1568 "}\n";
1569
Olli Etuaho5804dc82018-04-13 14:11:46 +03001570 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez91c8de82017-10-12 16:32:44 -04001571 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1572 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1573 ASSERT_NE(-1, posLocation);
1574 ASSERT_NE(-1, wLocation);
1575 glUseProgram(program.get());
1576
1577 GLBuffer buffer;
1578 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1579 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1580
1581 glEnableVertexAttribArray(posLocation);
1582 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1583 glVertexAttribDivisorANGLE(posLocation, 0);
1584
1585 glEnableVertexAttribArray(wLocation);
1586 glVertexAttribDivisorANGLE(wLocation, 1);
1587
1588 const uint8_t* zeroOffset = nullptr;
1589
1590 // Test touching the last element is valid.
1591 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1592 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1593 ASSERT_GL_NO_ERROR();
1594
1595 // Test touching the last element + 1 is invalid.
1596 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1597 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1598 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1599
1600 // Test touching the last element is valid, using a stride.
1601 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1602 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1603 ASSERT_GL_NO_ERROR();
1604
1605 // Test touching the last element + 1 is invalid, using a stride.
1606 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1607 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 4);
1608 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1609
1610 // Test any offset is valid if no vertices are drawn.
1611 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1612 glDrawArraysInstancedANGLE(GL_POINTS, 0, 0, 1);
1613 ASSERT_GL_NO_ERROR();
1614
1615 // Test any offset is valid if no primitives are drawn.
1616 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1617 glDrawArraysInstancedANGLE(GL_POINTS, 0, 1, 0);
1618 ASSERT_GL_NO_ERROR();
Corentin Wallezfd456442016-12-21 17:57:00 -05001619}
1620
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001621// Test the checks for OOB reads in the index buffer
1622TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -05001623{
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001624 const std::string &vert =
1625 "attribute float a_pos;\n"
1626 "void main()\n"
1627 "{\n"
1628 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1629 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -05001630
Olli Etuaho5804dc82018-04-13 14:11:46 +03001631 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001632 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1633 ASSERT_NE(-1, posLocation);
1634 glUseProgram(program.get());
1635
1636 GLBuffer vertexBuffer;
1637 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1638 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1639
1640 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001641 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001642
1643 const uint8_t *zeroOffset = nullptr;
1644 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
1645
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001646 GLBuffer indexBuffer;
1647 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1648 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -05001649 ASSERT_GL_NO_ERROR();
1650
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001651 // Test touching the last index is valid
1652 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1653 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -05001654
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001655 // Test touching the last + 1 element is invalid
1656 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
1657 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -05001658
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001659 // Test any offset if valid if count is zero
1660 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
1661 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -05001662
1663 // Test touching the first index is valid
1664 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1665 ASSERT_GL_NO_ERROR();
1666
1667 // Test touching the first - 1 index is invalid
1668 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
1669 // the historic behavior of WebGL implementations
1670 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
1671 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -05001672}
1673
Corentin Wallez91c8de82017-10-12 16:32:44 -04001674// Test the checks for OOB in vertex buffers caused by indices, non-instanced version
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001675TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInVertexBuffer)
1676{
1677 const std::string &vert =
1678 "attribute float a_pos;\n"
1679 "void main()\n"
1680 "{\n"
1681 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1682 "}\n";
1683
Olli Etuaho5804dc82018-04-13 14:11:46 +03001684 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001685 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1686 ASSERT_NE(-1, posLocation);
1687 glUseProgram(program.get());
1688
1689 GLBuffer vertexBuffer;
1690 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1691 glBufferData(GL_ARRAY_BUFFER, 8, nullptr, GL_STATIC_DRAW);
1692
1693 glEnableVertexAttribArray(posLocation);
Corentin Wallez91c8de82017-10-12 16:32:44 -04001694 glVertexAttribPointer(posLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001695
1696 const uint8_t *zeroOffset = nullptr;
1697 const uint8_t testIndices[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 255};
1698
Corentin Wallezc3bc9842017-10-11 15:15:59 -04001699 GLBuffer indexBuffer;
1700 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1701 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(testIndices), testIndices, GL_STATIC_DRAW);
1702 ASSERT_GL_NO_ERROR();
1703
1704 // Test touching the end of the vertex buffer is valid
1705 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 7);
1706 ASSERT_GL_NO_ERROR();
1707
1708 // Test touching just after the end of the vertex buffer is invalid
1709 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 8);
1710 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1711
1712 // Test touching the whole vertex buffer is valid
1713 glDrawElements(GL_POINTS, 8, GL_UNSIGNED_BYTE, zeroOffset + 0);
1714 ASSERT_GL_NO_ERROR();
1715
1716 // Test an index that would be negative
1717 glDrawElements(GL_POINTS, 1, GL_UNSIGNED_BYTE, zeroOffset + 9);
1718 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1719}
1720
Frank Henigman6137ddc2017-02-10 18:55:07 -05001721// Test depth range with 'near' more or less than 'far.'
1722TEST_P(WebGLCompatibilityTest, DepthRange)
1723{
1724 glDepthRangef(0, 1);
1725 ASSERT_GL_NO_ERROR();
1726
1727 glDepthRangef(.5, .5);
1728 ASSERT_GL_NO_ERROR();
1729
1730 glDepthRangef(1, 0);
1731 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1732}
1733
Frank Henigman146e8a12017-03-02 23:22:37 -05001734// Test all blend function combinations.
1735// In WebGL it is invalid to combine constant color with constant alpha.
1736TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
1737{
1738 constexpr GLenum srcFunc[] = {
1739 GL_ZERO,
1740 GL_ONE,
1741 GL_SRC_COLOR,
1742 GL_ONE_MINUS_SRC_COLOR,
1743 GL_DST_COLOR,
1744 GL_ONE_MINUS_DST_COLOR,
1745 GL_SRC_ALPHA,
1746 GL_ONE_MINUS_SRC_ALPHA,
1747 GL_DST_ALPHA,
1748 GL_ONE_MINUS_DST_ALPHA,
1749 GL_CONSTANT_COLOR,
1750 GL_ONE_MINUS_CONSTANT_COLOR,
1751 GL_CONSTANT_ALPHA,
1752 GL_ONE_MINUS_CONSTANT_ALPHA,
1753 GL_SRC_ALPHA_SATURATE,
1754 };
1755
1756 constexpr GLenum dstFunc[] = {
1757 GL_ZERO, GL_ONE,
1758 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1759 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1760 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1761 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
1762 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
1763 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
1764 };
1765
1766 for (GLenum src : srcFunc)
1767 {
1768 for (GLenum dst : dstFunc)
1769 {
1770 glBlendFunc(src, dst);
1771 CheckBlendFunctions(src, dst);
1772 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
1773 CheckBlendFunctions(src, dst);
1774 }
1775 }
1776}
1777
Geoff Langfc32e8b2017-05-31 14:16:59 -04001778// Test that binding/querying uniforms and attributes with invalid names generates errors
1779TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
1780{
1781 const std::string validAttribName =
1782 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
1783 const std::string validUniformName =
1784 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
Geoff Langa71a98e2017-06-19 15:15:00 -04001785 std::vector<char> invalidSet = {'"', '$', '`', '@', '\''};
1786 if (getClientMajorVersion() < 3)
1787 {
1788 invalidSet.push_back('\\');
1789 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04001790
1791 std::string vert = "attribute float ";
1792 vert += validAttribName;
1793 vert +=
1794 ";\n"
1795 "void main()\n"
1796 "{\n"
1797 " gl_Position = vec4(1.0);\n"
1798 "}\n";
1799
1800 std::string frag =
1801 "precision highp float;\n"
1802 "uniform vec4 ";
1803 frag += validUniformName;
Geoff Langcab92ee2017-07-19 17:32:07 -04001804 // Insert illegal characters into comments
Geoff Langfc32e8b2017-05-31 14:16:59 -04001805 frag +=
1806 ";\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001807 " // $ \" @ /*\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001808 "void main()\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001809 "{/*\n"
1810 " ` @ $\n"
1811 " */gl_FragColor = vec4(1.0);\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001812 "}\n";
1813
1814 ANGLE_GL_PROGRAM(program, vert, frag);
1815 EXPECT_GL_NO_ERROR();
1816
1817 for (char invalidChar : invalidSet)
1818 {
1819 std::string invalidName = validAttribName + invalidChar;
1820 glGetAttribLocation(program, invalidName.c_str());
1821 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1822 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1823
1824 glBindAttribLocation(program, 0, invalidName.c_str());
1825 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1826 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1827 }
1828
1829 for (char invalidChar : invalidSet)
1830 {
1831 std::string invalidName = validUniformName + invalidChar;
1832 glGetUniformLocation(program, invalidName.c_str());
1833 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1834 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1835 }
1836
1837 for (char invalidChar : invalidSet)
1838 {
1839 std::string invalidAttribName = validAttribName + invalidChar;
1840 const char *invalidVert[] = {
1841 "attribute float ",
1842 invalidAttribName.c_str(),
1843 ";\n",
1844 "void main()\n",
1845 "{\n",
1846 " gl_Position = vec4(1.0);\n",
1847 "}\n",
1848 };
1849
1850 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1851 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
1852 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1853 glDeleteShader(shader);
1854 }
1855}
1856
Geoff Langcab92ee2017-07-19 17:32:07 -04001857// Test that line continuation is handled correctly when valdiating shader source
Bryan Bernhart (Intel Americas Inc)335d8bf2017-10-23 15:41:43 -07001858TEST_P(WebGLCompatibilityTest, ShaderSourceLineContinuation)
1859{
1860 // Verify that a line continuation character (i.e. backslash) cannot be used
1861 // within a preprocessor directive in a ES2 context.
1862 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
1863
1864 const char *validVert =
1865 "#define foo this is a test\n"
1866 "precision mediump float;\n"
1867 "void main()\n"
1868 "{\n"
1869 " gl_Position = vec4(1.0);\n"
1870 "}\n";
1871
1872 const char *invalidVert =
1873 "#define foo this \\n"
1874 " is a test\n"
1875 "precision mediump float;\n"
1876 "void main()\n"
1877 "{\n"
1878 " gl_Position = vec4(1.0);\n"
1879 "}\n";
1880
1881 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1882 glShaderSource(shader, 1, &validVert, nullptr);
1883 EXPECT_GL_NO_ERROR();
1884
1885 glShaderSource(shader, 1, &invalidVert, nullptr);
1886 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1887 glDeleteShader(shader);
1888}
1889
1890// Test that line continuation is handled correctly when valdiating shader source
Geoff Langcab92ee2017-07-19 17:32:07 -04001891TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
1892{
1893 const char *validVert =
1894 "#version 300 es\n"
1895 "precision mediump float;\n"
1896 "\n"
1897 "void main ()\n"
1898 "{\n"
1899 " float f\\\n"
1900 "oo = 1.0;\n"
1901 " gl_Position = vec4(foo);\n"
1902 "}\n";
1903
1904 const char *invalidVert =
1905 "#version 300 es\n"
1906 "precision mediump float;\n"
1907 "\n"
1908 "void main ()\n"
1909 "{\n"
1910 " float f\\$\n"
1911 "oo = 1.0;\n"
1912 " gl_Position = vec4(foo);\n"
1913 "}\n";
1914
1915 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1916 glShaderSource(shader, 1, &validVert, nullptr);
1917 EXPECT_GL_NO_ERROR();
1918 glShaderSource(shader, 1, &invalidVert, nullptr);
1919 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1920 glDeleteShader(shader);
1921}
1922
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001923// Tests bindAttribLocations for reserved prefixes and length limits
1924TEST_P(WebGLCompatibilityTest, BindAttribLocationLimitation)
1925{
1926 constexpr int maxLocStringLength = 256;
1927 const std::string tooLongString(maxLocStringLength + 1, '_');
1928
1929 glBindAttribLocation(0, 0, "_webgl_var");
1930
1931 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1932
1933 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
1934
1935 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1936}
1937
Corentin Wallez0dc97812017-06-22 14:38:44 -04001938// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001939TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1940{
1941 const std::string &vert =
1942 "attribute float a_pos;\n"
1943 "void main()\n"
1944 "{\n"
1945 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1946 "}\n";
1947
Olli Etuaho5804dc82018-04-13 14:11:46 +03001948 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Geoff Lang407d4e72017-04-12 14:54:11 -04001949
1950 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1951 ASSERT_NE(-1, posLocation);
1952
1953 glUseProgram(program.get());
1954
1955 GLBuffer buffer;
1956 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1957 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1958
1959 glEnableVertexAttribArray(posLocation);
1960 glVertexAttribDivisor(posLocation, 1);
1961
Geoff Lang407d4e72017-04-12 14:54:11 -04001962 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1963 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04001964 ASSERT_GL_NO_ERROR();
1965}
1966
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001967// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1968TEST_P(WebGLCompatibilityTest, NPOT)
1969{
1970 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1971
1972 // Create a texture and set an NPOT mip 0, should always be acceptable.
1973 GLTexture texture;
1974 glBindTexture(GL_TEXTURE_2D, texture.get());
1975 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1976 ASSERT_GL_NO_ERROR();
1977
1978 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1979 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1980 if (getClientMajorVersion() < 3)
1981 {
1982 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1983 }
1984 else
1985 {
1986 ASSERT_GL_NO_ERROR();
1987 }
1988
1989 if (extensionRequestable("GL_OES_texture_npot"))
1990 {
1991 glRequestExtensionANGLE("GL_OES_texture_npot");
1992 ASSERT_GL_NO_ERROR();
1993
1994 // Try again to set NPOT mip 1
1995 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1996 ASSERT_GL_NO_ERROR();
1997 }
1998}
1999
Jamie Madillcad97ee2017-02-02 18:52:44 -05002000template <typename T>
2001void FillTexture2D(GLuint texture,
2002 GLsizei width,
2003 GLsizei height,
2004 const T &onePixelData,
2005 GLint level,
2006 GLint internalFormat,
2007 GLenum format,
2008 GLenum type)
2009{
2010 std::vector<T> allPixelsData(width * height, onePixelData);
2011
2012 glBindTexture(GL_TEXTURE_2D, texture);
2013 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
2014 allPixelsData.data());
2015 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2016 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2017 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2018 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2019}
2020
Frank Henigman875bbba2017-02-08 16:38:17 -05002021// Test that unset gl_Position defaults to (0,0,0,0).
2022TEST_P(WebGLCompatibilityTest, DefaultPosition)
2023{
2024 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
2025 // and green otherwise. The center of each quadrant will be red if and only if all
2026 // four corners are red.
2027 const std::string vertexShader =
2028 "attribute vec3 pos;\n"
2029 "varying vec4 color;\n"
2030 "void main() {\n"
2031 " if (gl_Position == vec4(0,0,0,0)) {\n"
2032 " color = vec4(1,0,0,1);\n"
2033 " } else {\n"
2034 " color = vec4(0,1,0,1);\n"
2035 " }\n"
2036 " gl_Position = vec4(pos,1);\n"
2037 "}\n";
2038
2039 const std::string fragmentShader =
2040 "precision mediump float;\n"
2041 "varying vec4 color;\n"
2042 "void main() {\n"
2043 " gl_FragColor = color;\n"
2044 "}\n";
2045
2046 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2047 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
2048 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
2049 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
2050 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
2051 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
2052}
2053
Jamie Madilla4595b82017-01-11 17:36:34 -05002054// Tests that a rendering feedback loop triggers a GL error under WebGL.
2055// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
2056TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
2057{
2058 const std::string vertexShader =
2059 "attribute vec4 a_position;\n"
2060 "varying vec2 v_texCoord;\n"
2061 "void main() {\n"
2062 " gl_Position = a_position;\n"
2063 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
2064 "}\n";
2065
2066 const std::string fragmentShader =
2067 "precision mediump float;\n"
2068 "varying vec2 v_texCoord;\n"
2069 "uniform sampler2D u_texture;\n"
2070 "void main() {\n"
2071 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
2072 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
2073 "}\n";
2074
2075 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05002076 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05002077
2078 ASSERT_GL_NO_ERROR();
2079
2080 GLFramebuffer framebuffer;
2081 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2082 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2083
2084 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2085
2086 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2087
2088 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
2089 ASSERT_NE(-1, uniformLoc);
2090
2091 glUseProgram(program.get());
2092 glUniform1i(uniformLoc, 0);
2093 glDisable(GL_BLEND);
2094 glDisable(GL_DEPTH_TEST);
2095 ASSERT_GL_NO_ERROR();
2096
2097 // Drawing with a texture that is also bound to the current framebuffer should fail
2098 glBindTexture(GL_TEXTURE_2D, texture.get());
2099 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2100 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2101
2102 // Ensure that the texture contents did not change after the previous render
2103 glBindFramebuffer(GL_FRAMEBUFFER, 0);
2104 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2105 ASSERT_GL_NO_ERROR();
2106 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
2107
2108 // Drawing when texture is bound to an inactive uniform should succeed
2109 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05002110 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05002111
2112 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2113 glActiveTexture(GL_TEXTURE1);
2114 glBindTexture(GL_TEXTURE_2D, texture.get());
2115 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
2116 ASSERT_GL_NO_ERROR();
2117 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
2118}
2119
Bryan Bernhart58806562017-01-05 13:09:31 -08002120// Test for the max draw buffers and color attachments.
2121TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
2122{
2123 // This test only applies to ES2.
2124 if (getClientMajorVersion() != 2)
2125 {
2126 return;
2127 }
2128
2129 GLFramebuffer fbo[2];
2130 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
2131
2132 // Test that is valid when we bind with a single attachment point.
2133 GLTexture texture;
2134 glBindTexture(GL_TEXTURE_2D, texture.get());
2135 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2136 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2137 ASSERT_GL_NO_ERROR();
2138
2139 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
2140 // attachment point.
2141 if (extensionRequestable("GL_EXT_draw_buffers"))
2142 {
2143 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2144 EXPECT_GL_NO_ERROR();
2145 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
2146
2147 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
2148
2149 GLTexture texture2;
2150 glBindTexture(GL_TEXTURE_2D, texture2.get());
2151 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2152 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
2153 0);
2154 ASSERT_GL_NO_ERROR();
2155 }
2156}
2157
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002158// Test that the offset in the index buffer is forced to be a multiple of the element size
2159TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
2160{
2161 const std::string &vert =
2162 "attribute vec3 a_pos;\n"
2163 "void main()\n"
2164 "{\n"
2165 " gl_Position = vec4(a_pos, 1.0);\n"
2166 "}\n";
2167
Olli Etuaho5804dc82018-04-13 14:11:46 +03002168 ANGLE_GL_PROGRAM(program, vert, essl1_shaders::fs::Red());
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002169
2170 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
2171 ASSERT_NE(-1, posLocation);
2172 glUseProgram(program.get());
2173
2174 const auto &vertices = GetQuadVertices();
2175
2176 GLBuffer vertexBuffer;
2177 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
2178 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
2179 GL_STATIC_DRAW);
2180
2181 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
2182 glEnableVertexAttribArray(posLocation);
2183
2184 GLBuffer indexBuffer;
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002185 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002186 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
2187 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
2188
2189 ASSERT_GL_NO_ERROR();
2190
2191 const char *zeroIndices = nullptr;
2192
2193 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
2194 ASSERT_GL_NO_ERROR();
2195
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002196 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002197 ASSERT_GL_NO_ERROR();
2198
Brandon Jonesed5b46f2017-07-21 08:39:17 -07002199 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices + 1);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05002200 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2201}
2202
2203// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
2204// size
2205TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
2206{
2207 const char *zeroOffset = nullptr;
2208
2209 // Base case, vector of two floats
2210 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
2211 ASSERT_GL_NO_ERROR();
2212
2213 // Test setting a non-multiple offset
2214 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
2215 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2216 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
2217 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2218 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
2219 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2220
2221 // Test setting a non-multiple stride
2222 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
2223 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2224 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
2225 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2226 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
2227 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2228}
2229
Jamie Madillcad97ee2017-02-02 18:52:44 -05002230void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
2231 const std::array<GLenum, 2> &drawBuffers,
2232 GLenum expectedError)
2233{
2234 glDrawBuffersEXT(2, drawBuffers.data());
2235
2236 // Make sure framebuffer is complete before feedback loop detection
2237 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2238
2239 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
2240
2241 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
2242 // it should be NO_ERROR"
2243 EXPECT_GL_ERROR(expectedError);
2244}
2245
2246// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
2247// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
2248TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
2249{
2250 const std::string vertexShader =
2251 "attribute vec4 aPosition;\n"
2252 "varying vec2 texCoord;\n"
2253 "void main() {\n"
2254 " gl_Position = aPosition;\n"
2255 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2256 "}\n";
2257
2258 const std::string fragmentShader =
2259 "#extension GL_EXT_draw_buffers : require\n"
2260 "precision mediump float;\n"
2261 "uniform sampler2D tex;\n"
2262 "varying vec2 texCoord;\n"
2263 "void main() {\n"
2264 " gl_FragData[0] = texture2D(tex, texCoord);\n"
2265 " gl_FragData[1] = texture2D(tex, texCoord);\n"
2266 "}\n";
2267
2268 GLsizei width = 8;
2269 GLsizei height = 8;
2270
2271 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
2272 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
2273 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
2274 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
2275 {
2276 // No WEBGL_draw_buffers support -- this is legal.
2277 return;
2278 }
2279
2280 GLint maxDrawBuffers = 0;
2281 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2282
Yunchao He9550c602018-02-13 14:47:05 +08002283 // Test skipped because MAX_DRAW_BUFFERS is too small.
2284 ANGLE_SKIP_TEST_IF(maxDrawBuffers < 2);
Jamie Madillcad97ee2017-02-02 18:52:44 -05002285
2286 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2287 glUseProgram(program.get());
2288 glViewport(0, 0, width, height);
2289
2290 GLTexture tex0;
2291 GLTexture tex1;
2292 GLFramebuffer fbo;
2293 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2294 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2295 ASSERT_GL_NO_ERROR();
2296
2297 glBindTexture(GL_TEXTURE_2D, tex1.get());
2298 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2299 ASSERT_NE(-1, texLoc);
2300 glUniform1i(texLoc, 0);
2301 ASSERT_GL_NO_ERROR();
2302
2303 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2304 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2305 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2306 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2307
2308 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
2309 GL_INVALID_OPERATION);
2310 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2311 GL_INVALID_OPERATION);
2312 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2313}
2314
Jamie Madill07be8bf2017-02-02 19:59:57 -05002315// Test tests that texture copying feedback loops are properly rejected in WebGL.
2316// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
2317TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
2318{
2319 GLTexture texture;
2320 glBindTexture(GL_TEXTURE_2D, texture.get());
2321 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2324 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2325 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2326
2327 GLTexture texture2;
2328 glBindTexture(GL_TEXTURE_2D, texture2.get());
2329 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2330 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2331 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2332 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
2333 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
2334
2335 GLFramebuffer framebuffer;
2336 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2337 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2338
2339 // framebuffer should be FRAMEBUFFER_COMPLETE.
2340 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2341 ASSERT_GL_NO_ERROR();
2342
2343 // testing copyTexImage2D
2344
2345 // copyTexImage2D to same texture but different level
2346 glBindTexture(GL_TEXTURE_2D, texture.get());
2347 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
2348 EXPECT_GL_NO_ERROR();
2349
2350 // copyTexImage2D to same texture same level, invalid feedback loop
2351 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2352 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2353
2354 // copyTexImage2D to different texture
2355 glBindTexture(GL_TEXTURE_2D, texture2.get());
2356 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
2357 EXPECT_GL_NO_ERROR();
2358
2359 // testing copyTexSubImage2D
2360
2361 // copyTexSubImage2D to same texture but different level
2362 glBindTexture(GL_TEXTURE_2D, texture.get());
2363 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
2364 EXPECT_GL_NO_ERROR();
2365
2366 // copyTexSubImage2D to same texture same level, invalid feedback loop
2367 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2368 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2369
2370 // copyTexSubImage2D to different texture
2371 glBindTexture(GL_TEXTURE_2D, texture2.get());
2372 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2373 EXPECT_GL_NO_ERROR();
2374}
2375
2376void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
2377 const std::array<GLenum, 2> &drawBuffers,
2378 GLenum expectedError)
2379{
2380 glDrawBuffers(2, drawBuffers.data());
2381
2382 // Make sure framebuffer is complete before feedback loop detection
2383 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2384
2385 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
2386
2387 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
2388 // it should be NO_ERROR"
2389 EXPECT_GL_ERROR(expectedError);
2390}
2391
Yuly Novikov817232e2017-02-22 18:36:10 -05002392// Tests invariance matching rules between built in varyings.
2393// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
2394TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
2395{
2396 const std::string vertexShaderVariant =
2397 "varying vec4 v_varying;\n"
2398 "void main()\n"
2399 "{\n"
2400 " gl_PointSize = 1.0;\n"
2401 " gl_Position = v_varying;\n"
2402 "}";
2403 const std::string fragmentShaderInvariantGlFragCoord =
2404 "invariant gl_FragCoord;\n"
2405 "void main()\n"
2406 "{\n"
2407 " gl_FragColor = gl_FragCoord;\n"
2408 "}";
2409 const std::string fragmentShaderInvariantGlPointCoord =
2410 "invariant gl_PointCoord;\n"
2411 "void main()\n"
2412 "{\n"
2413 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
2414 "}";
2415
2416 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
2417 EXPECT_EQ(0u, program);
2418
2419 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
2420 EXPECT_EQ(0u, program);
2421}
2422
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04002423// Tests global namespace conflicts between uniforms and attributes.
2424// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
2425TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
2426{
2427 const std::string vertexShader =
2428 "attribute vec4 foo;\n"
2429 "void main()\n"
2430 "{\n"
2431 " gl_Position = foo;\n"
2432 "}";
2433 const std::string fragmentShader =
2434 "precision mediump float;\n"
2435 "uniform vec4 foo;\n"
2436 "void main()\n"
2437 "{\n"
2438 " gl_FragColor = foo;\n"
2439 "}";
2440
2441 GLuint program = CompileProgram(vertexShader, fragmentShader);
2442 EXPECT_EQ(0u, program);
2443}
2444
Geoff Lang966c9402017-04-18 12:38:27 -04002445// Test dimension and image size validation of compressed textures
2446TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
2447{
2448 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
2449 {
2450 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
2451 }
2452
Yunchao He9550c602018-02-13 14:47:05 +08002453 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_compression_dxt1"));
Geoff Lang966c9402017-04-18 12:38:27 -04002454
2455 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
2456
2457 GLTexture texture;
2458 glBindTexture(GL_TEXTURE_2D, texture);
2459
2460 // Regular case, verify that it works
2461 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2462 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2463 ASSERT_GL_NO_ERROR();
2464
2465 // Test various dimensions that are not valid
2466 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
2467 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2468 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2469
2470 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
2471 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2472 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2473
2474 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2475 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2476 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2477
2478 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2479 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2480 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2481
2482 // Test various image sizes that are not valid
2483 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2484 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
2485 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2486
2487 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2488 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
2489 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2490
2491 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
2492 CompressedImageDXT1);
2493 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2494
2495 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
2496 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2497 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2498
2499 // Fill a full mip chain and verify that it works
2500 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2501 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2502 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2503 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2504 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2505 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2506 ASSERT_GL_NO_ERROR();
2507
2508 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2509 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2510 ASSERT_GL_NO_ERROR();
2511
2512 // Test that non-block size sub-uploads are not valid for the 0 mip
2513 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2514 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2515 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2516
2517 // Test that non-block size sub-uploads are valid for if they fill the whole mip
2518 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2519 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2520 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2521 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2522 ASSERT_GL_NO_ERROR();
2523
2524 // Test that if the format miss-matches the texture, an error is generated
2525 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2526 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2527 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2528}
2529
Geoff Lang677bb6f2017-04-05 12:40:40 -04002530TEST_P(WebGLCompatibilityTest, L32FTextures)
2531{
2532 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
2533 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
2534
2535 for (auto extension : FloatingPointTextureExtensions)
2536 {
2537 if (strlen(extension) > 0 && extensionRequestable(extension))
2538 {
2539 glRequestExtensionANGLE(extension);
2540 ASSERT_GL_NO_ERROR();
2541 }
2542
2543 // Unsized L 32F
2544 {
2545 bool texture = extensionEnabled("GL_OES_texture_float");
2546 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2547 bool render = false;
2548 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
2549 textureData, readPixelData);
2550 }
2551
2552 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2553 {
2554 // Sized L 32F
2555 bool texture = extensionEnabled("GL_OES_texture_float") &&
2556 extensionEnabled("GL_EXT_texture_storage");
2557 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2558 bool render = false;
2559 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
2560 render, textureData, readPixelData);
2561 }
2562 }
2563}
2564
2565TEST_P(WebGLCompatibilityTest, A32FTextures)
2566{
2567 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
2568 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
2569
2570 for (auto extension : FloatingPointTextureExtensions)
2571 {
2572 if (strlen(extension) > 0 && extensionRequestable(extension))
2573 {
2574 glRequestExtensionANGLE(extension);
2575 ASSERT_GL_NO_ERROR();
2576 }
2577
2578 // Unsized A 32F
2579 {
2580 bool texture = extensionEnabled("GL_OES_texture_float");
2581 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2582 bool render = false;
2583 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
2584 textureData, readPixelData);
2585 }
2586
2587 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2588 {
2589 // Sized A 32F
2590 bool texture = extensionEnabled("GL_OES_texture_float") &&
2591 extensionEnabled("GL_EXT_texture_storage");
2592 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2593 bool render = false;
2594 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
2595 textureData, readPixelData);
2596 }
2597 }
2598}
2599
2600TEST_P(WebGLCompatibilityTest, LA32FTextures)
2601{
2602 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
2603 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
2604 textureData[1]};
2605
2606 for (auto extension : FloatingPointTextureExtensions)
2607 {
2608 if (strlen(extension) > 0 && extensionRequestable(extension))
2609 {
2610 glRequestExtensionANGLE(extension);
2611 ASSERT_GL_NO_ERROR();
2612 }
2613
2614 // Unsized LA 32F
2615 {
2616 bool texture = extensionEnabled("GL_OES_texture_float");
2617 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2618 bool render = false;
2619 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2620 filter, render, textureData, readPixelData);
2621 }
2622
2623 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2624 {
2625 // Sized LA 32F
2626 bool texture = extensionEnabled("GL_OES_texture_float") &&
2627 extensionEnabled("GL_EXT_texture_storage");
2628 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2629 bool render = false;
2630 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2631 filter, render, textureData, readPixelData);
2632 }
2633 }
2634}
2635
2636TEST_P(WebGLCompatibilityTest, R32FTextures)
2637{
2638 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
2639
2640 for (auto extension : FloatingPointTextureExtensions)
2641 {
2642 if (strlen(extension) > 0 && extensionRequestable(extension))
2643 {
2644 glRequestExtensionANGLE(extension);
2645 ASSERT_GL_NO_ERROR();
2646 }
2647
2648 // Unsized R 32F
2649 {
2650 bool texture =
2651 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
2652 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2653 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2654 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2655 }
2656
2657 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2658 {
2659 // Sized R 32F
2660 bool texture =
2661 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2662 extensionEnabled("GL_EXT_texture_rg") &&
2663 extensionEnabled("GL_EXT_texture_storage"));
2664 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2665 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2666 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2667 }
2668 }
2669}
2670
2671TEST_P(WebGLCompatibilityTest, RG32FTextures)
2672{
2673 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
2674
2675 for (auto extension : FloatingPointTextureExtensions)
2676 {
2677 if (strlen(extension) > 0 && extensionRequestable(extension))
2678 {
2679 glRequestExtensionANGLE(extension);
2680 ASSERT_GL_NO_ERROR();
2681 }
2682
2683 // Unsized RG 32F
2684 {
2685 bool texture =
2686 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
2687 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2688 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2689 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2690 }
2691
2692 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2693 {
2694 // Sized RG 32F
2695 bool texture =
2696 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2697 extensionEnabled("GL_EXT_texture_rg") &&
2698 extensionEnabled("GL_EXT_texture_storage"));
2699 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2700 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2701 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2702 }
2703 }
2704}
2705
2706TEST_P(WebGLCompatibilityTest, RGB32FTextures)
2707{
Yunchao He9550c602018-02-13 14:47:05 +08002708 ANGLE_SKIP_TEST_IF(IsLinux() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002709
Geoff Lang677bb6f2017-04-05 12:40:40 -04002710 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
2711
2712 for (auto extension : FloatingPointTextureExtensions)
2713 {
2714 if (strlen(extension) > 0 && extensionRequestable(extension))
2715 {
2716 glRequestExtensionANGLE(extension);
2717 ASSERT_GL_NO_ERROR();
2718 }
2719
2720 // Unsized RGB 32F
2721 {
2722 bool texture = extensionEnabled("GL_OES_texture_float");
2723 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2724 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2725 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
2726 }
2727
2728 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2729 {
2730 // Sized RGBA 32F
2731 bool texture =
2732 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2733 extensionEnabled("GL_EXT_texture_storage"));
2734 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2735 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2736 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
2737 data);
2738 }
2739 }
2740}
2741
2742TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
2743{
2744 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2745
2746 for (auto extension : FloatingPointTextureExtensions)
2747 {
2748 if (strlen(extension) > 0 && extensionRequestable(extension))
2749 {
2750 glRequestExtensionANGLE(extension);
2751 ASSERT_GL_NO_ERROR();
2752 }
2753
2754 // Unsized RGBA 32F
2755 {
2756 bool texture = extensionEnabled("GL_OES_texture_float");
2757 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2758 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2759 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2760 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
2761 }
2762
2763 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2764 {
2765 // Sized RGBA 32F
2766 bool texture =
2767 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2768 extensionEnabled("GL_EXT_texture_storage"));
2769 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2770 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2771 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2772 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
2773 data);
2774 }
2775 }
2776}
2777
2778TEST_P(WebGLCompatibilityTest, R16FTextures)
2779{
2780 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
2781 const GLushort textureData[] = {
2782 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2783 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2784
2785 for (auto extension : FloatingPointTextureExtensions)
2786 {
2787 if (strlen(extension) > 0 && extensionRequestable(extension))
2788 {
2789 glRequestExtensionANGLE(extension);
2790 ASSERT_GL_NO_ERROR();
2791 }
2792
2793 // Unsized R 16F (OES)
2794 {
2795 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2796 extensionEnabled("GL_EXT_texture_rg");
2797 bool filter = getClientMajorVersion() >= 3 ||
2798 extensionEnabled("GL_OES_texture_half_float_linear");
2799 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2800 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2801 textureData, readPixelsData);
2802 }
2803
2804 // Unsized R 16F
2805 {
2806 bool texture = false;
2807 bool filter = false;
2808 bool render = false;
2809 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2810 textureData, readPixelsData);
2811 }
2812
2813 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2814 {
2815 // Sized R 16F
2816 bool texture = getClientMajorVersion() >= 3;
2817 bool filter = getClientMajorVersion() >= 3 ||
2818 extensionEnabled("GL_OES_texture_half_float_linear");
2819 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2820 extensionEnabled("GL_EXT_color_buffer_float");
2821 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2822 textureData, readPixelsData);
2823 }
2824 }
2825}
2826
2827TEST_P(WebGLCompatibilityTest, RG16FTextures)
2828{
2829 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
2830 const GLushort textureData[] = {
2831 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2832 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2833
2834 for (auto extension : FloatingPointTextureExtensions)
2835 {
2836 if (strlen(extension) > 0 && extensionRequestable(extension))
2837 {
2838 glRequestExtensionANGLE(extension);
2839 ASSERT_GL_NO_ERROR();
2840 }
2841
2842 // Unsized RG 16F (OES)
2843 {
2844 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2845 extensionEnabled("GL_EXT_texture_rg");
2846 bool filter = getClientMajorVersion() >= 3 ||
2847 extensionEnabled("GL_OES_texture_half_float_linear");
2848 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
2849 extensionEnabled("GL_EXT_texture_rg");
2850 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2851 textureData, readPixelsData);
2852 }
2853
2854 // Unsized RG 16F
2855 {
2856 bool texture = false;
2857 bool filter = false;
2858 bool render = false;
2859 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2860 textureData, readPixelsData);
2861 }
2862
2863 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2864 {
2865 // Sized RG 16F
2866 bool texture = getClientMajorVersion() >= 3;
2867 bool filter = getClientMajorVersion() >= 3 ||
2868 extensionEnabled("GL_OES_texture_half_float_linear");
2869 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2870 extensionEnabled("GL_EXT_color_buffer_float");
2871 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2872 textureData, readPixelsData);
2873 }
2874 }
2875}
2876
2877TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2878{
Yunchao He9550c602018-02-13 14:47:05 +08002879 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002880
Geoff Lang677bb6f2017-04-05 12:40:40 -04002881 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2882 const GLushort textureData[] = {
2883 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2884 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2885
2886 for (auto extension : FloatingPointTextureExtensions)
2887 {
2888 if (strlen(extension) > 0 && extensionRequestable(extension))
2889 {
2890 glRequestExtensionANGLE(extension);
2891 ASSERT_GL_NO_ERROR();
2892 }
2893
2894 // Unsized RGB 16F (OES)
2895 {
2896 bool texture = extensionEnabled("GL_OES_texture_half_float");
2897 bool filter = getClientMajorVersion() >= 3 ||
2898 extensionEnabled("GL_OES_texture_half_float_linear");
2899 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2900 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2901 textureData, readPixelsData);
2902 }
2903
2904 // Unsized RGB 16F
2905 {
2906 bool texture = false;
2907 bool filter = false;
2908 bool render = false;
2909 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2910 textureData, readPixelsData);
2911 }
2912
2913 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2914 {
2915 // Sized RGB 16F
2916 bool texture = getClientMajorVersion() >= 3;
2917 bool filter = getClientMajorVersion() >= 3 ||
2918 extensionEnabled("GL_OES_texture_half_float_linear");
2919 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2920 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2921 textureData, readPixelsData);
2922 }
2923 }
2924}
2925
2926TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2927{
Yunchao He9550c602018-02-13 14:47:05 +08002928 ANGLE_SKIP_TEST_IF(IsOzone() && IsIntel());
Geoff Lang40762ef2017-05-08 13:47:03 -04002929
Geoff Lang677bb6f2017-04-05 12:40:40 -04002930 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2931 const GLushort textureData[] = {
2932 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2933 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2934
2935 for (auto extension : FloatingPointTextureExtensions)
2936 {
2937 if (strlen(extension) > 0 && extensionRequestable(extension))
2938 {
2939 glRequestExtensionANGLE(extension);
2940 ASSERT_GL_NO_ERROR();
2941 }
2942
2943 // Unsized RGBA 16F (OES)
2944 {
2945 bool texture = extensionEnabled("GL_OES_texture_half_float");
2946 bool filter = getClientMajorVersion() >= 3 ||
2947 extensionEnabled("GL_OES_texture_half_float_linear");
2948 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2949 extensionEnabled("GL_EXT_color_buffer_float");
2950 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2951 textureData, readPixelsData);
2952 }
2953
2954 // Unsized RGBA 16F
2955 {
2956 bool texture = false;
2957 bool filter = false;
2958 bool render = false;
2959 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2960 textureData, readPixelsData);
2961 }
2962
2963 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2964 {
2965 // Sized RGBA 16F
2966 bool texture = getClientMajorVersion() >= 3;
2967 bool filter = getClientMajorVersion() >= 3 ||
2968 extensionEnabled("GL_OES_texture_half_float_linear");
2969 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2970 extensionEnabled("GL_EXT_color_buffer_float");
2971 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2972 textureData, readPixelsData);
2973 }
2974 }
2975}
2976
Geoff Lang6e898aa2017-06-02 11:17:26 -04002977// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2978// accepted by glTexImage2D
2979TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2980{
Yunchao He9550c602018-02-13 14:47:05 +08002981 // Test skipped because it is only valid for WebGL1 contexts.
2982 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
Geoff Lang6e898aa2017-06-02 11:17:26 -04002983
Yunchao He9550c602018-02-13 14:47:05 +08002984 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_OES_texture_float"));
2985
Geoff Lang6e898aa2017-06-02 11:17:26 -04002986 glRequestExtensionANGLE("GL_OES_texture_float");
2987 ASSERT_GL_NO_ERROR();
2988
2989 GLTexture texture;
2990 glBindTexture(GL_TEXTURE_2D, texture);
2991
2992 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2993 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2994
2995 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2996 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2997
2998 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2999 {
3000 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
3001 ASSERT_GL_NO_ERROR();
3002
3003 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3004 EXPECT_GL_NO_ERROR();
3005 }
3006
3007 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
3008 {
3009 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
3010 ASSERT_GL_NO_ERROR();
3011
3012 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
3013 EXPECT_GL_NO_ERROR();
3014 }
3015}
3016
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003017// Verify GL_DEPTH_STENCIL_ATTACHMENT is a valid attachment point.
3018TEST_P(WebGLCompatibilityTest, DepthStencilAttachment)
3019{
3020 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3021
3022 // Test that attaching a bound texture succeeds.
3023 GLTexture texture;
3024 glBindTexture(GL_TEXTURE_2D, texture);
3025
3026 GLFramebuffer fbo;
3027 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3028
3029 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, texture, 0);
3030
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003031 GLint attachmentType = 0;
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003032 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003033 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003034 EXPECT_GL_NO_ERROR();
3035 EXPECT_GLENUM_EQ(GL_TEXTURE, attachmentType);
3036
3037 // Test when if no attach object at the named attachment point and pname is not OBJECT_TYPE.
3038 GLFramebuffer fbo2;
3039 glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
3040
3041 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003042 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &attachmentType);
Bryan Bernhart (Intel Americas Inc)491b0d62017-11-10 12:48:22 -08003043 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3044}
3045
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003046// Verify framebuffer attachments return expected types when in an inconsistant state.
3047TEST_P(WebGLCompatibilityTest, FramebufferAttachmentConsistancy)
3048{
3049 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3050
3051 GLFramebuffer fbo;
3052 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3053
3054 GLRenderbuffer rb1;
3055 glBindRenderbuffer(GL_RENDERBUFFER, rb1);
3056
3057 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb1);
3058
3059 GLint attachmentType = 0;
3060 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
3061 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3062
3063 EXPECT_GL_NO_ERROR();
3064 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3065
3066 GLRenderbuffer rb2;
3067 glBindRenderbuffer(GL_RENDERBUFFER, rb2);
3068
3069 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3070
3071 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT,
3072 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3073
3074 EXPECT_GL_NO_ERROR();
3075 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)5f198102017-12-12 14:21:39 -08003076
3077 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb2);
3078
3079 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3080 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3081
3082 EXPECT_GL_NO_ERROR();
3083 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
3084
3085 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb2);
3086
3087 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
3088 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &attachmentType);
3089
3090 EXPECT_GL_NO_ERROR();
3091 EXPECT_GLENUM_EQ(GL_RENDERBUFFER, attachmentType);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08003092}
3093
Jamie Madill07be8bf2017-02-02 19:59:57 -05003094// This tests that rendering feedback loops works as expected with WebGL 2.
3095// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
3096TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
3097{
3098 const std::string vertexShader =
3099 "#version 300 es\n"
3100 "in vec4 aPosition;\n"
3101 "out vec2 texCoord;\n"
3102 "void main() {\n"
3103 " gl_Position = aPosition;\n"
3104 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3105 "}\n";
3106
3107 const std::string fragmentShader =
3108 "#version 300 es\n"
3109 "precision mediump float;\n"
3110 "uniform sampler2D tex;\n"
3111 "in vec2 texCoord;\n"
3112 "out vec4 oColor;\n"
3113 "void main() {\n"
3114 " oColor = texture(tex, texCoord);\n"
3115 "}\n";
3116
3117 GLsizei width = 8;
3118 GLsizei height = 8;
3119
3120 GLint maxDrawBuffers = 0;
3121 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3122 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
3123 ASSERT_GE(maxDrawBuffers, 2);
3124
3125 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3126 glUseProgram(program.get());
3127 glViewport(0, 0, width, height);
3128
3129 GLTexture tex0;
3130 GLTexture tex1;
3131 GLFramebuffer fbo;
3132 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3133 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3134 ASSERT_GL_NO_ERROR();
3135
3136 glBindTexture(GL_TEXTURE_2D, tex1.get());
3137 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3138 ASSERT_NE(-1, texLoc);
3139 glUniform1i(texLoc, 0);
3140
3141 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
3142 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3143 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3144 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
3145 ASSERT_GL_NO_ERROR();
3146
3147 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
3148 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
3149 GL_INVALID_OPERATION);
3150 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
3151}
3152
Jamie Madill1d37bc52017-02-02 19:59:58 -05003153// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
3154// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
3155TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
3156{
3157 const std::string vertexShader =
3158 "#version 300 es\n"
3159 "in vec4 aPosition;\n"
3160 "out vec2 texCoord;\n"
3161 "void main() {\n"
3162 " gl_Position = aPosition;\n"
3163 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
3164 "}\n";
3165
3166 const std::string fragmentShader =
3167 "#version 300 es\n"
3168 "precision mediump float;\n"
3169 "uniform sampler2D tex;\n"
3170 "in vec2 texCoord;\n"
3171 "out vec4 oColor;\n"
3172 "void main() {\n"
3173 " oColor = texture(tex, texCoord);\n"
3174 "}\n";
3175
3176 GLsizei width = 8;
3177 GLsizei height = 8;
3178
3179 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3180 glUseProgram(program.get());
3181
3182 glViewport(0, 0, width, height);
3183
3184 GLint texLoc = glGetUniformLocation(program.get(), "tex");
3185 glUniform1i(texLoc, 0);
3186
3187 // Create textures and allocate storage
3188 GLTexture tex0;
3189 GLTexture tex1;
3190 GLRenderbuffer rb;
3191 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
3192 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
3193 GL_UNSIGNED_INT);
3194 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
3195 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
3196 ASSERT_GL_NO_ERROR();
3197
3198 GLFramebuffer fbo;
3199 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
3200 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
3201
3202 // Test rendering and sampling feedback loop for depth buffer
3203 glBindTexture(GL_TEXTURE_2D, tex1.get());
3204 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
3205 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3206
3207 // The same image is used as depth buffer during rendering.
3208 glEnable(GL_DEPTH_TEST);
3209 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3210 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3211
3212 // The same image is used as depth buffer. But depth mask is false.
3213 glDepthMask(GL_FALSE);
3214 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3215 EXPECT_GL_NO_ERROR();
3216
3217 // The same image is used as depth buffer. But depth test is not enabled during rendering.
3218 glDepthMask(GL_TRUE);
3219 glDisable(GL_DEPTH_TEST);
3220 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3221 EXPECT_GL_NO_ERROR();
3222
3223 // Test rendering and sampling feedback loop for stencil buffer
3224 glBindTexture(GL_RENDERBUFFER, rb.get());
3225 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
3226 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
3227 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
3228 constexpr GLint stencilClearValue = 0x40;
3229 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
3230
3231 // The same image is used as stencil buffer during rendering.
3232 glEnable(GL_STENCIL_TEST);
3233 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3234 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3235
3236 // The same image is used as stencil buffer. But stencil mask is zero.
3237 glStencilMask(0x0);
3238 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3239 EXPECT_GL_NO_ERROR();
3240
3241 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
3242 glStencilMask(0xffff);
3243 glDisable(GL_STENCIL_TEST);
3244 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
3245 EXPECT_GL_NO_ERROR();
3246}
3247
Jamie Madillfd3dd432017-02-02 19:59:59 -05003248// The source and the target for CopyTexSubImage3D are the same 3D texture.
3249// But the level of the 3D texture != the level of the read attachment.
3250TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
3251{
3252 GLTexture texture;
3253 GLFramebuffer framebuffer;
3254
3255 glBindTexture(GL_TEXTURE_3D, texture.get());
3256 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3257
3258 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3259 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3260 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
3261 ASSERT_GL_NO_ERROR();
3262
3263 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3264 EXPECT_GL_NO_ERROR();
3265}
3266
3267// The source and the target for CopyTexSubImage3D are the same 3D texture.
3268// But the zoffset of the 3D texture != the layer of the read attachment.
3269TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
3270{
3271 GLTexture texture;
3272 GLFramebuffer framebuffer;
3273
3274 glBindTexture(GL_TEXTURE_3D, texture.get());
3275 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3276
3277 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3278 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
3279 ASSERT_GL_NO_ERROR();
3280
3281 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
3282 EXPECT_GL_NO_ERROR();
3283}
3284
3285// The source and the target for CopyTexSubImage3D are the same 3D texture.
3286// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
3287TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
3288{
3289 GLTexture texture;
3290 GLFramebuffer framebuffer;
3291
3292 glBindTexture(GL_TEXTURE_3D, texture.get());
3293 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3294
3295 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3296 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3297 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3298 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
3299 ASSERT_GL_NO_ERROR();
3300
3301 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
3302 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3303}
3304
Corentin Wallez59c41592017-07-11 13:19:54 -04003305// Verify that errors are generated when there isn't a defined conversion between the clear type and
3306// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04003307TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
3308{
Yunchao He9550c602018-02-13 14:47:05 +08003309 // Test skipped for D3D11 because it generates D3D11 runtime warnings.
3310 ANGLE_SKIP_TEST_IF(IsD3D11());
Geoff Lang76e65652017-03-27 14:58:02 -04003311
3312 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3313 constexpr int clearInt[] = {0, 0, 0, 0};
3314 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3315
3316 GLTexture texture;
3317 GLFramebuffer framebuffer;
3318
3319 glBindTexture(GL_TEXTURE_2D, texture.get());
3320 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
3321
3322 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
3323 ASSERT_GL_NO_ERROR();
3324
3325 // Unsigned integer buffer
3326 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
3327 ASSERT_GL_NO_ERROR();
3328
3329 glClearBufferfv(GL_COLOR, 0, clearFloat);
3330 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3331
3332 glClearBufferiv(GL_COLOR, 0, clearInt);
3333 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3334
3335 glClearBufferuiv(GL_COLOR, 0, clearUint);
3336 EXPECT_GL_NO_ERROR();
3337
3338 glClear(GL_COLOR_BUFFER_BIT);
3339 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3340
3341 // Integer buffer
3342 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
3343 ASSERT_GL_NO_ERROR();
3344
3345 glClearBufferfv(GL_COLOR, 0, clearFloat);
3346 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3347
3348 glClearBufferiv(GL_COLOR, 0, clearInt);
3349 EXPECT_GL_NO_ERROR();
3350
3351 glClearBufferuiv(GL_COLOR, 0, clearUint);
3352 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3353
3354 glClear(GL_COLOR_BUFFER_BIT);
3355 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3356
3357 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04003358 if (extensionRequestable("GL_EXT_color_buffer_float"))
3359 {
3360 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3361 }
Geoff Lang76e65652017-03-27 14:58:02 -04003362
Geoff Lang677bb6f2017-04-05 12:40:40 -04003363 if (extensionEnabled("GL_EXT_color_buffer_float"))
3364 {
3365 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
3366 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003367
Geoff Lang677bb6f2017-04-05 12:40:40 -04003368 glClearBufferfv(GL_COLOR, 0, clearFloat);
3369 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04003370
Geoff Lang677bb6f2017-04-05 12:40:40 -04003371 glClearBufferiv(GL_COLOR, 0, clearInt);
3372 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04003373
Geoff Lang677bb6f2017-04-05 12:40:40 -04003374 glClearBufferuiv(GL_COLOR, 0, clearUint);
3375 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3376
3377 glClear(GL_COLOR_BUFFER_BIT);
3378 EXPECT_GL_NO_ERROR();
3379 }
Geoff Lang76e65652017-03-27 14:58:02 -04003380
3381 // Normalized uint buffer
3382 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3383 ASSERT_GL_NO_ERROR();
3384
3385 glClearBufferfv(GL_COLOR, 0, clearFloat);
3386 EXPECT_GL_NO_ERROR();
3387
3388 glClearBufferiv(GL_COLOR, 0, clearInt);
3389 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3390
3391 glClearBufferuiv(GL_COLOR, 0, clearUint);
3392 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3393
3394 glClear(GL_COLOR_BUFFER_BIT);
3395 EXPECT_GL_NO_ERROR();
3396}
3397
Corentin Wallez59c41592017-07-11 13:19:54 -04003398// Test the interaction of WebGL compatibility clears with default framebuffers
3399TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
3400{
3401 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
3402 constexpr int clearInt[] = {0, 0, 0, 0};
3403 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
3404
3405 // glClear works as usual, this is also a regression test for a bug where we
3406 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
3407 glClear(GL_COLOR_BUFFER_BIT);
3408 EXPECT_GL_NO_ERROR();
3409
3410 // Default framebuffers are normalized uints, so only glClearBufferfv works.
3411 glClearBufferfv(GL_COLOR, 0, clearFloat);
3412 EXPECT_GL_NO_ERROR();
3413
3414 glClearBufferiv(GL_COLOR, 0, clearInt);
3415 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3416
3417 glClearBufferuiv(GL_COLOR, 0, clearUint);
3418 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3419}
3420
Geoff Lange4915782017-04-12 15:19:07 -04003421// Verify that errors are generate when trying to blit from an image to itself
3422TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
3423{
3424 GLTexture textures[2];
3425 glBindTexture(GL_TEXTURE_2D, textures[0]);
3426 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3427 glBindTexture(GL_TEXTURE_2D, textures[1]);
3428 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
3429
3430 GLRenderbuffer renderbuffers[2];
3431 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
3432 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3433 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
3434 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
3435
3436 GLFramebuffer framebuffers[2];
3437 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
3438 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
3439
3440 ASSERT_GL_NO_ERROR();
3441
3442 // Same texture
3443 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3444 0);
3445 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3446 0);
3447 ASSERT_GL_NO_ERROR();
3448 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3449 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3450
3451 // Same textures but different renderbuffers
3452 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3453 renderbuffers[0]);
3454 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3455 renderbuffers[1]);
3456 ASSERT_GL_NO_ERROR();
3457 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
3458 ASSERT_GL_NO_ERROR();
3459 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3460 GL_NEAREST);
3461 ASSERT_GL_NO_ERROR();
3462 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3463 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3464 GL_NEAREST);
3465 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3466
3467 // Same renderbuffers but different textures
3468 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
3469 0);
3470 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
3471 0);
3472 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3473 renderbuffers[0]);
3474 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3475 renderbuffers[0]);
3476 ASSERT_GL_NO_ERROR();
3477 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
3478 ASSERT_GL_NO_ERROR();
3479 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3480 GL_NEAREST);
3481 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3482 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
3483 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
3484 GL_NEAREST);
3485 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
3486}
3487
Geoff Lange0cff192017-05-30 13:04:56 -04003488// Verify that errors are generated when the fragment shader output doesn't match the bound color
3489// buffer types
3490TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
3491{
3492 const std::string vertexShader =
3493 "#version 300 es\n"
3494 "void main() {\n"
3495 " gl_Position = vec4(0, 0, 0, 1);\n"
3496 "}\n";
3497
3498 const std::string fragmentShader =
3499 "#version 300 es\n"
3500 "precision mediump float;\n"
3501 "layout(location = 0) out vec4 floatOutput;\n"
3502 "layout(location = 1) out uvec4 uintOutput;\n"
3503 "layout(location = 2) out ivec4 intOutput;\n"
3504 "void main() {\n"
3505 " floatOutput = vec4(0, 0, 0, 1);\n"
3506 " uintOutput = uvec4(0, 0, 0, 1);\n"
3507 " intOutput = ivec4(0, 0, 0, 1);\n"
3508 "}\n";
3509
3510 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3511 glUseProgram(program.get());
3512
3513 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
3514 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
3515 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
3516
3517 GLFramebuffer fbo;
3518 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3519
3520 GLRenderbuffer floatRenderbuffer;
3521 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
3522 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
3523 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3524 floatRenderbuffer);
3525
3526 GLRenderbuffer uintRenderbuffer;
3527 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
3528 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
3529 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3530 uintRenderbuffer);
3531
3532 GLRenderbuffer intRenderbuffer;
3533 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
3534 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
3535 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3536 intRenderbuffer);
3537
3538 ASSERT_GL_NO_ERROR();
3539
3540 GLint maxDrawBuffers = 0;
3541 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3542 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
3543 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
3544 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
3545 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
3546
3547 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
3548
3549 // Check that the correct case generates no errors
3550 glDrawArrays(GL_TRIANGLES, 0, 6);
3551 EXPECT_GL_NO_ERROR();
3552
3553 // Unbind some buffers and verify that there are still no errors
3554 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3555 0);
3556 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3557 0);
3558 glDrawArrays(GL_TRIANGLES, 0, 6);
3559 EXPECT_GL_NO_ERROR();
3560
3561 // Swap the int and uint buffers to and verify that an error is generated
3562 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3563 intRenderbuffer);
3564 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3565 uintRenderbuffer);
3566 glDrawArrays(GL_TRIANGLES, 0, 6);
3567 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3568
3569 // Swap the float and uint buffers to and verify that an error is generated
3570 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3571 floatRenderbuffer);
3572 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3573 uintRenderbuffer);
3574 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3575 intRenderbuffer);
3576 glDrawArrays(GL_TRIANGLES, 0, 6);
3577 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3578}
3579
Geoff Lang9ab5b822017-05-30 16:19:23 -04003580// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
3581// types
Corentin Wallezc3bc9842017-10-11 15:15:59 -04003582TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMismatch)
Geoff Lang9ab5b822017-05-30 16:19:23 -04003583{
3584 const std::string vertexShader =
3585 "#version 300 es\n"
3586 "in vec4 floatInput;\n"
3587 "in uvec4 uintInput;\n"
3588 "in ivec4 intInput;\n"
3589 "void main() {\n"
3590 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
3591 "}\n";
3592
3593 const std::string fragmentShader =
3594 "#version 300 es\n"
3595 "precision mediump float;\n"
3596 "out vec4 outputColor;\n"
3597 "void main() {\n"
3598 " outputColor = vec4(0, 0, 0, 1);"
3599 "}\n";
3600
3601 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3602 glUseProgram(program.get());
3603
3604 GLint floatLocation = glGetAttribLocation(program, "floatInput");
3605 GLint uintLocation = glGetAttribLocation(program, "uintInput");
3606 GLint intLocation = glGetAttribLocation(program, "intInput");
3607
3608 // Default attributes are of float types
3609 glDrawArrays(GL_TRIANGLES, 0, 6);
3610 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3611
3612 // Set the default attributes to the correct types, should succeed
3613 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
3614 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
3615 glDrawArrays(GL_TRIANGLES, 0, 6);
3616 EXPECT_GL_NO_ERROR();
3617
3618 // Change the default float attribute to an integer, should fail
3619 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
3620 glDrawArrays(GL_TRIANGLES, 0, 6);
3621 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3622
3623 // Use a buffer for some attributes
3624 GLBuffer buffer;
3625 glBindBuffer(GL_ARRAY_BUFFER, buffer);
3626 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
3627 glEnableVertexAttribArray(floatLocation);
3628 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3629 glDrawArrays(GL_TRIANGLES, 0, 6);
3630 EXPECT_GL_NO_ERROR();
3631
3632 // Use a float pointer attrib for a uint input
3633 glEnableVertexAttribArray(uintLocation);
3634 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3635 glDrawArrays(GL_TRIANGLES, 0, 6);
3636 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3637
3638 // Use a uint pointer for the uint input
3639 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
3640 glDrawArrays(GL_TRIANGLES, 0, 6);
3641 EXPECT_GL_NO_ERROR();
3642}
3643
Geoff Langfa125c92017-10-24 13:01:46 -04003644// Test that it's not possible to query the non-zero color attachments without the drawbuffers
3645// extension in WebGL1
3646TEST_P(WebGLCompatibilityTest, FramebufferAttachmentQuery)
3647{
3648 ANGLE_SKIP_TEST_IF(getClientMajorVersion() > 2);
3649 ANGLE_SKIP_TEST_IF(extensionEnabled("GL_EXT_draw_buffers"));
3650
3651 GLFramebuffer fbo;
3652 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3653 EXPECT_GL_NO_ERROR();
3654
3655 GLint result;
3656 glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
3657 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &result);
3658 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3659
3660 GLRenderbuffer renderbuffer;
3661 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
3662 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
3663 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, renderbuffer);
3664 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3665}
3666
Corentin Walleze7557742017-06-01 13:09:57 -04003667// Tests the WebGL removal of undefined behavior when attachments aren't written to.
3668TEST_P(WebGLCompatibilityTest, DrawBuffers)
3669{
Corentin Walleze7557742017-06-01 13:09:57 -04003670 // Make sure we can use at least 4 attachments for the tests.
3671 bool useEXT = false;
3672 if (getClientMajorVersion() < 3)
3673 {
Yunchao He9550c602018-02-13 14:47:05 +08003674 ANGLE_SKIP_TEST_IF(!extensionRequestable("GL_EXT_draw_buffers"));
Corentin Walleze7557742017-06-01 13:09:57 -04003675
3676 glRequestExtensionANGLE("GL_EXT_draw_buffers");
3677 useEXT = true;
3678 EXPECT_GL_NO_ERROR();
3679 }
3680
3681 GLint maxDrawBuffers = 0;
3682 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
Yunchao He9550c602018-02-13 14:47:05 +08003683 // Test skipped because MAX_DRAW_BUFFERS is too small.
3684 ANGLE_SKIP_TEST_IF(maxDrawBuffers < 4);
Corentin Walleze7557742017-06-01 13:09:57 -04003685
3686 // Clears all the renderbuffers to red.
3687 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
3688 GLFramebuffer clearFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003689 glBindFramebuffer(GL_FRAMEBUFFER, clearFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003690
3691 glClearColor(1, 0, 0, 1);
3692 for (int i = 0; i < 4; ++i)
3693 {
Geoff Lange8afa902017-09-27 15:00:43 -04003694 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003695 renderbuffers[i]);
3696 glClear(GL_COLOR_BUFFER_BIT);
3697 }
3698 ASSERT_GL_NO_ERROR();
3699 };
3700
3701 // Checks that the renderbuffers specified by mask have the correct color
3702 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
3703 GLFramebuffer readFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003704 glBindFramebuffer(GL_FRAMEBUFFER, readFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003705
3706 for (int i = 0; i < 4; ++i)
3707 {
3708 if (mask & (1 << i))
3709 {
Geoff Lange8afa902017-09-27 15:00:43 -04003710 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3711 renderbuffers[i]);
Corentin Walleze7557742017-06-01 13:09:57 -04003712 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
3713 }
3714 }
3715 ASSERT_GL_NO_ERROR();
3716 };
3717
3718 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
3719 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
3720 if (useEXT)
3721 {
3722 glDrawBuffersEXT(numBuffers, buffers);
3723 }
3724 else
3725 {
3726 glDrawBuffers(numBuffers, buffers);
3727 }
3728 };
3729
3730 // Initialized the test framebuffer
3731 GLFramebuffer drawFBO;
Geoff Lange8afa902017-09-27 15:00:43 -04003732 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003733
3734 GLRenderbuffer renderbuffers[4];
3735 for (int i = 0; i < 4; ++i)
3736 {
3737 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
Geoff Langd84a00b2017-10-27 17:27:26 -04003738 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, 1, 1);
Geoff Lange8afa902017-09-27 15:00:43 -04003739 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
Corentin Walleze7557742017-06-01 13:09:57 -04003740 renderbuffers[i]);
3741 }
3742
3743 ASSERT_GL_NO_ERROR();
3744
Corentin Walleze7557742017-06-01 13:09:57 -04003745 GLenum allDrawBuffers[] = {
3746 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3747 };
3748
3749 GLenum halfDrawBuffers[] = {
3750 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3751 };
3752
3753 // Test that when using gl_FragColor, only the first attachment is written to.
3754 const char *fragESSL1 =
3755 "precision highp float;\n"
3756 "void main()\n"
3757 "{\n"
3758 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3759 "}\n";
Olli Etuaho5804dc82018-04-13 14:11:46 +03003760 ANGLE_GL_PROGRAM(programESSL1, essl1_shaders::vs::Simple(), fragESSL1);
Corentin Walleze7557742017-06-01 13:09:57 -04003761
3762 {
3763 ClearEverythingToRed(renderbuffers);
3764
Geoff Lange8afa902017-09-27 15:00:43 -04003765 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003766 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003767 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003768 ASSERT_GL_NO_ERROR();
3769
3770 CheckColors(renderbuffers, 0b0001, GLColor::green);
3771 CheckColors(renderbuffers, 0b1110, GLColor::red);
3772 }
3773
3774 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
3775 // written to.
3776 {
3777 ClearEverythingToRed(renderbuffers);
3778
Geoff Lange8afa902017-09-27 15:00:43 -04003779 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003780 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003781 drawQuad(programESSL1, essl1_shaders::PositionAttrib(), 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003782 ASSERT_GL_NO_ERROR();
3783
3784 CheckColors(renderbuffers, 0b1111, GLColor::red);
3785 }
3786
3787 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
3788 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
3789 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
3790 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
3791 // attachments not declared in the shader should not be written to.
Olli Etuaho5804dc82018-04-13 14:11:46 +03003792 const char *positionAttrib;
Corentin Walleze7557742017-06-01 13:09:57 -04003793 const char *writeOddOutputsVert;
3794 const char *writeOddOutputsFrag;
3795 GLColor unwrittenColor;
3796 if (useEXT)
3797 {
3798 // In the extension, when an attachment isn't written to, it should get 0's
3799 unwrittenColor = GLColor(0, 0, 0, 0);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003800 positionAttrib = essl1_shaders::PositionAttrib();
3801 writeOddOutputsVert = essl1_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003802 writeOddOutputsFrag =
3803 "#extension GL_EXT_draw_buffers : require\n"
3804 "precision highp float;\n"
3805 "void main()\n"
3806 "{\n"
3807 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3808 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3809 "}\n";
3810 }
3811 else
3812 {
3813 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
3814 // because of the preceding clears.
3815 unwrittenColor = GLColor::red;
Olli Etuaho5804dc82018-04-13 14:11:46 +03003816 positionAttrib = essl3_shaders::PositionAttrib();
3817 writeOddOutputsVert = essl3_shaders::vs::Simple();
Corentin Walleze7557742017-06-01 13:09:57 -04003818 writeOddOutputsFrag =
3819 "#version 300 es\n"
3820 "precision highp float;\n"
3821 "layout(location = 1) out vec4 output1;"
3822 "layout(location = 3) out vec4 output2;"
3823 "void main()\n"
3824 "{\n"
3825 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3826 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3827 "}\n";
3828 }
3829 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
3830
3831 // Test that attachments not written to get the "unwritten" color
3832 {
3833 ClearEverythingToRed(renderbuffers);
3834
Geoff Lange8afa902017-09-27 15:00:43 -04003835 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003836 DrawBuffers(useEXT, 4, allDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003837 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003838 ASSERT_GL_NO_ERROR();
3839
3840 CheckColors(renderbuffers, 0b1010, GLColor::green);
3841 CheckColors(renderbuffers, 0b0101, unwrittenColor);
3842 }
3843
3844 // Test that attachments not written to get the "unwritten" color but that even when the
3845 // extension is used, disabled attachments are not written at all and stay red.
3846 {
3847 ClearEverythingToRed(renderbuffers);
3848
Geoff Lange8afa902017-09-27 15:00:43 -04003849 glBindFramebuffer(GL_FRAMEBUFFER, drawFBO);
Corentin Walleze7557742017-06-01 13:09:57 -04003850 DrawBuffers(useEXT, 4, halfDrawBuffers);
Olli Etuaho5804dc82018-04-13 14:11:46 +03003851 drawQuad(writeOddOutputsProgram, positionAttrib, 0.5, 1.0, true);
Corentin Walleze7557742017-06-01 13:09:57 -04003852 ASSERT_GL_NO_ERROR();
3853
3854 CheckColors(renderbuffers, 0b1000, GLColor::green);
3855 CheckColors(renderbuffers, 0b0100, unwrittenColor);
3856 CheckColors(renderbuffers, 0b0011, GLColor::red);
3857 }
3858}
3859
Geoff Lang536eca12017-09-13 11:23:35 -04003860// Test that it's possible to generate mipmaps on unsized floating point textures once the
3861// extensions have been enabled
3862TEST_P(WebGLCompatibilityTest, GenerateMipmapUnsizedFloatingPointTexture)
3863{
3864 if (extensionRequestable("GL_OES_texture_float"))
3865 {
3866 glRequestExtensionANGLE("GL_OES_texture_float");
3867 }
3868 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3869
3870 GLTexture texture;
3871 glBindTexture(GL_TEXTURE_2D, texture);
3872
3873 constexpr GLColor32F data[4] = {
3874 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3875 };
3876 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_FLOAT, data);
3877 ASSERT_GL_NO_ERROR();
3878
3879 glGenerateMipmap(GL_TEXTURE_2D);
3880 EXPECT_GL_NO_ERROR();
3881}
3882// Test that it's possible to generate mipmaps on unsized floating point textures once the
3883// extensions have been enabled
3884TEST_P(WebGLCompatibilityTest, GenerateMipmapSizedFloatingPointTexture)
3885{
3886 if (extensionRequestable("GL_OES_texture_float"))
3887 {
3888 glRequestExtensionANGLE("GL_OES_texture_float");
3889 }
3890 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3891
3892 if (extensionRequestable("GL_EXT_texture_storage"))
3893 {
3894 glRequestExtensionANGLE("GL_EXT_texture_storage");
3895 }
3896 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage"));
3897
3898 GLTexture texture;
3899 glBindTexture(GL_TEXTURE_2D, texture);
3900
3901 constexpr GLColor32F data[4] = {
3902 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3903 };
3904 glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA32F, 2, 2);
3905 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_FLOAT, data);
3906 ASSERT_GL_NO_ERROR();
3907
3908 glGenerateMipmap(GL_TEXTURE_2D);
3909 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3910
3911 if (extensionRequestable("GL_EXT_color_buffer_float"))
3912 {
3913 // Format is renderable but not filterable
3914 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3915 glGenerateMipmap(GL_TEXTURE_2D);
3916 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3917 }
3918
3919 if (extensionRequestable("GL_EXT_color_buffer_float_linear"))
3920 {
3921 // Format is renderable but not filterable
3922 glRequestExtensionANGLE("GL_EXT_color_buffer_float_linear");
3923
3924 if (extensionEnabled("GL_EXT_color_buffer_float"))
3925 {
3926 // Format is filterable and renderable
3927 glGenerateMipmap(GL_TEXTURE_2D);
3928 EXPECT_GL_NO_ERROR();
3929 }
3930 else
3931 {
3932 // Format is filterable but not renderable
3933 glGenerateMipmap(GL_TEXTURE_2D);
3934 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3935 }
3936 }
3937}
3938
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003939// Verify that a texture format is only allowed with extension enabled.
3940void WebGLCompatibilityTest::validateTexImageExtensionFormat(GLenum format,
3941 const std::string &extName)
3942{
3943 // Verify texture format fails by default.
3944 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3945 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3946
3947 if (extensionRequestable(extName))
3948 {
3949 // Verify texture format is allowed once extension is enabled.
3950 glRequestExtensionANGLE(extName.c_str());
3951 EXPECT_TRUE(extensionEnabled(extName));
3952
3953 glTexImage2D(GL_TEXTURE_2D, 0, format, 1, 1, 0, format, GL_UNSIGNED_BYTE, nullptr);
3954 ASSERT_GL_NO_ERROR();
3955 }
3956}
3957
Geoff Lang86f81162017-10-30 15:10:45 -04003958// Test enabling various non-compressed texture format extensions
3959TEST_P(WebGLCompatibilityTest, EnableTextureFormatExtensions)
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003960{
Geoff Lang2c5c41f2017-10-31 10:58:09 -04003961 ANGLE_SKIP_TEST_IF(IsOzone());
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003962 ANGLE_SKIP_TEST_IF(getClientMajorVersion() != 2);
3963
3964 GLTexture texture;
3965 glBindTexture(GL_TEXTURE_2D, texture.get());
3966
3967 // Verify valid format is allowed.
3968 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
3969 ASSERT_GL_NO_ERROR();
3970
3971 // Verify invalid format fails.
3972 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA32F, GL_UNSIGNED_BYTE, nullptr);
3973 EXPECT_GL_ERROR(GL_INVALID_ENUM);
3974
3975 // Verify formats from enableable extensions.
Geoff Lang660b28c2017-10-30 12:58:56 -04003976 if (!IsOpenGLES())
Bryan Bernhart (Intel Americas Inc)2a357412017-09-05 10:42:47 -07003977 {
3978 validateTexImageExtensionFormat(GL_RED_EXT, "GL_EXT_texture_rg");
3979 }
3980
3981 validateTexImageExtensionFormat(GL_SRGB_EXT, "GL_EXT_texture_sRGB");
3982 validateTexImageExtensionFormat(GL_BGRA_EXT, "GL_EXT_texture_format_BGRA8888");
3983}
3984
Geoff Lang86f81162017-10-30 15:10:45 -04003985void WebGLCompatibilityTest::validateCompressedTexImageExtensionFormat(GLenum format,
3986 GLsizei width,
3987 GLsizei height,
3988 GLsizei blockSize,
3989 const std::string &extName,
3990 bool subImageAllowed)
3991{
3992 std::vector<GLubyte> data(blockSize, 0u);
3993
3994 GLTexture texture;
3995 glBindTexture(GL_TEXTURE_2D, texture.get());
3996
3997 // Verify texture format fails by default.
3998 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
3999 EXPECT_GL_ERROR(GL_INVALID_ENUM);
4000
4001 if (extensionRequestable(extName))
4002 {
4003 // Verify texture format is allowed once extension is enabled.
4004 glRequestExtensionANGLE(extName.c_str());
4005 EXPECT_TRUE(extensionEnabled(extName));
4006
4007 glCompressedTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, blockSize, data.data());
4008 EXPECT_GL_NO_ERROR();
4009
4010 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, blockSize,
4011 data.data());
4012 if (subImageAllowed)
4013 {
4014 EXPECT_GL_NO_ERROR();
4015 }
4016 else
4017 {
4018 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4019 }
4020 }
4021}
4022
4023// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGB_S3TC_DXT1_EXT
4024TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGB)
4025{
4026 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 8,
4027 "GL_EXT_texture_compression_dxt1", true);
4028}
4029
4030// Test enabling GL_EXT_texture_compression_dxt1 for GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
4031TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1RGBA)
4032{
4033 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 8,
4034 "GL_EXT_texture_compression_dxt1", true);
4035}
4036
4037// Test enabling GL_ANGLE_texture_compression_dxt3
4038TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3)
4039{
4040 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 16,
4041 "GL_ANGLE_texture_compression_dxt3", true);
4042}
4043
4044// Test enabling GL_ANGLE_texture_compression_dxt5
4045TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5)
4046{
4047 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 16,
4048 "GL_ANGLE_texture_compression_dxt5", true);
4049}
4050
4051// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
4052TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGB)
4053{
4054 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 8,
4055 "GL_EXT_texture_compression_s3tc_srgb", true);
4056}
4057
4058// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
4059TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT1SRGBA)
4060{
4061 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 8,
4062 "GL_EXT_texture_compression_s3tc_srgb", true);
4063}
4064
4065// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
4066TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT3SRGBA)
4067{
4068 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 16,
4069 "GL_EXT_texture_compression_s3tc_srgb", true);
4070}
4071
4072// Test enabling GL_EXT_texture_compression_s3tc_srgb for GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
4073TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionDXT5SRGBA)
4074{
4075 validateCompressedTexImageExtensionFormat(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 16,
4076 "GL_EXT_texture_compression_s3tc_srgb", true);
4077}
4078
4079// Test enabling GL_OES_compressed_ETC1_RGB8_texture
4080TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionETC1)
4081{
4082 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_OES, 4, 4, 8,
4083 "GL_OES_compressed_ETC1_RGB8_texture", false);
4084}
4085
4086// Test enabling GL_ANGLE_lossy_etc_decode
4087TEST_P(WebGLCompatibilityTest, EnableCompressedTextureExtensionLossyDecode)
4088{
4089 validateCompressedTexImageExtensionFormat(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 8,
4090 "GL_ANGLE_lossy_etc_decode", true);
4091}
4092
Frank Henigmanfccbac22017-05-28 17:29:26 -04004093// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
4094// qualifiers.
4095TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
4096{
4097 const std::string vertexShader =
4098 "#version 300 es\n"
4099 "uniform Block { mediump vec4 val; };\n"
4100 "void main() { gl_Position = val; }\n";
4101 const std::string fragmentShader =
4102 "#version 300 es\n"
4103 "uniform Block { highp vec4 val; };\n"
4104 "out highp vec4 out_FragColor;\n"
4105 "void main() { out_FragColor = val; }\n";
4106
4107 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
4108 ASSERT_NE(0u, vs);
4109 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
4110 ASSERT_NE(0u, fs);
4111
4112 GLuint program = glCreateProgram();
4113
4114 glAttachShader(program, vs);
4115 glDeleteShader(vs);
4116 glAttachShader(program, fs);
4117 glDeleteShader(fs);
4118
4119 glLinkProgram(program);
4120 GLint linkStatus;
4121 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
4122 ASSERT_EQ(0, linkStatus);
4123
4124 glDeleteProgram(program);
4125}
4126
Geoff Lang69df2422017-07-05 12:42:31 -04004127// Test no attribute vertex shaders
4128TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
4129{
4130 const std::string vertexShader =
4131 "#version 300 es\n"
4132 "void main()\n"
4133 "{\n"
4134 "\n"
4135 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
4136 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
4137 "}";
Geoff Lang69df2422017-07-05 12:42:31 -04004138
Olli Etuaho5804dc82018-04-13 14:11:46 +03004139 ANGLE_GL_PROGRAM(program, vertexShader, essl3_shaders::fs::Red());
Geoff Lang69df2422017-07-05 12:42:31 -04004140 glUseProgram(program);
4141
4142 glDrawArrays(GL_TRIANGLES, 0, 6);
4143 ASSERT_GL_NO_ERROR();
Olli Etuaho5804dc82018-04-13 14:11:46 +03004144 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
Geoff Lang69df2422017-07-05 12:42:31 -04004145}
4146
Brandon Jonesed5b46f2017-07-21 08:39:17 -07004147// Tests bindAttribLocations for length limit
4148TEST_P(WebGL2CompatibilityTest, BindAttribLocationLimitation)
4149{
4150 constexpr int maxLocStringLength = 1024;
4151 const std::string tooLongString(maxLocStringLength + 1, '_');
4152
4153 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
4154
4155 EXPECT_GL_ERROR(GL_INVALID_VALUE);
4156}
4157
Jamie Madill629bb252018-04-20 11:01:33 -04004158// Covers a bug in transform feedback loop detection.
4159TEST_P(WebGL2CompatibilityTest, TransformFeedbackCheckNullDeref)
4160{
4161 constexpr char kVS[] = R"(attribute vec4 color; void main() { color.r; })";
4162 constexpr char kFS[] = R"(void main(){})";
4163 ANGLE_GL_PROGRAM(program, kVS, kFS);
4164 glUseProgram(program);
4165
4166 GLBuffer buffer;
4167 glBindBuffer(GL_ARRAY_BUFFER, buffer);
4168 glEnableVertexAttribArray(0);
4169 glDrawArrays(GL_POINTS, 0, 1);
4170
4171 // This should fail because it is trying to pull one vertex from an empty buffer.
4172 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
4173}
4174
Geoff Langc287ea62016-09-16 14:46:51 -04004175// Use this to select which configurations (e.g. which renderer, which GLES major version) these
4176// tests should be run against.
4177ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
4178 ES2_D3D9(),
4179 ES2_D3D11(),
4180 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04004181 ES2_OPENGL(),
4182 ES3_OPENGL(),
4183 ES2_OPENGLES(),
4184 ES3_OPENGLES());
4185
Jamie Madill07be8bf2017-02-02 19:59:57 -05004186ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04004187} // namespace