blob: 9fe6d1e15ba42062e9dd43a42af0ece6d87aa15c [file] [log] [blame]
Geoff Langc287ea62016-09-16 14:46:51 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// WebGLCompatibilityTest.cpp : Tests of the GL_ANGLE_webgl_compatibility extension.
8
9#include "test_utils/ANGLETest.h"
10
Geoff Lang677bb6f2017-04-05 12:40:40 -040011#include "common/mathutil.h"
Geoff Langc287ea62016-09-16 14:46:51 -040012#include "test_utils/gl_raii.h"
13
Frank Henigman146e8a12017-03-02 23:22:37 -050014namespace
15{
16
17bool ConstantColorAndAlphaBlendFunctions(GLenum first, GLenum second)
18{
19 return (first == GL_CONSTANT_COLOR || first == GL_ONE_MINUS_CONSTANT_COLOR) &&
20 (second == GL_CONSTANT_ALPHA || second == GL_ONE_MINUS_CONSTANT_ALPHA);
21}
22
23void CheckBlendFunctions(GLenum src, GLenum dst)
24{
25 if (ConstantColorAndAlphaBlendFunctions(src, dst) ||
26 ConstantColorAndAlphaBlendFunctions(dst, src))
27 {
28 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
29 }
30 else
31 {
32 ASSERT_GL_NO_ERROR();
33 }
34}
35
Geoff Lang677bb6f2017-04-05 12:40:40 -040036// Extensions that affect the ability to use floating point textures
37constexpr const char *FloatingPointTextureExtensions[] = {
38 "",
39 "GL_EXT_texture_storage",
Geoff Lang677bb6f2017-04-05 12:40:40 -040040 "GL_OES_texture_half_float",
41 "GL_OES_texture_half_float_linear",
42 "GL_EXT_color_buffer_half_float",
Geoff Lang7d4602f2017-09-13 10:45:09 -040043 "GL_OES_texture_float",
44 "GL_OES_texture_float_linear",
Geoff Lang677bb6f2017-04-05 12:40:40 -040045 "GL_EXT_color_buffer_float",
46 "GL_CHROMIUM_color_buffer_float_rgba",
47 "GL_CHROMIUM_color_buffer_float_rgb",
48};
49
Frank Henigman146e8a12017-03-02 23:22:37 -050050} // namespace
51
Geoff Langc287ea62016-09-16 14:46:51 -040052namespace angle
53{
54
55class WebGLCompatibilityTest : public ANGLETest
56{
57 protected:
58 WebGLCompatibilityTest()
59 {
60 setWindowWidth(128);
61 setWindowHeight(128);
62 setConfigRedBits(8);
63 setConfigGreenBits(8);
64 setConfigBlueBits(8);
65 setConfigAlphaBits(8);
66 setWebGLCompatibilityEnabled(true);
67 }
68
69 void SetUp() override
70 {
71 ANGLETest::SetUp();
Geoff Langc339c4e2016-11-29 10:37:36 -050072 glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>(
73 eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -040074 }
75
Geoff Lang677bb6f2017-04-05 12:40:40 -040076 template <typename T>
77 void TestFloatTextureFormat(GLenum internalFormat,
78 GLenum format,
79 GLenum type,
80 bool texturingEnabled,
81 bool linearSamplingEnabled,
82 bool renderingEnabled,
83 const T textureData[4],
84 const float floatData[4])
85 {
86 ASSERT_GL_NO_ERROR();
87
88 const std::string samplingVs =
89 "attribute vec4 position;\n"
90 "varying vec2 texcoord;\n"
91 "void main()\n"
92 "{\n"
93 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
94 " texcoord = (position.xy * 0.5) + 0.5;\n"
95 "}\n";
96
97 const std::string samplingFs =
98 "precision mediump float;\n"
99 "uniform sampler2D tex;\n"
100 "uniform vec4 subtractor;\n"
101 "varying vec2 texcoord;\n"
102 "void main()\n"
103 "{\n"
104 " vec4 color = texture2D(tex, texcoord);\n"
105 " if (abs(color.r - subtractor.r) +\n"
106 " abs(color.g - subtractor.g) +\n"
107 " abs(color.b - subtractor.b) +\n"
108 " abs(color.a - subtractor.a) < 8.0)\n"
109 " {\n"
110 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
111 " }\n"
112 " else\n"
113 " {\n"
114 " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
115 " }\n"
116 "}\n";
117
118 ANGLE_GL_PROGRAM(samplingProgram, samplingVs, samplingFs);
119 glUseProgram(samplingProgram.get());
120
121 GLRenderbuffer rbo;
122 glBindRenderbuffer(GL_RENDERBUFFER, rbo.get());
123 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
124
125 GLFramebuffer fbo;
126 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
127 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbo.get());
128
129 GLTexture texture;
130 glBindTexture(GL_TEXTURE_2D, texture.get());
131
132 if (internalFormat == format)
133 {
134 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, 1, 1, 0, format, type, textureData);
135 }
136 else
137 {
138 if (getClientMajorVersion() >= 3)
139 {
140 glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
141 }
142 else
143 {
144 ASSERT_TRUE(extensionEnabled("GL_EXT_texture_storage"));
145 glTexStorage2DEXT(GL_TEXTURE_2D, 1, internalFormat, 1, 1);
146 }
147 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1, 1, format, type, textureData);
148 }
149
150 if (!texturingEnabled)
151 {
152 // Depending on the entry point and client version, different errors may be generated
153 ASSERT_GLENUM_NE(GL_NO_ERROR, glGetError());
154
155 // Two errors may be generated in the glTexStorage + glTexSubImage case, clear the
156 // second error
157 glGetError();
158
159 return;
160 }
161 ASSERT_GL_NO_ERROR();
162
163 glUniform1i(glGetUniformLocation(samplingProgram.get(), "tex"), 0);
164 glUniform4fv(glGetUniformLocation(samplingProgram.get(), "subtractor"), 1, floatData);
165
166 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
167 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
168 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
169 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
170
171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
172 drawQuad(samplingProgram.get(), "position", 0.5f, 1.0f, true);
173
174 if (linearSamplingEnabled)
175 {
176 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
177 }
178 else
179 {
180 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
181 }
182
183 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(),
184 0);
185 glBindTexture(GL_TEXTURE_2D, 0);
186 if (!renderingEnabled)
187 {
188 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT,
189 glCheckFramebufferStatus(GL_FRAMEBUFFER));
190 return;
191 }
192 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
193
194 const std::string renderingVs =
195 "attribute vec4 position;\n"
196 "void main()\n"
197 "{\n"
198 " gl_Position = vec4(position.xy, 0.0, 1.0);\n"
199 "}\n";
200
201 const std::string renderingFs =
202 "precision mediump float;\n"
203 "uniform vec4 writeValue;\n"
204 "void main()\n"
205 "{\n"
206 " gl_FragColor = writeValue;\n"
207 "}\n";
208
209 ANGLE_GL_PROGRAM(renderingProgram, renderingVs, renderingFs);
210 glUseProgram(renderingProgram.get());
211
212 glUniform4fv(glGetUniformLocation(renderingProgram.get(), "writeValue"), 1, floatData);
213
214 drawQuad(renderingProgram.get(), "position", 0.5f, 1.0f, true);
215
216 EXPECT_PIXEL_COLOR32F_NEAR(
217 0, 0, GLColor32F(floatData[0], floatData[1], floatData[2], floatData[3]), 1.0f);
218 }
219
Jamie Madillcad97ee2017-02-02 18:52:44 -0500220 // Called from RenderingFeedbackLoopWithDrawBuffersEXT.
221 void drawBuffersEXTFeedbackLoop(GLuint program,
222 const std::array<GLenum, 2> &drawBuffers,
223 GLenum expectedError);
224
Jamie Madill07be8bf2017-02-02 19:59:57 -0500225 // Called from RenderingFeedbackLoopWithDrawBuffers.
226 void drawBuffersFeedbackLoop(GLuint program,
227 const std::array<GLenum, 2> &drawBuffers,
228 GLenum expectedError);
229
Geoff Langc339c4e2016-11-29 10:37:36 -0500230 PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr;
Geoff Langc287ea62016-09-16 14:46:51 -0400231};
232
Corentin Wallezfd456442016-12-21 17:57:00 -0500233class WebGL2CompatibilityTest : public WebGLCompatibilityTest
234{
235};
236
Geoff Langc287ea62016-09-16 14:46:51 -0400237// Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so
238// the GL extension should always be present
239TEST_P(WebGLCompatibilityTest, ExtensionStringExposed)
240{
241 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
242}
243
244// Verify that all extension entry points are available
245TEST_P(WebGLCompatibilityTest, EntryPoints)
246{
Geoff Langc339c4e2016-11-29 10:37:36 -0500247 if (extensionEnabled("GL_ANGLE_request_extension"))
Geoff Langc287ea62016-09-16 14:46:51 -0400248 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500249 EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE"));
Geoff Langc287ea62016-09-16 14:46:51 -0400250 }
251}
252
253// WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable,
254// even in ES2 contexts.
255TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint)
256{
257 GLRenderbuffer renderbuffer;
258 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
259 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
260
261 GLFramebuffer framebuffer;
262 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
263 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
264 renderbuffer.get());
265
266 EXPECT_GL_NO_ERROR();
267}
268
269// Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION
270TEST_P(WebGLCompatibilityTest, EnableExtensionValidation)
271{
Geoff Langc339c4e2016-11-29 10:37:36 -0500272 glRequestExtensionANGLE("invalid_extension_string");
Geoff Langc287ea62016-09-16 14:46:51 -0400273 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
274}
275
276// Test enabling the GL_OES_element_index_uint extension
277TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices)
278{
279 if (getClientMajorVersion() != 2)
280 {
281 // This test only works on ES2 where uint indices are not available by default
282 return;
283 }
284
285 EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint"));
286
287 GLBuffer indexBuffer;
288 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
289
290 GLuint data[] = {0, 1, 2, 1, 3, 2};
291 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW);
292
293 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
294 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
295 glUseProgram(program.get());
296
Jamie Madille7b96342017-06-23 15:06:08 -0400297 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400298 EXPECT_GL_ERROR(GL_INVALID_ENUM);
299
Geoff Langc339c4e2016-11-29 10:37:36 -0500300 if (extensionRequestable("GL_OES_element_index_uint"))
Geoff Langc287ea62016-09-16 14:46:51 -0400301 {
Geoff Langc339c4e2016-11-29 10:37:36 -0500302 glRequestExtensionANGLE("GL_OES_element_index_uint");
Geoff Langc287ea62016-09-16 14:46:51 -0400303 EXPECT_GL_NO_ERROR();
304 EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint"));
305
Jamie Madille7b96342017-06-23 15:06:08 -0400306 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
Geoff Langc287ea62016-09-16 14:46:51 -0400307 EXPECT_GL_NO_ERROR();
308 }
309}
310
Geoff Langff5c63e2017-04-12 15:26:54 -0400311// Test enabling the GL_OES_standard_derivatives extension
312TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives)
313{
314 EXPECT_FALSE(extensionEnabled("GL_OES_standard_derivatives"));
315
316 const std::string source =
317 "#extension GL_OES_standard_derivatives : require\n"
318 "void main() { gl_FragColor = vec4(dFdx(vec2(1.0, 1.0)).x, 1, 0, 1); }\n";
319 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
320
321 if (extensionRequestable("GL_OES_standard_derivatives"))
322 {
323 glRequestExtensionANGLE("GL_OES_standard_derivatives");
324 EXPECT_GL_NO_ERROR();
325 EXPECT_TRUE(extensionEnabled("GL_OES_standard_derivatives"));
326
327 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
328 ASSERT_NE(0u, shader);
329 glDeleteShader(shader);
330 }
331}
332
333// Test enabling the GL_EXT_shader_texture_lod extension
334TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD)
335{
336 EXPECT_FALSE(extensionEnabled("GL_EXT_shader_texture_lod"));
337
338 const std::string source =
339 "#extension GL_EXT_shader_texture_lod : require\n"
340 "uniform sampler2D u_texture;\n"
341 "void main() {\n"
342 " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, "
343 "0.0));\n"
344 "}\n";
345 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
346
347 if (extensionRequestable("GL_EXT_shader_texture_lod"))
348 {
349 glRequestExtensionANGLE("GL_EXT_shader_texture_lod");
350 EXPECT_GL_NO_ERROR();
351 EXPECT_TRUE(extensionEnabled("GL_EXT_shader_texture_lod"));
352
353 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
354 ASSERT_NE(0u, shader);
355 glDeleteShader(shader);
356 }
357}
358
359// Test enabling the GL_EXT_frag_depth extension
360TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth)
361{
362 EXPECT_FALSE(extensionEnabled("GL_EXT_frag_depth"));
363
364 const std::string source =
365 "#extension GL_EXT_frag_depth : require\n"
366 "void main() {\n"
367 " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n"
368 " gl_FragDepthEXT = 1.0;\n"
369 "}\n";
370 ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source));
371
372 if (extensionRequestable("GL_EXT_frag_depth"))
373 {
374 glRequestExtensionANGLE("GL_EXT_frag_depth");
375 EXPECT_GL_NO_ERROR();
376 EXPECT_TRUE(extensionEnabled("GL_EXT_frag_depth"));
377
378 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
379 ASSERT_NE(0u, shader);
380 glDeleteShader(shader);
381 }
382}
383
Geoff Langd7d526a2017-02-21 16:48:43 -0500384// Test enabling the GL_EXT_texture_filter_anisotropic extension
385TEST_P(WebGLCompatibilityTest, EnableExtensionTextureFilterAnisotropic)
386{
387 EXPECT_FALSE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
388
389 GLfloat maxAnisotropy = 0.0f;
390 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
391 EXPECT_GL_ERROR(GL_INVALID_ENUM);
392
393 GLTexture texture;
394 glBindTexture(GL_TEXTURE_2D, texture.get());
395 ASSERT_GL_NO_ERROR();
396
397 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
398 EXPECT_GL_ERROR(GL_INVALID_ENUM);
399
400 GLfloat currentAnisotropy = 0.0f;
401 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
402 EXPECT_GL_ERROR(GL_INVALID_ENUM);
403
404 if (extensionRequestable("GL_EXT_texture_filter_anisotropic"))
405 {
406 glRequestExtensionANGLE("GL_EXT_texture_filter_anisotropic");
407 EXPECT_GL_NO_ERROR();
408 EXPECT_TRUE(extensionEnabled("GL_EXT_texture_filter_anisotropic"));
409
410 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
411 ASSERT_GL_NO_ERROR();
412 EXPECT_GE(maxAnisotropy, 2.0f);
413
414 glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, &currentAnisotropy);
415 ASSERT_GL_NO_ERROR();
416 EXPECT_EQ(1.0f, currentAnisotropy);
417
418 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);
419 ASSERT_GL_NO_ERROR();
420 }
421}
422
Bryan Bernhart87c182e2016-11-02 11:23:22 -0700423// Verify that shaders are of a compatible spec when the extension is enabled.
424TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec)
425{
426 EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility"));
427
428 // Use of reserved _webgl prefix should fail when the shader specification is for WebGL.
429 const std::string &vert =
430 "struct Foo {\n"
431 " int _webgl_bar;\n"
432 "};\n"
433 "void main()\n"
434 "{\n"
435 " Foo foo = Foo(1);\n"
436 "}";
437
438 // Default fragement shader.
439 const std::string &frag =
440 "void main()\n"
441 "{\n"
442 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n"
443 "}";
444
445 GLuint program = CompileProgram(vert, frag);
446 EXPECT_EQ(0u, program);
447 glDeleteProgram(program);
448}
449
Geoff Lang3fab7632017-09-26 15:45:54 -0400450// Test enabling the GL_NV_pixel_buffer_object extension
451TEST_P(WebGLCompatibilityTest, EnablePixelBufferObjectExtensions)
452{
453 EXPECT_FALSE(extensionEnabled("GL_NV_pixel_buffer_object"));
454 EXPECT_FALSE(extensionEnabled("GL_OES_mapbuffer"));
455 EXPECT_FALSE(extensionEnabled("GL_EXT_map_buffer_range"));
456
457 // These extensions become core in in ES3/WebGL2.
458 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
459
460 GLBuffer buffer;
461 glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
462 EXPECT_GL_ERROR(GL_INVALID_ENUM);
463
464 if (extensionRequestable("GL_NV_pixel_buffer_object"))
465 {
466 glRequestExtensionANGLE("GL_NV_pixel_buffer_object");
467 EXPECT_GL_NO_ERROR();
468
469 glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer);
470 EXPECT_GL_NO_ERROR();
471
472 glBufferData(GL_PIXEL_PACK_BUFFER, 4, nullptr, GL_STATIC_DRAW);
473 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
474 EXPECT_GL_NO_ERROR();
475 }
476}
477
478// Test enabling the GL_OES_mapbuffer and GL_EXT_map_buffer_range extensions
479TEST_P(WebGLCompatibilityTest, EnableMapBufferExtensions)
480{
481 EXPECT_FALSE(extensionEnabled("GL_OES_mapbuffer"));
482 EXPECT_FALSE(extensionEnabled("GL_EXT_map_buffer_range"));
483
484 // These extensions become core in in ES3/WebGL2.
485 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
486
487 GLBuffer buffer;
488 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
489 glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4, nullptr, GL_STATIC_DRAW);
490
491 glMapBufferOES(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
492 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
493
494 glMapBufferRangeEXT(GL_ELEMENT_ARRAY_BUFFER, 0, 4, GL_MAP_WRITE_BIT);
495 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
496
497 GLint access = 0;
498 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
499 EXPECT_GL_ERROR(GL_INVALID_ENUM);
500
501 if (extensionRequestable("GL_OES_mapbuffer"))
502 {
503 glRequestExtensionANGLE("GL_OES_mapbuffer");
504 EXPECT_GL_NO_ERROR();
505
506 glMapBufferOES(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY_OES);
507 glUnmapBufferOES(GL_ELEMENT_ARRAY_BUFFER);
508 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
509 EXPECT_GL_NO_ERROR();
510 }
511
512 if (extensionRequestable("GL_EXT_map_buffer_range"))
513 {
514 glRequestExtensionANGLE("GL_EXT_map_buffer_range");
515 EXPECT_GL_NO_ERROR();
516
517 glMapBufferRangeEXT(GL_ELEMENT_ARRAY_BUFFER, 0, 4, GL_MAP_WRITE_BIT);
518 glUnmapBufferOES(GL_ELEMENT_ARRAY_BUFFER);
519 glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_ACCESS_OES, &access);
520 EXPECT_GL_NO_ERROR();
521 }
522}
523
Geoff Lang8c7133c2017-09-26 17:31:10 -0400524// Test enabling the GL_OES_fbo_render_mipmap extension
525TEST_P(WebGLCompatibilityTest, EnableRenderMipmapExtension)
526{
527 EXPECT_FALSE(extensionEnabled("GL_OES_fbo_render_mipmap"));
528
529 // This extensions become core in in ES3/WebGL2.
530 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
531
532 GLTexture texture;
533 glBindTexture(GL_TEXTURE_2D, texture);
534 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
535 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
536
537 GLFramebuffer fbo;
538 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
539 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
540 EXPECT_GL_NO_ERROR();
541
542 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
543 EXPECT_GL_ERROR(GL_INVALID_VALUE);
544
545 if (extensionRequestable("GL_OES_fbo_render_mipmap"))
546 {
547 glRequestExtensionANGLE("GL_OES_fbo_render_mipmap");
548 EXPECT_GL_NO_ERROR();
549
550 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
551 EXPECT_GL_NO_ERROR();
552 }
553}
554
Geoff Lang50cac572017-09-26 17:37:43 -0400555// Test enabling the GL_EXT_blend_minmax extension
556TEST_P(WebGLCompatibilityTest, EnableBlendMinMaxExtension)
557{
558 EXPECT_FALSE(extensionEnabled("GL_EXT_blend_minmax"));
559
560 // This extensions become core in in ES3/WebGL2.
561 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
562
563 glBlendEquation(GL_MIN);
564 EXPECT_GL_ERROR(GL_INVALID_ENUM);
565
566 glBlendEquation(GL_MAX);
567 EXPECT_GL_ERROR(GL_INVALID_ENUM);
568
569 if (extensionRequestable("GL_EXT_blend_minmax"))
570 {
571 glRequestExtensionANGLE("GL_EXT_blend_minmax");
572 EXPECT_GL_NO_ERROR();
573
574 glBlendEquation(GL_MIN);
575 glBlendEquation(GL_MAX);
576 EXPECT_GL_NO_ERROR();
577 }
578}
579
Geoff Langa0e0aeb2017-04-12 15:06:29 -0400580// Verify that the context generates the correct error when the framebuffer attachments are
581// different sizes
582TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMissmatch)
583{
584 GLFramebuffer fbo;
585 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
586
587 GLTexture textures[2];
588 glBindTexture(GL_TEXTURE_2D, textures[0]);
589 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
590 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
591
592 ASSERT_GL_NO_ERROR();
593 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
594
595 GLRenderbuffer renderbuffer;
596 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
597 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3);
598 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
599
600 ASSERT_GL_NO_ERROR();
601 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
602 glCheckFramebufferStatus(GL_FRAMEBUFFER));
603
604 if (extensionRequestable("GL_EXT_draw_buffers"))
605 {
606 glRequestExtensionANGLE("GL_EXT_draw_buffers");
607 EXPECT_GL_NO_ERROR();
608 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
609
610 glBindTexture(GL_TEXTURE_2D, textures[1]);
611 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
612 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
613 ASSERT_GL_NO_ERROR();
614
615 ASSERT_GL_NO_ERROR();
616 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
617 glCheckFramebufferStatus(GL_FRAMEBUFFER));
618
619 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
620
621 ASSERT_GL_NO_ERROR();
622 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
623
624 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
625
626 ASSERT_GL_NO_ERROR();
627 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
628 glCheckFramebufferStatus(GL_FRAMEBUFFER));
629 }
630}
631
Corentin Wallez327411e2016-12-09 11:09:17 -0500632// Test that client-side array buffers are forbidden in WebGL mode
633TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
634{
635 const std::string &vert =
636 "attribute vec3 a_pos;\n"
637 "void main()\n"
638 "{\n"
639 " gl_Position = vec4(a_pos, 1.0);\n"
640 "}\n";
641
642 const std::string &frag =
643 "precision highp float;\n"
644 "void main()\n"
645 "{\n"
646 " gl_FragColor = vec4(1.0);\n"
647 "}\n";
648
649 ANGLE_GL_PROGRAM(program, vert, frag);
650
651 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
652 ASSERT_NE(-1, posLocation);
653 glUseProgram(program.get());
654
655 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -0500656 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -0500657 glEnableVertexAttribArray(posLocation);
658
659 ASSERT_GL_NO_ERROR();
660 glDrawArrays(GL_TRIANGLES, 0, 6);
661 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
662}
663
664// Test that client-side element array buffers are forbidden in WebGL mode
665TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
666{
667 const std::string &vert =
668 "attribute vec3 a_pos;\n"
669 "void main()\n"
670 "{\n"
671 " gl_Position = vec4(a_pos, 1.0);\n"
672 "}\n";
673
674 const std::string &frag =
675 "precision highp float;\n"
676 "void main()\n"
677 "{\n"
678 " gl_FragColor = vec4(1.0);\n"
679 "}\n";
680
681 ANGLE_GL_PROGRAM(program, vert, frag);
682
683 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
684 ASSERT_NE(-1, posLocation);
685 glUseProgram(program.get());
686
687 const auto &vertices = GetQuadVertices();
688
689 GLBuffer vertexBuffer;
690 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
691 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
692 GL_STATIC_DRAW);
693
694 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
695 glEnableVertexAttribArray(posLocation);
696
Corentin Wallez327411e2016-12-09 11:09:17 -0500697 ASSERT_GL_NO_ERROR();
Corentin Wallezded1b5a2017-03-09 18:58:48 -0500698
699 // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also
700 // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate
701 // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check.
702 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1)));
Corentin Wallez327411e2016-12-09 11:09:17 -0500703 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
704}
705
Corentin Wallez672f7f32017-06-15 17:42:17 -0400706// Test that client-side array buffers are forbidden even if the program doesn't use the attribute
707TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes)
708{
709 const std::string &vert =
710 "void main()\n"
711 "{\n"
712 " gl_Position = vec4(1.0);\n"
713 "}\n";
714
715 const std::string &frag =
716 "precision highp float;\n"
717 "void main()\n"
718 "{\n"
719 " gl_FragColor = vec4(1.0);\n"
720 "}\n";
721
722 ANGLE_GL_PROGRAM(program, vert, frag);
723
724 glUseProgram(program.get());
725
726 const auto &vertices = GetQuadVertices();
727 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
728 glEnableVertexAttribArray(0);
729
730 ASSERT_GL_NO_ERROR();
731 glDrawArrays(GL_TRIANGLES, 0, 6);
732 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
733}
734
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500735// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
736TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
737{
738 // Run the test in an FBO to make sure we have some stencil bits.
739 GLRenderbuffer renderbuffer;
740 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
741 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
742
743 GLFramebuffer framebuffer;
744 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
745 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
746 renderbuffer.get());
747
748 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
749 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
750 glUseProgram(program.get());
751 ASSERT_GL_NO_ERROR();
752
753 // Having ref and mask the same for front and back is valid.
754 glStencilMask(255);
755 glStencilFunc(GL_ALWAYS, 0, 255);
756 glDrawArrays(GL_TRIANGLES, 0, 6);
757 ASSERT_GL_NO_ERROR();
758
759 // Having a different front - back write mask generates an error.
760 glStencilMaskSeparate(GL_FRONT, 1);
761 glDrawArrays(GL_TRIANGLES, 0, 6);
762 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
763
764 // Setting both write masks separately to the same value is valid.
765 glStencilMaskSeparate(GL_BACK, 1);
766 glDrawArrays(GL_TRIANGLES, 0, 6);
767 ASSERT_GL_NO_ERROR();
768
769 // Having a different stencil front - back mask generates an error
770 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
771 glDrawArrays(GL_TRIANGLES, 0, 6);
772 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
773
774 // Setting both masks separately to the same value is valid.
775 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
776 glDrawArrays(GL_TRIANGLES, 0, 6);
777 ASSERT_GL_NO_ERROR();
778
779 // Having a different stencil front - back reference generates an error
780 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
781 glDrawArrays(GL_TRIANGLES, 0, 6);
782 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
783
784 // Setting both references separately to the same value is valid.
785 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
786 glDrawArrays(GL_TRIANGLES, 0, 6);
787 ASSERT_GL_NO_ERROR();
788
789 // Using different stencil funcs, everything being equal is valid.
790 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
791 glDrawArrays(GL_TRIANGLES, 0, 6);
792 ASSERT_GL_NO_ERROR();
793}
794
Corentin Wallez506fc9c2016-12-21 16:53:33 -0500795// Test that GL_FIXED is forbidden
796TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
797{
798 GLBuffer buffer;
799 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
800 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
801
802 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
803 ASSERT_GL_NO_ERROR();
804
805 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
806 EXPECT_GL_ERROR(GL_INVALID_ENUM);
807}
808
809// Test the WebGL limit of 255 for the attribute stride
810TEST_P(WebGLCompatibilityTest, MaxStride)
811{
812 GLBuffer buffer;
813 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
814 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
815
816 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
817 ASSERT_GL_NO_ERROR();
818
819 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
820 EXPECT_GL_ERROR(GL_INVALID_VALUE);
821}
822
Corentin Wallezfd456442016-12-21 17:57:00 -0500823// Test the checks for OOB reads in the vertex buffers, non-instanced version
824TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
825{
826 const std::string &vert =
827 "attribute float a_pos;\n"
828 "void main()\n"
829 "{\n"
830 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
831 "}\n";
832
833 const std::string &frag =
834 "precision highp float;\n"
835 "void main()\n"
836 "{\n"
837 " gl_FragColor = vec4(1.0);\n"
838 "}\n";
839
840 ANGLE_GL_PROGRAM(program, vert, frag);
841
842 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
843 ASSERT_NE(-1, posLocation);
844 glUseProgram(program.get());
845
846 GLBuffer buffer;
847 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
848 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
849
850 glEnableVertexAttribArray(posLocation);
851
852 const uint8_t* zeroOffset = nullptr;
853
854 // Test touching the last element is valid.
855 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
856 glDrawArrays(GL_POINTS, 0, 4);
857 ASSERT_GL_NO_ERROR();
858
859 // Test touching the last element + 1 is invalid.
860 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
861 glDrawArrays(GL_POINTS, 0, 4);
862 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
863
864 // Test touching the last element is valid, using a stride.
865 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
866 glDrawArrays(GL_POINTS, 0, 4);
867 ASSERT_GL_NO_ERROR();
868
869 // Test touching the last element + 1 is invalid, using a stride.
870 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
871 glDrawArrays(GL_POINTS, 0, 4);
872 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
873
874 // Test any offset is valid if no vertices are drawn.
875 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
876 glDrawArrays(GL_POINTS, 0, 0);
877 ASSERT_GL_NO_ERROR();
878}
879
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500880// Test the checks for OOB reads in the index buffer
881TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -0500882{
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500883 const std::string &vert =
884 "attribute float a_pos;\n"
885 "void main()\n"
886 "{\n"
887 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
888 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -0500889
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500890 const std::string &frag =
891 "precision highp float;\n"
892 "void main()\n"
893 "{\n"
894 " gl_FragColor = vec4(1.0);\n"
895 "}\n";
896
897 ANGLE_GL_PROGRAM(program, vert, frag);
898
899 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
900 ASSERT_NE(-1, posLocation);
901 glUseProgram(program.get());
902
903 GLBuffer vertexBuffer;
904 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
905 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
906
907 glEnableVertexAttribArray(posLocation);
908
909 const uint8_t *zeroOffset = nullptr;
910 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
911
912 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset);
913
914 GLBuffer indexBuffer;
915 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
916 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -0500917 ASSERT_GL_NO_ERROR();
918
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500919 // Test touching the last index is valid
920 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
921 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -0500922
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500923 // Test touching the last + 1 element is invalid
924 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
925 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -0500926
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500927 // Test any offset if valid if count is zero
928 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
929 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -0500930
931 // Test touching the first index is valid
932 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
933 ASSERT_GL_NO_ERROR();
934
935 // Test touching the first - 1 index is invalid
936 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
937 // the historic behavior of WebGL implementations
938 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
939 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -0500940}
941
Frank Henigman6137ddc2017-02-10 18:55:07 -0500942// Test depth range with 'near' more or less than 'far.'
943TEST_P(WebGLCompatibilityTest, DepthRange)
944{
945 glDepthRangef(0, 1);
946 ASSERT_GL_NO_ERROR();
947
948 glDepthRangef(.5, .5);
949 ASSERT_GL_NO_ERROR();
950
951 glDepthRangef(1, 0);
952 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
953}
954
Frank Henigman146e8a12017-03-02 23:22:37 -0500955// Test all blend function combinations.
956// In WebGL it is invalid to combine constant color with constant alpha.
957TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
958{
959 constexpr GLenum srcFunc[] = {
960 GL_ZERO,
961 GL_ONE,
962 GL_SRC_COLOR,
963 GL_ONE_MINUS_SRC_COLOR,
964 GL_DST_COLOR,
965 GL_ONE_MINUS_DST_COLOR,
966 GL_SRC_ALPHA,
967 GL_ONE_MINUS_SRC_ALPHA,
968 GL_DST_ALPHA,
969 GL_ONE_MINUS_DST_ALPHA,
970 GL_CONSTANT_COLOR,
971 GL_ONE_MINUS_CONSTANT_COLOR,
972 GL_CONSTANT_ALPHA,
973 GL_ONE_MINUS_CONSTANT_ALPHA,
974 GL_SRC_ALPHA_SATURATE,
975 };
976
977 constexpr GLenum dstFunc[] = {
978 GL_ZERO, GL_ONE,
979 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
980 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
981 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
982 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
983 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
984 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
985 };
986
987 for (GLenum src : srcFunc)
988 {
989 for (GLenum dst : dstFunc)
990 {
991 glBlendFunc(src, dst);
992 CheckBlendFunctions(src, dst);
993 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
994 CheckBlendFunctions(src, dst);
995 }
996 }
997}
998
Geoff Langfc32e8b2017-05-31 14:16:59 -0400999// Test that binding/querying uniforms and attributes with invalid names generates errors
1000TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
1001{
1002 const std::string validAttribName =
1003 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
1004 const std::string validUniformName =
1005 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
Geoff Langa71a98e2017-06-19 15:15:00 -04001006 std::vector<char> invalidSet = {'"', '$', '`', '@', '\''};
1007 if (getClientMajorVersion() < 3)
1008 {
1009 invalidSet.push_back('\\');
1010 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04001011
1012 std::string vert = "attribute float ";
1013 vert += validAttribName;
1014 vert +=
1015 ";\n"
1016 "void main()\n"
1017 "{\n"
1018 " gl_Position = vec4(1.0);\n"
1019 "}\n";
1020
1021 std::string frag =
1022 "precision highp float;\n"
1023 "uniform vec4 ";
1024 frag += validUniformName;
Geoff Langcab92ee2017-07-19 17:32:07 -04001025 // Insert illegal characters into comments
Geoff Langfc32e8b2017-05-31 14:16:59 -04001026 frag +=
1027 ";\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001028 " // $ \" @ /*\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001029 "void main()\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001030 "{/*\n"
1031 " ` @ $\n"
1032 " */gl_FragColor = vec4(1.0);\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001033 "}\n";
1034
1035 ANGLE_GL_PROGRAM(program, vert, frag);
1036 EXPECT_GL_NO_ERROR();
1037
1038 for (char invalidChar : invalidSet)
1039 {
1040 std::string invalidName = validAttribName + invalidChar;
1041 glGetAttribLocation(program, invalidName.c_str());
1042 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1043 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1044
1045 glBindAttribLocation(program, 0, invalidName.c_str());
1046 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1047 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1048 }
1049
1050 for (char invalidChar : invalidSet)
1051 {
1052 std::string invalidName = validUniformName + invalidChar;
1053 glGetUniformLocation(program, invalidName.c_str());
1054 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1055 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1056 }
1057
1058 for (char invalidChar : invalidSet)
1059 {
1060 std::string invalidAttribName = validAttribName + invalidChar;
1061 const char *invalidVert[] = {
1062 "attribute float ",
1063 invalidAttribName.c_str(),
1064 ";\n",
1065 "void main()\n",
1066 "{\n",
1067 " gl_Position = vec4(1.0);\n",
1068 "}\n",
1069 };
1070
1071 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1072 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
1073 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1074 glDeleteShader(shader);
1075 }
1076}
1077
Geoff Langcab92ee2017-07-19 17:32:07 -04001078// Test that line continuation is handled correctly when valdiating shader source
1079TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
1080{
1081 const char *validVert =
1082 "#version 300 es\n"
1083 "precision mediump float;\n"
1084 "\n"
1085 "void main ()\n"
1086 "{\n"
1087 " float f\\\n"
1088 "oo = 1.0;\n"
1089 " gl_Position = vec4(foo);\n"
1090 "}\n";
1091
1092 const char *invalidVert =
1093 "#version 300 es\n"
1094 "precision mediump float;\n"
1095 "\n"
1096 "void main ()\n"
1097 "{\n"
1098 " float f\\$\n"
1099 "oo = 1.0;\n"
1100 " gl_Position = vec4(foo);\n"
1101 "}\n";
1102
1103 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1104 glShaderSource(shader, 1, &validVert, nullptr);
1105 EXPECT_GL_NO_ERROR();
1106 glShaderSource(shader, 1, &invalidVert, nullptr);
1107 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1108 glDeleteShader(shader);
1109}
1110
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001111// Tests bindAttribLocations for reserved prefixes and length limits
1112TEST_P(WebGLCompatibilityTest, BindAttribLocationLimitation)
1113{
1114 constexpr int maxLocStringLength = 256;
1115 const std::string tooLongString(maxLocStringLength + 1, '_');
1116
1117 glBindAttribLocation(0, 0, "_webgl_var");
1118
1119 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1120
1121 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
1122
1123 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1124}
1125
Corentin Wallezfd456442016-12-21 17:57:00 -05001126// Test the checks for OOB reads in the vertex buffers, instanced version
1127TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
1128{
1129 const std::string &vert =
1130 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -04001131 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -05001132 "void main()\n"
1133 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -04001134 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -05001135 "}\n";
1136
1137 const std::string &frag =
1138 "precision highp float;\n"
1139 "void main()\n"
1140 "{\n"
1141 " gl_FragColor = vec4(1.0);\n"
1142 "}\n";
1143
1144 ANGLE_GL_PROGRAM(program, vert, frag);
1145
1146 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1147 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -04001148
1149 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1150 ASSERT_NE(-1, wLocation);
1151
Corentin Wallezfd456442016-12-21 17:57:00 -05001152 glUseProgram(program.get());
1153
1154 GLBuffer buffer;
1155 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1156 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1157
1158 glEnableVertexAttribArray(posLocation);
1159 glVertexAttribDivisor(posLocation, 1);
1160
Geoff Lang407d4e72017-04-12 14:54:11 -04001161 glEnableVertexAttribArray(wLocation);
1162 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1163 glVertexAttribDivisor(wLocation, 0);
1164
Corentin Wallezfd456442016-12-21 17:57:00 -05001165 const uint8_t* zeroOffset = nullptr;
1166
1167 // Test touching the last element is valid.
1168 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1169 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1170 ASSERT_GL_NO_ERROR();
1171
1172 // Test touching the last element + 1 is invalid.
1173 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1174 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1175 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1176
1177 // Test touching the last element is valid, using a stride.
1178 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1179 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1180 ASSERT_GL_NO_ERROR();
1181
1182 // Test touching the last element + 1 is invalid, using a stride.
1183 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1184 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1185 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1186
1187 // Test any offset is valid if no vertices are drawn.
1188 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1189 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1190 ASSERT_GL_NO_ERROR();
1191}
1192
Corentin Wallez0dc97812017-06-22 14:38:44 -04001193// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001194TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1195{
1196 const std::string &vert =
1197 "attribute float a_pos;\n"
1198 "void main()\n"
1199 "{\n"
1200 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1201 "}\n";
1202
1203 const std::string &frag =
1204 "precision highp float;\n"
1205 "void main()\n"
1206 "{\n"
1207 " gl_FragColor = vec4(1.0);\n"
1208 "}\n";
1209
1210 ANGLE_GL_PROGRAM(program, vert, frag);
1211
1212 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1213 ASSERT_NE(-1, posLocation);
1214
1215 glUseProgram(program.get());
1216
1217 GLBuffer buffer;
1218 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1219 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1220
1221 glEnableVertexAttribArray(posLocation);
1222 glVertexAttribDivisor(posLocation, 1);
1223
Geoff Lang407d4e72017-04-12 14:54:11 -04001224 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1225 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04001226 ASSERT_GL_NO_ERROR();
1227}
1228
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001229// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1230TEST_P(WebGLCompatibilityTest, NPOT)
1231{
1232 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1233
1234 // Create a texture and set an NPOT mip 0, should always be acceptable.
1235 GLTexture texture;
1236 glBindTexture(GL_TEXTURE_2D, texture.get());
1237 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1238 ASSERT_GL_NO_ERROR();
1239
1240 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1241 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1242 if (getClientMajorVersion() < 3)
1243 {
1244 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1245 }
1246 else
1247 {
1248 ASSERT_GL_NO_ERROR();
1249 }
1250
1251 if (extensionRequestable("GL_OES_texture_npot"))
1252 {
1253 glRequestExtensionANGLE("GL_OES_texture_npot");
1254 ASSERT_GL_NO_ERROR();
1255
1256 // Try again to set NPOT mip 1
1257 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1258 ASSERT_GL_NO_ERROR();
1259 }
1260}
1261
Jamie Madillcad97ee2017-02-02 18:52:44 -05001262template <typename T>
1263void FillTexture2D(GLuint texture,
1264 GLsizei width,
1265 GLsizei height,
1266 const T &onePixelData,
1267 GLint level,
1268 GLint internalFormat,
1269 GLenum format,
1270 GLenum type)
1271{
1272 std::vector<T> allPixelsData(width * height, onePixelData);
1273
1274 glBindTexture(GL_TEXTURE_2D, texture);
1275 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
1276 allPixelsData.data());
1277 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1278 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1279 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1280 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1281}
1282
Frank Henigman875bbba2017-02-08 16:38:17 -05001283// Test that unset gl_Position defaults to (0,0,0,0).
1284TEST_P(WebGLCompatibilityTest, DefaultPosition)
1285{
1286 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
1287 // and green otherwise. The center of each quadrant will be red if and only if all
1288 // four corners are red.
1289 const std::string vertexShader =
1290 "attribute vec3 pos;\n"
1291 "varying vec4 color;\n"
1292 "void main() {\n"
1293 " if (gl_Position == vec4(0,0,0,0)) {\n"
1294 " color = vec4(1,0,0,1);\n"
1295 " } else {\n"
1296 " color = vec4(0,1,0,1);\n"
1297 " }\n"
1298 " gl_Position = vec4(pos,1);\n"
1299 "}\n";
1300
1301 const std::string fragmentShader =
1302 "precision mediump float;\n"
1303 "varying vec4 color;\n"
1304 "void main() {\n"
1305 " gl_FragColor = color;\n"
1306 "}\n";
1307
1308 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1309 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
1310 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1311 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1312 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1313 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1314}
1315
Jamie Madilla4595b82017-01-11 17:36:34 -05001316// Tests that a rendering feedback loop triggers a GL error under WebGL.
1317// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
1318TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
1319{
1320 const std::string vertexShader =
1321 "attribute vec4 a_position;\n"
1322 "varying vec2 v_texCoord;\n"
1323 "void main() {\n"
1324 " gl_Position = a_position;\n"
1325 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
1326 "}\n";
1327
1328 const std::string fragmentShader =
1329 "precision mediump float;\n"
1330 "varying vec2 v_texCoord;\n"
1331 "uniform sampler2D u_texture;\n"
1332 "void main() {\n"
1333 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
1334 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
1335 "}\n";
1336
1337 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001338 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001339
1340 ASSERT_GL_NO_ERROR();
1341
1342 GLFramebuffer framebuffer;
1343 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1344 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1345
1346 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1347
1348 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1349
1350 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
1351 ASSERT_NE(-1, uniformLoc);
1352
1353 glUseProgram(program.get());
1354 glUniform1i(uniformLoc, 0);
1355 glDisable(GL_BLEND);
1356 glDisable(GL_DEPTH_TEST);
1357 ASSERT_GL_NO_ERROR();
1358
1359 // Drawing with a texture that is also bound to the current framebuffer should fail
1360 glBindTexture(GL_TEXTURE_2D, texture.get());
1361 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1362 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1363
1364 // Ensure that the texture contents did not change after the previous render
1365 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1366 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1367 ASSERT_GL_NO_ERROR();
1368 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1369
1370 // Drawing when texture is bound to an inactive uniform should succeed
1371 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001372 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001373
1374 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1375 glActiveTexture(GL_TEXTURE1);
1376 glBindTexture(GL_TEXTURE_2D, texture.get());
1377 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1378 ASSERT_GL_NO_ERROR();
1379 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1380}
1381
Bryan Bernhart58806562017-01-05 13:09:31 -08001382// Test for the max draw buffers and color attachments.
1383TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
1384{
1385 // This test only applies to ES2.
1386 if (getClientMajorVersion() != 2)
1387 {
1388 return;
1389 }
1390
1391 GLFramebuffer fbo[2];
1392 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
1393
1394 // Test that is valid when we bind with a single attachment point.
1395 GLTexture texture;
1396 glBindTexture(GL_TEXTURE_2D, texture.get());
1397 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1398 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1399 ASSERT_GL_NO_ERROR();
1400
1401 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
1402 // attachment point.
1403 if (extensionRequestable("GL_EXT_draw_buffers"))
1404 {
1405 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1406 EXPECT_GL_NO_ERROR();
1407 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1408
1409 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
1410
1411 GLTexture texture2;
1412 glBindTexture(GL_TEXTURE_2D, texture2.get());
1413 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1414 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
1415 0);
1416 ASSERT_GL_NO_ERROR();
1417 }
1418}
1419
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001420// Test that the offset in the index buffer is forced to be a multiple of the element size
1421TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
1422{
1423 const std::string &vert =
1424 "attribute vec3 a_pos;\n"
1425 "void main()\n"
1426 "{\n"
1427 " gl_Position = vec4(a_pos, 1.0);\n"
1428 "}\n";
1429
1430 const std::string &frag =
1431 "precision highp float;\n"
1432 "void main()\n"
1433 "{\n"
1434 " gl_FragColor = vec4(1.0);\n"
1435 "}\n";
1436
1437 ANGLE_GL_PROGRAM(program, vert, frag);
1438
1439 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1440 ASSERT_NE(-1, posLocation);
1441 glUseProgram(program.get());
1442
1443 const auto &vertices = GetQuadVertices();
1444
1445 GLBuffer vertexBuffer;
1446 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1447 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1448 GL_STATIC_DRAW);
1449
1450 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1451 glEnableVertexAttribArray(posLocation);
1452
1453 GLBuffer indexBuffer;
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001454 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001455 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1456 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1457
1458 ASSERT_GL_NO_ERROR();
1459
1460 const char *zeroIndices = nullptr;
1461
1462 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1463 ASSERT_GL_NO_ERROR();
1464
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001465 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001466 ASSERT_GL_NO_ERROR();
1467
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001468 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices + 1);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001469 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1470}
1471
1472// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1473// size
1474TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1475{
1476 const char *zeroOffset = nullptr;
1477
1478 // Base case, vector of two floats
1479 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1480 ASSERT_GL_NO_ERROR();
1481
1482 // Test setting a non-multiple offset
1483 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1484 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1485 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1486 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1487 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1488 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1489
1490 // Test setting a non-multiple stride
1491 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1492 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1493 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1494 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1495 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1496 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1497}
1498
Jamie Madillcad97ee2017-02-02 18:52:44 -05001499void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1500 const std::array<GLenum, 2> &drawBuffers,
1501 GLenum expectedError)
1502{
1503 glDrawBuffersEXT(2, drawBuffers.data());
1504
1505 // Make sure framebuffer is complete before feedback loop detection
1506 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1507
1508 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1509
1510 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1511 // it should be NO_ERROR"
1512 EXPECT_GL_ERROR(expectedError);
1513}
1514
1515// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1516// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1517TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1518{
1519 const std::string vertexShader =
1520 "attribute vec4 aPosition;\n"
1521 "varying vec2 texCoord;\n"
1522 "void main() {\n"
1523 " gl_Position = aPosition;\n"
1524 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1525 "}\n";
1526
1527 const std::string fragmentShader =
1528 "#extension GL_EXT_draw_buffers : require\n"
1529 "precision mediump float;\n"
1530 "uniform sampler2D tex;\n"
1531 "varying vec2 texCoord;\n"
1532 "void main() {\n"
1533 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1534 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1535 "}\n";
1536
1537 GLsizei width = 8;
1538 GLsizei height = 8;
1539
1540 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1541 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1542 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1543 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1544 {
1545 // No WEBGL_draw_buffers support -- this is legal.
1546 return;
1547 }
1548
1549 GLint maxDrawBuffers = 0;
1550 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1551
1552 if (maxDrawBuffers < 2)
1553 {
1554 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1555 return;
1556 }
1557
1558 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1559 glUseProgram(program.get());
1560 glViewport(0, 0, width, height);
1561
1562 GLTexture tex0;
1563 GLTexture tex1;
1564 GLFramebuffer fbo;
1565 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1566 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1567 ASSERT_GL_NO_ERROR();
1568
1569 glBindTexture(GL_TEXTURE_2D, tex1.get());
1570 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1571 ASSERT_NE(-1, texLoc);
1572 glUniform1i(texLoc, 0);
1573 ASSERT_GL_NO_ERROR();
1574
1575 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1576 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1577 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1578 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1579
1580 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1581 GL_INVALID_OPERATION);
1582 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1583 GL_INVALID_OPERATION);
1584 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1585}
1586
Jamie Madill07be8bf2017-02-02 19:59:57 -05001587// Test tests that texture copying feedback loops are properly rejected in WebGL.
1588// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1589TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1590{
1591 GLTexture texture;
1592 glBindTexture(GL_TEXTURE_2D, texture.get());
1593 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1594 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1595 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1596 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1597 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1598
1599 GLTexture texture2;
1600 glBindTexture(GL_TEXTURE_2D, texture2.get());
1601 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1602 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1603 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1604 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1605 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1606
1607 GLFramebuffer framebuffer;
1608 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1609 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1610
1611 // framebuffer should be FRAMEBUFFER_COMPLETE.
1612 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1613 ASSERT_GL_NO_ERROR();
1614
1615 // testing copyTexImage2D
1616
1617 // copyTexImage2D to same texture but different level
1618 glBindTexture(GL_TEXTURE_2D, texture.get());
1619 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1620 EXPECT_GL_NO_ERROR();
1621
1622 // copyTexImage2D to same texture same level, invalid feedback loop
1623 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1624 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1625
1626 // copyTexImage2D to different texture
1627 glBindTexture(GL_TEXTURE_2D, texture2.get());
1628 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1629 EXPECT_GL_NO_ERROR();
1630
1631 // testing copyTexSubImage2D
1632
1633 // copyTexSubImage2D to same texture but different level
1634 glBindTexture(GL_TEXTURE_2D, texture.get());
1635 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1636 EXPECT_GL_NO_ERROR();
1637
1638 // copyTexSubImage2D to same texture same level, invalid feedback loop
1639 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1640 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1641
1642 // copyTexSubImage2D to different texture
1643 glBindTexture(GL_TEXTURE_2D, texture2.get());
1644 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1645 EXPECT_GL_NO_ERROR();
1646}
1647
1648void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1649 const std::array<GLenum, 2> &drawBuffers,
1650 GLenum expectedError)
1651{
1652 glDrawBuffers(2, drawBuffers.data());
1653
1654 // Make sure framebuffer is complete before feedback loop detection
1655 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1656
1657 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1658
1659 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1660 // it should be NO_ERROR"
1661 EXPECT_GL_ERROR(expectedError);
1662}
1663
Yuly Novikov817232e2017-02-22 18:36:10 -05001664// Tests invariance matching rules between built in varyings.
1665// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1666TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1667{
1668 const std::string vertexShaderVariant =
1669 "varying vec4 v_varying;\n"
1670 "void main()\n"
1671 "{\n"
1672 " gl_PointSize = 1.0;\n"
1673 " gl_Position = v_varying;\n"
1674 "}";
1675 const std::string fragmentShaderInvariantGlFragCoord =
1676 "invariant gl_FragCoord;\n"
1677 "void main()\n"
1678 "{\n"
1679 " gl_FragColor = gl_FragCoord;\n"
1680 "}";
1681 const std::string fragmentShaderInvariantGlPointCoord =
1682 "invariant gl_PointCoord;\n"
1683 "void main()\n"
1684 "{\n"
1685 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1686 "}";
1687
1688 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1689 EXPECT_EQ(0u, program);
1690
1691 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1692 EXPECT_EQ(0u, program);
1693}
1694
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04001695// Tests global namespace conflicts between uniforms and attributes.
1696// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
1697TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
1698{
1699 const std::string vertexShader =
1700 "attribute vec4 foo;\n"
1701 "void main()\n"
1702 "{\n"
1703 " gl_Position = foo;\n"
1704 "}";
1705 const std::string fragmentShader =
1706 "precision mediump float;\n"
1707 "uniform vec4 foo;\n"
1708 "void main()\n"
1709 "{\n"
1710 " gl_FragColor = foo;\n"
1711 "}";
1712
1713 GLuint program = CompileProgram(vertexShader, fragmentShader);
1714 EXPECT_EQ(0u, program);
1715}
1716
Geoff Lang966c9402017-04-18 12:38:27 -04001717// Test dimension and image size validation of compressed textures
1718TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
1719{
1720 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
1721 {
1722 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
1723 }
1724
1725 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
1726 {
1727 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
1728 << std::endl;
1729 return;
1730 }
1731
1732 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
1733
1734 GLTexture texture;
1735 glBindTexture(GL_TEXTURE_2D, texture);
1736
1737 // Regular case, verify that it works
1738 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1739 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1740 ASSERT_GL_NO_ERROR();
1741
1742 // Test various dimensions that are not valid
1743 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
1744 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1745 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1746
1747 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
1748 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1749 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1750
1751 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1752 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1753 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1754
1755 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1756 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1757 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1758
1759 // Test various image sizes that are not valid
1760 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1761 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
1762 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1763
1764 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1765 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
1766 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1767
1768 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
1769 CompressedImageDXT1);
1770 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1771
1772 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
1773 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1774 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1775
1776 // Fill a full mip chain and verify that it works
1777 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1778 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1779 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1780 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1781 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1782 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1783 ASSERT_GL_NO_ERROR();
1784
1785 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1786 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1787 ASSERT_GL_NO_ERROR();
1788
1789 // Test that non-block size sub-uploads are not valid for the 0 mip
1790 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1791 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1792 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1793
1794 // Test that non-block size sub-uploads are valid for if they fill the whole mip
1795 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1796 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1797 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1798 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1799 ASSERT_GL_NO_ERROR();
1800
1801 // Test that if the format miss-matches the texture, an error is generated
1802 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1803 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1804 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1805}
1806
Geoff Lang677bb6f2017-04-05 12:40:40 -04001807TEST_P(WebGLCompatibilityTest, L32FTextures)
1808{
1809 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
1810 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
1811
1812 for (auto extension : FloatingPointTextureExtensions)
1813 {
1814 if (strlen(extension) > 0 && extensionRequestable(extension))
1815 {
1816 glRequestExtensionANGLE(extension);
1817 ASSERT_GL_NO_ERROR();
1818 }
1819
1820 // Unsized L 32F
1821 {
1822 bool texture = extensionEnabled("GL_OES_texture_float");
1823 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1824 bool render = false;
1825 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
1826 textureData, readPixelData);
1827 }
1828
1829 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1830 {
1831 // Sized L 32F
1832 bool texture = extensionEnabled("GL_OES_texture_float") &&
1833 extensionEnabled("GL_EXT_texture_storage");
1834 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1835 bool render = false;
1836 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
1837 render, textureData, readPixelData);
1838 }
1839 }
1840}
1841
1842TEST_P(WebGLCompatibilityTest, A32FTextures)
1843{
1844 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
1845 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
1846
1847 for (auto extension : FloatingPointTextureExtensions)
1848 {
1849 if (strlen(extension) > 0 && extensionRequestable(extension))
1850 {
1851 glRequestExtensionANGLE(extension);
1852 ASSERT_GL_NO_ERROR();
1853 }
1854
1855 // Unsized A 32F
1856 {
1857 bool texture = extensionEnabled("GL_OES_texture_float");
1858 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1859 bool render = false;
1860 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
1861 textureData, readPixelData);
1862 }
1863
1864 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1865 {
1866 // Sized A 32F
1867 bool texture = extensionEnabled("GL_OES_texture_float") &&
1868 extensionEnabled("GL_EXT_texture_storage");
1869 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1870 bool render = false;
1871 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
1872 textureData, readPixelData);
1873 }
1874 }
1875}
1876
1877TEST_P(WebGLCompatibilityTest, LA32FTextures)
1878{
1879 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
1880 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
1881 textureData[1]};
1882
1883 for (auto extension : FloatingPointTextureExtensions)
1884 {
1885 if (strlen(extension) > 0 && extensionRequestable(extension))
1886 {
1887 glRequestExtensionANGLE(extension);
1888 ASSERT_GL_NO_ERROR();
1889 }
1890
1891 // Unsized LA 32F
1892 {
1893 bool texture = extensionEnabled("GL_OES_texture_float");
1894 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1895 bool render = false;
1896 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1897 filter, render, textureData, readPixelData);
1898 }
1899
1900 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1901 {
1902 // Sized LA 32F
1903 bool texture = extensionEnabled("GL_OES_texture_float") &&
1904 extensionEnabled("GL_EXT_texture_storage");
1905 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1906 bool render = false;
1907 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1908 filter, render, textureData, readPixelData);
1909 }
1910 }
1911}
1912
1913TEST_P(WebGLCompatibilityTest, R32FTextures)
1914{
1915 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
1916
1917 for (auto extension : FloatingPointTextureExtensions)
1918 {
1919 if (strlen(extension) > 0 && extensionRequestable(extension))
1920 {
1921 glRequestExtensionANGLE(extension);
1922 ASSERT_GL_NO_ERROR();
1923 }
1924
1925 // Unsized R 32F
1926 {
1927 bool texture =
1928 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
1929 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1930 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1931 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1932 }
1933
1934 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1935 {
1936 // Sized R 32F
1937 bool texture =
1938 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1939 extensionEnabled("GL_EXT_texture_rg") &&
1940 extensionEnabled("GL_EXT_texture_storage"));
1941 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1942 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1943 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1944 }
1945 }
1946}
1947
1948TEST_P(WebGLCompatibilityTest, RG32FTextures)
1949{
1950 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
1951
1952 for (auto extension : FloatingPointTextureExtensions)
1953 {
1954 if (strlen(extension) > 0 && extensionRequestable(extension))
1955 {
1956 glRequestExtensionANGLE(extension);
1957 ASSERT_GL_NO_ERROR();
1958 }
1959
1960 // Unsized RG 32F
1961 {
1962 bool texture =
1963 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
1964 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1965 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1966 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1967 }
1968
1969 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1970 {
1971 // Sized RG 32F
1972 bool texture =
1973 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1974 extensionEnabled("GL_EXT_texture_rg") &&
1975 extensionEnabled("GL_EXT_texture_storage"));
1976 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1977 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1978 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1979 }
1980 }
1981}
1982
1983TEST_P(WebGLCompatibilityTest, RGB32FTextures)
1984{
Geoff Lang40762ef2017-05-08 13:47:03 -04001985 if (IsLinux() && IsIntel())
1986 {
1987 std::cout << "Test skipped on Linux Intel." << std::endl;
1988 return;
1989 }
1990
Geoff Lang677bb6f2017-04-05 12:40:40 -04001991 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
1992
1993 for (auto extension : FloatingPointTextureExtensions)
1994 {
1995 if (strlen(extension) > 0 && extensionRequestable(extension))
1996 {
1997 glRequestExtensionANGLE(extension);
1998 ASSERT_GL_NO_ERROR();
1999 }
2000
2001 // Unsized RGB 32F
2002 {
2003 bool texture = extensionEnabled("GL_OES_texture_float");
2004 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2005 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2006 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
2007 }
2008
2009 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2010 {
2011 // Sized RGBA 32F
2012 bool texture =
2013 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2014 extensionEnabled("GL_EXT_texture_storage"));
2015 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2016 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2017 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
2018 data);
2019 }
2020 }
2021}
2022
2023TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
2024{
2025 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2026
2027 for (auto extension : FloatingPointTextureExtensions)
2028 {
2029 if (strlen(extension) > 0 && extensionRequestable(extension))
2030 {
2031 glRequestExtensionANGLE(extension);
2032 ASSERT_GL_NO_ERROR();
2033 }
2034
2035 // Unsized RGBA 32F
2036 {
2037 bool texture = extensionEnabled("GL_OES_texture_float");
2038 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2039 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2040 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2041 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
2042 }
2043
2044 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2045 {
2046 // Sized RGBA 32F
2047 bool texture =
2048 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2049 extensionEnabled("GL_EXT_texture_storage"));
2050 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2051 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2052 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2053 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
2054 data);
2055 }
2056 }
2057}
2058
2059TEST_P(WebGLCompatibilityTest, R16FTextures)
2060{
2061 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
2062 const GLushort textureData[] = {
2063 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2064 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2065
2066 for (auto extension : FloatingPointTextureExtensions)
2067 {
2068 if (strlen(extension) > 0 && extensionRequestable(extension))
2069 {
2070 glRequestExtensionANGLE(extension);
2071 ASSERT_GL_NO_ERROR();
2072 }
2073
2074 // Unsized R 16F (OES)
2075 {
2076 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2077 extensionEnabled("GL_EXT_texture_rg");
2078 bool filter = getClientMajorVersion() >= 3 ||
2079 extensionEnabled("GL_OES_texture_half_float_linear");
2080 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2081 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2082 textureData, readPixelsData);
2083 }
2084
2085 // Unsized R 16F
2086 {
2087 bool texture = false;
2088 bool filter = false;
2089 bool render = false;
2090 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2091 textureData, readPixelsData);
2092 }
2093
2094 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2095 {
2096 // Sized R 16F
2097 bool texture = getClientMajorVersion() >= 3;
2098 bool filter = getClientMajorVersion() >= 3 ||
2099 extensionEnabled("GL_OES_texture_half_float_linear");
2100 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2101 extensionEnabled("GL_EXT_color_buffer_float");
2102 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2103 textureData, readPixelsData);
2104 }
2105 }
2106}
2107
2108TEST_P(WebGLCompatibilityTest, RG16FTextures)
2109{
2110 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
2111 const GLushort textureData[] = {
2112 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2113 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2114
2115 for (auto extension : FloatingPointTextureExtensions)
2116 {
2117 if (strlen(extension) > 0 && extensionRequestable(extension))
2118 {
2119 glRequestExtensionANGLE(extension);
2120 ASSERT_GL_NO_ERROR();
2121 }
2122
2123 // Unsized RG 16F (OES)
2124 {
2125 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2126 extensionEnabled("GL_EXT_texture_rg");
2127 bool filter = getClientMajorVersion() >= 3 ||
2128 extensionEnabled("GL_OES_texture_half_float_linear");
2129 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
2130 extensionEnabled("GL_EXT_texture_rg");
2131 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2132 textureData, readPixelsData);
2133 }
2134
2135 // Unsized RG 16F
2136 {
2137 bool texture = false;
2138 bool filter = false;
2139 bool render = false;
2140 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2141 textureData, readPixelsData);
2142 }
2143
2144 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2145 {
2146 // Sized RG 16F
2147 bool texture = getClientMajorVersion() >= 3;
2148 bool filter = getClientMajorVersion() >= 3 ||
2149 extensionEnabled("GL_OES_texture_half_float_linear");
2150 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2151 extensionEnabled("GL_EXT_color_buffer_float");
2152 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2153 textureData, readPixelsData);
2154 }
2155 }
2156}
2157
2158TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2159{
Geoff Lang40762ef2017-05-08 13:47:03 -04002160 if (IsOzone() && IsIntel())
2161 {
2162 std::cout << "Test skipped on Intel Ozone." << std::endl;
2163 return;
2164 }
2165
Geoff Lang677bb6f2017-04-05 12:40:40 -04002166 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2167 const GLushort textureData[] = {
2168 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2169 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2170
2171 for (auto extension : FloatingPointTextureExtensions)
2172 {
2173 if (strlen(extension) > 0 && extensionRequestable(extension))
2174 {
2175 glRequestExtensionANGLE(extension);
2176 ASSERT_GL_NO_ERROR();
2177 }
2178
2179 // Unsized RGB 16F (OES)
2180 {
2181 bool texture = extensionEnabled("GL_OES_texture_half_float");
2182 bool filter = getClientMajorVersion() >= 3 ||
2183 extensionEnabled("GL_OES_texture_half_float_linear");
2184 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2185 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2186 textureData, readPixelsData);
2187 }
2188
2189 // Unsized RGB 16F
2190 {
2191 bool texture = false;
2192 bool filter = false;
2193 bool render = false;
2194 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2195 textureData, readPixelsData);
2196 }
2197
2198 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2199 {
2200 // Sized RGB 16F
2201 bool texture = getClientMajorVersion() >= 3;
2202 bool filter = getClientMajorVersion() >= 3 ||
2203 extensionEnabled("GL_OES_texture_half_float_linear");
2204 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2205 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2206 textureData, readPixelsData);
2207 }
2208 }
2209}
2210
2211TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2212{
Geoff Lang40762ef2017-05-08 13:47:03 -04002213 if (IsOzone() && IsIntel())
2214 {
2215 std::cout << "Test skipped on Intel Ozone." << std::endl;
2216 return;
2217 }
2218
Geoff Lang677bb6f2017-04-05 12:40:40 -04002219 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2220 const GLushort textureData[] = {
2221 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2222 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2223
2224 for (auto extension : FloatingPointTextureExtensions)
2225 {
2226 if (strlen(extension) > 0 && extensionRequestable(extension))
2227 {
2228 glRequestExtensionANGLE(extension);
2229 ASSERT_GL_NO_ERROR();
2230 }
2231
2232 // Unsized RGBA 16F (OES)
2233 {
2234 bool texture = extensionEnabled("GL_OES_texture_half_float");
2235 bool filter = getClientMajorVersion() >= 3 ||
2236 extensionEnabled("GL_OES_texture_half_float_linear");
2237 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2238 extensionEnabled("GL_EXT_color_buffer_float");
2239 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2240 textureData, readPixelsData);
2241 }
2242
2243 // Unsized RGBA 16F
2244 {
2245 bool texture = false;
2246 bool filter = false;
2247 bool render = false;
2248 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2249 textureData, readPixelsData);
2250 }
2251
2252 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2253 {
2254 // Sized RGBA 16F
2255 bool texture = getClientMajorVersion() >= 3;
2256 bool filter = getClientMajorVersion() >= 3 ||
2257 extensionEnabled("GL_OES_texture_half_float_linear");
2258 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2259 extensionEnabled("GL_EXT_color_buffer_float");
2260 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2261 textureData, readPixelsData);
2262 }
2263 }
2264}
2265
Geoff Lang6e898aa2017-06-02 11:17:26 -04002266// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2267// accepted by glTexImage2D
2268TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2269{
2270 if (getClientMajorVersion() != 2)
2271 {
2272 std::cout << "Test skipped because it is only valid for WebGL1 contexts." << std::endl;
2273 return;
2274 }
2275
2276 if (!extensionRequestable("GL_OES_texture_float"))
2277 {
2278 std::cout << "Test skipped because GL_OES_texture_float is not requestable." << std::endl;
2279 return;
2280 }
2281 glRequestExtensionANGLE("GL_OES_texture_float");
2282 ASSERT_GL_NO_ERROR();
2283
2284 GLTexture texture;
2285 glBindTexture(GL_TEXTURE_2D, texture);
2286
2287 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2288 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2289
2290 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2291 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2292
2293 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2294 {
2295 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2296 ASSERT_GL_NO_ERROR();
2297
2298 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2299 EXPECT_GL_NO_ERROR();
2300 }
2301
2302 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2303 {
2304 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2305 ASSERT_GL_NO_ERROR();
2306
2307 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2308 EXPECT_GL_NO_ERROR();
2309 }
2310}
2311
Jamie Madill07be8bf2017-02-02 19:59:57 -05002312// This tests that rendering feedback loops works as expected with WebGL 2.
2313// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2314TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2315{
2316 const std::string vertexShader =
2317 "#version 300 es\n"
2318 "in vec4 aPosition;\n"
2319 "out vec2 texCoord;\n"
2320 "void main() {\n"
2321 " gl_Position = aPosition;\n"
2322 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2323 "}\n";
2324
2325 const std::string fragmentShader =
2326 "#version 300 es\n"
2327 "precision mediump float;\n"
2328 "uniform sampler2D tex;\n"
2329 "in vec2 texCoord;\n"
2330 "out vec4 oColor;\n"
2331 "void main() {\n"
2332 " oColor = texture(tex, texCoord);\n"
2333 "}\n";
2334
2335 GLsizei width = 8;
2336 GLsizei height = 8;
2337
2338 GLint maxDrawBuffers = 0;
2339 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2340 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2341 ASSERT_GE(maxDrawBuffers, 2);
2342
2343 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2344 glUseProgram(program.get());
2345 glViewport(0, 0, width, height);
2346
2347 GLTexture tex0;
2348 GLTexture tex1;
2349 GLFramebuffer fbo;
2350 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2351 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2352 ASSERT_GL_NO_ERROR();
2353
2354 glBindTexture(GL_TEXTURE_2D, tex1.get());
2355 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2356 ASSERT_NE(-1, texLoc);
2357 glUniform1i(texLoc, 0);
2358
2359 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2360 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2361 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2362 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2363 ASSERT_GL_NO_ERROR();
2364
2365 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2366 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2367 GL_INVALID_OPERATION);
2368 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2369}
2370
Jamie Madill1d37bc52017-02-02 19:59:58 -05002371// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2372// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2373TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2374{
2375 const std::string vertexShader =
2376 "#version 300 es\n"
2377 "in vec4 aPosition;\n"
2378 "out vec2 texCoord;\n"
2379 "void main() {\n"
2380 " gl_Position = aPosition;\n"
2381 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2382 "}\n";
2383
2384 const std::string fragmentShader =
2385 "#version 300 es\n"
2386 "precision mediump float;\n"
2387 "uniform sampler2D tex;\n"
2388 "in vec2 texCoord;\n"
2389 "out vec4 oColor;\n"
2390 "void main() {\n"
2391 " oColor = texture(tex, texCoord);\n"
2392 "}\n";
2393
2394 GLsizei width = 8;
2395 GLsizei height = 8;
2396
2397 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2398 glUseProgram(program.get());
2399
2400 glViewport(0, 0, width, height);
2401
2402 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2403 glUniform1i(texLoc, 0);
2404
2405 // Create textures and allocate storage
2406 GLTexture tex0;
2407 GLTexture tex1;
2408 GLRenderbuffer rb;
2409 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2410 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2411 GL_UNSIGNED_INT);
2412 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2413 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2414 ASSERT_GL_NO_ERROR();
2415
2416 GLFramebuffer fbo;
2417 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2418 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2419
2420 // Test rendering and sampling feedback loop for depth buffer
2421 glBindTexture(GL_TEXTURE_2D, tex1.get());
2422 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2423 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2424
2425 // The same image is used as depth buffer during rendering.
2426 glEnable(GL_DEPTH_TEST);
2427 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2428 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2429
2430 // The same image is used as depth buffer. But depth mask is false.
2431 glDepthMask(GL_FALSE);
2432 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2433 EXPECT_GL_NO_ERROR();
2434
2435 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2436 glDepthMask(GL_TRUE);
2437 glDisable(GL_DEPTH_TEST);
2438 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2439 EXPECT_GL_NO_ERROR();
2440
2441 // Test rendering and sampling feedback loop for stencil buffer
2442 glBindTexture(GL_RENDERBUFFER, rb.get());
2443 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2444 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2445 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2446 constexpr GLint stencilClearValue = 0x40;
2447 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2448
2449 // The same image is used as stencil buffer during rendering.
2450 glEnable(GL_STENCIL_TEST);
2451 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2452 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2453
2454 // The same image is used as stencil buffer. But stencil mask is zero.
2455 glStencilMask(0x0);
2456 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2457 EXPECT_GL_NO_ERROR();
2458
2459 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2460 glStencilMask(0xffff);
2461 glDisable(GL_STENCIL_TEST);
2462 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2463 EXPECT_GL_NO_ERROR();
2464}
2465
Jamie Madillfd3dd432017-02-02 19:59:59 -05002466// The source and the target for CopyTexSubImage3D are the same 3D texture.
2467// But the level of the 3D texture != the level of the read attachment.
2468TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2469{
2470 GLTexture texture;
2471 GLFramebuffer framebuffer;
2472
2473 glBindTexture(GL_TEXTURE_3D, texture.get());
2474 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2475
2476 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2477 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2478 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2479 ASSERT_GL_NO_ERROR();
2480
2481 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2482 EXPECT_GL_NO_ERROR();
2483}
2484
2485// The source and the target for CopyTexSubImage3D are the same 3D texture.
2486// But the zoffset of the 3D texture != the layer of the read attachment.
2487TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2488{
2489 GLTexture texture;
2490 GLFramebuffer framebuffer;
2491
2492 glBindTexture(GL_TEXTURE_3D, texture.get());
2493 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2494
2495 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2496 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2497 ASSERT_GL_NO_ERROR();
2498
2499 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2500 EXPECT_GL_NO_ERROR();
2501}
2502
2503// The source and the target for CopyTexSubImage3D are the same 3D texture.
2504// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2505TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2506{
2507 GLTexture texture;
2508 GLFramebuffer framebuffer;
2509
2510 glBindTexture(GL_TEXTURE_3D, texture.get());
2511 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2512
2513 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2514 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2515 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2516 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2517 ASSERT_GL_NO_ERROR();
2518
2519 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2520 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2521}
2522
Corentin Wallez59c41592017-07-11 13:19:54 -04002523// Verify that errors are generated when there isn't a defined conversion between the clear type and
2524// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04002525TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2526{
2527 if (IsD3D11())
2528 {
2529 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2530 return;
2531 }
2532
2533 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2534 constexpr int clearInt[] = {0, 0, 0, 0};
2535 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2536
2537 GLTexture texture;
2538 GLFramebuffer framebuffer;
2539
2540 glBindTexture(GL_TEXTURE_2D, texture.get());
2541 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2542
2543 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2544 ASSERT_GL_NO_ERROR();
2545
2546 // Unsigned integer buffer
2547 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2548 ASSERT_GL_NO_ERROR();
2549
2550 glClearBufferfv(GL_COLOR, 0, clearFloat);
2551 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2552
2553 glClearBufferiv(GL_COLOR, 0, clearInt);
2554 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2555
2556 glClearBufferuiv(GL_COLOR, 0, clearUint);
2557 EXPECT_GL_NO_ERROR();
2558
2559 glClear(GL_COLOR_BUFFER_BIT);
2560 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2561
2562 // Integer buffer
2563 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2564 ASSERT_GL_NO_ERROR();
2565
2566 glClearBufferfv(GL_COLOR, 0, clearFloat);
2567 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2568
2569 glClearBufferiv(GL_COLOR, 0, clearInt);
2570 EXPECT_GL_NO_ERROR();
2571
2572 glClearBufferuiv(GL_COLOR, 0, clearUint);
2573 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2574
2575 glClear(GL_COLOR_BUFFER_BIT);
2576 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2577
2578 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002579 if (extensionRequestable("GL_EXT_color_buffer_float"))
2580 {
2581 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2582 }
Geoff Lang76e65652017-03-27 14:58:02 -04002583
Geoff Lang677bb6f2017-04-05 12:40:40 -04002584 if (extensionEnabled("GL_EXT_color_buffer_float"))
2585 {
2586 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2587 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002588
Geoff Lang677bb6f2017-04-05 12:40:40 -04002589 glClearBufferfv(GL_COLOR, 0, clearFloat);
2590 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002591
Geoff Lang677bb6f2017-04-05 12:40:40 -04002592 glClearBufferiv(GL_COLOR, 0, clearInt);
2593 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002594
Geoff Lang677bb6f2017-04-05 12:40:40 -04002595 glClearBufferuiv(GL_COLOR, 0, clearUint);
2596 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2597
2598 glClear(GL_COLOR_BUFFER_BIT);
2599 EXPECT_GL_NO_ERROR();
2600 }
Geoff Lang76e65652017-03-27 14:58:02 -04002601
2602 // Normalized uint buffer
2603 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2604 ASSERT_GL_NO_ERROR();
2605
2606 glClearBufferfv(GL_COLOR, 0, clearFloat);
2607 EXPECT_GL_NO_ERROR();
2608
2609 glClearBufferiv(GL_COLOR, 0, clearInt);
2610 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2611
2612 glClearBufferuiv(GL_COLOR, 0, clearUint);
2613 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2614
2615 glClear(GL_COLOR_BUFFER_BIT);
2616 EXPECT_GL_NO_ERROR();
2617}
2618
Corentin Wallez59c41592017-07-11 13:19:54 -04002619// Test the interaction of WebGL compatibility clears with default framebuffers
2620TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
2621{
2622 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2623 constexpr int clearInt[] = {0, 0, 0, 0};
2624 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2625
2626 // glClear works as usual, this is also a regression test for a bug where we
2627 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
2628 glClear(GL_COLOR_BUFFER_BIT);
2629 EXPECT_GL_NO_ERROR();
2630
2631 // Default framebuffers are normalized uints, so only glClearBufferfv works.
2632 glClearBufferfv(GL_COLOR, 0, clearFloat);
2633 EXPECT_GL_NO_ERROR();
2634
2635 glClearBufferiv(GL_COLOR, 0, clearInt);
2636 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2637
2638 glClearBufferuiv(GL_COLOR, 0, clearUint);
2639 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2640}
2641
Geoff Lange4915782017-04-12 15:19:07 -04002642// Verify that errors are generate when trying to blit from an image to itself
2643TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2644{
2645 GLTexture textures[2];
2646 glBindTexture(GL_TEXTURE_2D, textures[0]);
2647 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2648 glBindTexture(GL_TEXTURE_2D, textures[1]);
2649 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2650
2651 GLRenderbuffer renderbuffers[2];
2652 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2653 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2654 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2655 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2656
2657 GLFramebuffer framebuffers[2];
2658 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2659 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2660
2661 ASSERT_GL_NO_ERROR();
2662
2663 // Same texture
2664 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2665 0);
2666 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2667 0);
2668 ASSERT_GL_NO_ERROR();
2669 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2670 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2671
2672 // Same textures but different renderbuffers
2673 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2674 renderbuffers[0]);
2675 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2676 renderbuffers[1]);
2677 ASSERT_GL_NO_ERROR();
2678 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2679 ASSERT_GL_NO_ERROR();
2680 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2681 GL_NEAREST);
2682 ASSERT_GL_NO_ERROR();
2683 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2684 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2685 GL_NEAREST);
2686 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2687
2688 // Same renderbuffers but different textures
2689 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2690 0);
2691 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2692 0);
2693 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2694 renderbuffers[0]);
2695 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2696 renderbuffers[0]);
2697 ASSERT_GL_NO_ERROR();
2698 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2699 ASSERT_GL_NO_ERROR();
2700 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2701 GL_NEAREST);
2702 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2703 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2704 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2705 GL_NEAREST);
2706 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2707}
2708
Geoff Lange0cff192017-05-30 13:04:56 -04002709// Verify that errors are generated when the fragment shader output doesn't match the bound color
2710// buffer types
2711TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
2712{
2713 const std::string vertexShader =
2714 "#version 300 es\n"
2715 "void main() {\n"
2716 " gl_Position = vec4(0, 0, 0, 1);\n"
2717 "}\n";
2718
2719 const std::string fragmentShader =
2720 "#version 300 es\n"
2721 "precision mediump float;\n"
2722 "layout(location = 0) out vec4 floatOutput;\n"
2723 "layout(location = 1) out uvec4 uintOutput;\n"
2724 "layout(location = 2) out ivec4 intOutput;\n"
2725 "void main() {\n"
2726 " floatOutput = vec4(0, 0, 0, 1);\n"
2727 " uintOutput = uvec4(0, 0, 0, 1);\n"
2728 " intOutput = ivec4(0, 0, 0, 1);\n"
2729 "}\n";
2730
2731 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2732 glUseProgram(program.get());
2733
2734 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
2735 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
2736 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
2737
2738 GLFramebuffer fbo;
2739 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2740
2741 GLRenderbuffer floatRenderbuffer;
2742 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
2743 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2744 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2745 floatRenderbuffer);
2746
2747 GLRenderbuffer uintRenderbuffer;
2748 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
2749 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
2750 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2751 uintRenderbuffer);
2752
2753 GLRenderbuffer intRenderbuffer;
2754 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
2755 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
2756 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2757 intRenderbuffer);
2758
2759 ASSERT_GL_NO_ERROR();
2760
2761 GLint maxDrawBuffers = 0;
2762 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2763 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
2764 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
2765 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
2766 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
2767
2768 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2769
2770 // Check that the correct case generates no errors
2771 glDrawArrays(GL_TRIANGLES, 0, 6);
2772 EXPECT_GL_NO_ERROR();
2773
2774 // Unbind some buffers and verify that there are still no errors
2775 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2776 0);
2777 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2778 0);
2779 glDrawArrays(GL_TRIANGLES, 0, 6);
2780 EXPECT_GL_NO_ERROR();
2781
2782 // Swap the int and uint buffers to and verify that an error is generated
2783 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2784 intRenderbuffer);
2785 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2786 uintRenderbuffer);
2787 glDrawArrays(GL_TRIANGLES, 0, 6);
2788 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2789
2790 // Swap the float and uint buffers to and verify that an error is generated
2791 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2792 floatRenderbuffer);
2793 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2794 uintRenderbuffer);
2795 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2796 intRenderbuffer);
2797 glDrawArrays(GL_TRIANGLES, 0, 6);
2798 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2799}
2800
Geoff Lang9ab5b822017-05-30 16:19:23 -04002801// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
2802// types
2803TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMissmatch)
2804{
2805 const std::string vertexShader =
2806 "#version 300 es\n"
2807 "in vec4 floatInput;\n"
2808 "in uvec4 uintInput;\n"
2809 "in ivec4 intInput;\n"
2810 "void main() {\n"
2811 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
2812 "}\n";
2813
2814 const std::string fragmentShader =
2815 "#version 300 es\n"
2816 "precision mediump float;\n"
2817 "out vec4 outputColor;\n"
2818 "void main() {\n"
2819 " outputColor = vec4(0, 0, 0, 1);"
2820 "}\n";
2821
2822 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2823 glUseProgram(program.get());
2824
2825 GLint floatLocation = glGetAttribLocation(program, "floatInput");
2826 GLint uintLocation = glGetAttribLocation(program, "uintInput");
2827 GLint intLocation = glGetAttribLocation(program, "intInput");
2828
2829 // Default attributes are of float types
2830 glDrawArrays(GL_TRIANGLES, 0, 6);
2831 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2832
2833 // Set the default attributes to the correct types, should succeed
2834 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
2835 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
2836 glDrawArrays(GL_TRIANGLES, 0, 6);
2837 EXPECT_GL_NO_ERROR();
2838
2839 // Change the default float attribute to an integer, should fail
2840 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
2841 glDrawArrays(GL_TRIANGLES, 0, 6);
2842 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2843
2844 // Use a buffer for some attributes
2845 GLBuffer buffer;
2846 glBindBuffer(GL_ARRAY_BUFFER, buffer);
2847 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
2848 glEnableVertexAttribArray(floatLocation);
2849 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2850 glDrawArrays(GL_TRIANGLES, 0, 6);
2851 EXPECT_GL_NO_ERROR();
2852
2853 // Use a float pointer attrib for a uint input
2854 glEnableVertexAttribArray(uintLocation);
2855 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2856 glDrawArrays(GL_TRIANGLES, 0, 6);
2857 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2858
2859 // Use a uint pointer for the uint input
2860 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
2861 glDrawArrays(GL_TRIANGLES, 0, 6);
2862 EXPECT_GL_NO_ERROR();
2863}
2864
Corentin Walleze7557742017-06-01 13:09:57 -04002865// Tests the WebGL removal of undefined behavior when attachments aren't written to.
2866TEST_P(WebGLCompatibilityTest, DrawBuffers)
2867{
Corentin Walleze7557742017-06-01 13:09:57 -04002868 // Make sure we can use at least 4 attachments for the tests.
2869 bool useEXT = false;
2870 if (getClientMajorVersion() < 3)
2871 {
2872 if (!extensionRequestable("GL_EXT_draw_buffers"))
2873 {
2874 std::cout << "Test skipped because draw buffers are not available" << std::endl;
2875 return;
2876 }
2877
2878 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2879 useEXT = true;
2880 EXPECT_GL_NO_ERROR();
2881 }
2882
2883 GLint maxDrawBuffers = 0;
2884 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2885 if (maxDrawBuffers < 4)
2886 {
2887 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
2888 return;
2889 }
2890
2891 // Clears all the renderbuffers to red.
2892 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
2893 GLFramebuffer clearFBO;
2894 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
2895
2896 glClearColor(1, 0, 0, 1);
2897 for (int i = 0; i < 4; ++i)
2898 {
2899 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2900 renderbuffers[i]);
2901 glClear(GL_COLOR_BUFFER_BIT);
2902 }
2903 ASSERT_GL_NO_ERROR();
2904 };
2905
2906 // Checks that the renderbuffers specified by mask have the correct color
2907 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
2908 GLFramebuffer readFBO;
2909 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
2910
2911 for (int i = 0; i < 4; ++i)
2912 {
2913 if (mask & (1 << i))
2914 {
2915 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2916 GL_RENDERBUFFER, renderbuffers[i]);
2917 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
2918 }
2919 }
2920 ASSERT_GL_NO_ERROR();
2921 };
2922
2923 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
2924 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
2925 if (useEXT)
2926 {
2927 glDrawBuffersEXT(numBuffers, buffers);
2928 }
2929 else
2930 {
2931 glDrawBuffers(numBuffers, buffers);
2932 }
2933 };
2934
2935 // Initialized the test framebuffer
2936 GLFramebuffer drawFBO;
2937 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2938
2939 GLRenderbuffer renderbuffers[4];
2940 for (int i = 0; i < 4; ++i)
2941 {
2942 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
2943 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2944 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
2945 renderbuffers[i]);
2946 }
2947
2948 ASSERT_GL_NO_ERROR();
2949
2950 const char *vertESSL1 =
2951 "attribute vec4 a_pos;\n"
2952 "void main()\n"
2953 "{\n"
2954 " gl_Position = a_pos;\n"
2955 "}\n";
2956 const char *vertESSL3 =
2957 "#version 300 es\n"
2958 "in vec4 a_pos;\n"
2959 "void main()\n"
2960 "{\n"
2961 " gl_Position = a_pos;\n"
2962 "}\n";
2963
2964 GLenum allDrawBuffers[] = {
2965 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2966 };
2967
2968 GLenum halfDrawBuffers[] = {
2969 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2970 };
2971
2972 // Test that when using gl_FragColor, only the first attachment is written to.
2973 const char *fragESSL1 =
2974 "precision highp float;\n"
2975 "void main()\n"
2976 "{\n"
2977 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
2978 "}\n";
2979 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
2980
2981 {
2982 ClearEverythingToRed(renderbuffers);
2983
2984 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2985 DrawBuffers(useEXT, 4, allDrawBuffers);
2986 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2987 ASSERT_GL_NO_ERROR();
2988
2989 CheckColors(renderbuffers, 0b0001, GLColor::green);
2990 CheckColors(renderbuffers, 0b1110, GLColor::red);
2991 }
2992
2993 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
2994 // written to.
2995 {
2996 ClearEverythingToRed(renderbuffers);
2997
2998 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2999 DrawBuffers(useEXT, 4, halfDrawBuffers);
3000 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
3001 ASSERT_GL_NO_ERROR();
3002
3003 CheckColors(renderbuffers, 0b1111, GLColor::red);
3004 }
3005
3006 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
3007 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
3008 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
3009 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
3010 // attachments not declared in the shader should not be written to.
3011 const char *writeOddOutputsVert;
3012 const char *writeOddOutputsFrag;
3013 GLColor unwrittenColor;
3014 if (useEXT)
3015 {
3016 // In the extension, when an attachment isn't written to, it should get 0's
3017 unwrittenColor = GLColor(0, 0, 0, 0);
3018 writeOddOutputsVert = vertESSL1;
3019 writeOddOutputsFrag =
3020 "#extension GL_EXT_draw_buffers : require\n"
3021 "precision highp float;\n"
3022 "void main()\n"
3023 "{\n"
3024 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3025 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3026 "}\n";
3027 }
3028 else
3029 {
3030 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
3031 // because of the preceding clears.
3032 unwrittenColor = GLColor::red;
3033 writeOddOutputsVert = vertESSL3;
3034 writeOddOutputsFrag =
3035 "#version 300 es\n"
3036 "precision highp float;\n"
3037 "layout(location = 1) out vec4 output1;"
3038 "layout(location = 3) out vec4 output2;"
3039 "void main()\n"
3040 "{\n"
3041 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3042 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3043 "}\n";
3044 }
3045 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
3046
3047 // Test that attachments not written to get the "unwritten" color
3048 {
3049 ClearEverythingToRed(renderbuffers);
3050
3051 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3052 DrawBuffers(useEXT, 4, allDrawBuffers);
3053 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
3054 ASSERT_GL_NO_ERROR();
3055
3056 CheckColors(renderbuffers, 0b1010, GLColor::green);
3057 CheckColors(renderbuffers, 0b0101, unwrittenColor);
3058 }
3059
3060 // Test that attachments not written to get the "unwritten" color but that even when the
3061 // extension is used, disabled attachments are not written at all and stay red.
3062 {
3063 ClearEverythingToRed(renderbuffers);
3064
3065 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3066 DrawBuffers(useEXT, 4, halfDrawBuffers);
3067 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
3068 ASSERT_GL_NO_ERROR();
3069
3070 CheckColors(renderbuffers, 0b1000, GLColor::green);
3071 CheckColors(renderbuffers, 0b0100, unwrittenColor);
3072 CheckColors(renderbuffers, 0b0011, GLColor::red);
3073 }
3074}
3075
Frank Henigmanfccbac22017-05-28 17:29:26 -04003076// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
3077// qualifiers.
3078TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
3079{
3080 const std::string vertexShader =
3081 "#version 300 es\n"
3082 "uniform Block { mediump vec4 val; };\n"
3083 "void main() { gl_Position = val; }\n";
3084 const std::string fragmentShader =
3085 "#version 300 es\n"
3086 "uniform Block { highp vec4 val; };\n"
3087 "out highp vec4 out_FragColor;\n"
3088 "void main() { out_FragColor = val; }\n";
3089
3090 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
3091 ASSERT_NE(0u, vs);
3092 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
3093 ASSERT_NE(0u, fs);
3094
3095 GLuint program = glCreateProgram();
3096
3097 glAttachShader(program, vs);
3098 glDeleteShader(vs);
3099 glAttachShader(program, fs);
3100 glDeleteShader(fs);
3101
3102 glLinkProgram(program);
3103 GLint linkStatus;
3104 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
3105 ASSERT_EQ(0, linkStatus);
3106
3107 glDeleteProgram(program);
3108}
3109
Geoff Lang69df2422017-07-05 12:42:31 -04003110// Test no attribute vertex shaders
3111TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
3112{
3113 const std::string vertexShader =
3114 "#version 300 es\n"
3115 "void main()\n"
3116 "{\n"
3117 "\n"
3118 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
3119 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
3120 "}";
3121 const std::string fragmentShader =
3122 "#version 300 es\n"
3123 "precision mediump float;\n"
3124 "out vec4 result;\n"
3125 "void main()\n"
3126 "{\n"
3127 " result = vec4(0, 1, 0, 1);\n"
3128 "}";
3129
3130 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3131 glUseProgram(program);
3132
3133 glDrawArrays(GL_TRIANGLES, 0, 6);
3134 ASSERT_GL_NO_ERROR();
3135 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3136}
3137
Brandon Jonesed5b46f2017-07-21 08:39:17 -07003138// Tests bindAttribLocations for length limit
3139TEST_P(WebGL2CompatibilityTest, BindAttribLocationLimitation)
3140{
3141 constexpr int maxLocStringLength = 1024;
3142 const std::string tooLongString(maxLocStringLength + 1, '_');
3143
3144 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
3145
3146 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3147}
3148
Geoff Langc287ea62016-09-16 14:46:51 -04003149// Use this to select which configurations (e.g. which renderer, which GLES major version) these
3150// tests should be run against.
3151ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
3152 ES2_D3D9(),
3153 ES2_D3D11(),
3154 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04003155 ES2_OPENGL(),
3156 ES3_OPENGL(),
3157 ES2_OPENGLES(),
3158 ES3_OPENGLES());
3159
Jamie Madill07be8bf2017-02-02 19:59:57 -05003160ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04003161} // namespace