blob: ae4aa0fd1cf954aa74349ec9f2c19954237e0ad5 [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 Lang8c5b31c2017-09-26 18:07:44 -0400580// Test enabling the query extensions
581TEST_P(WebGLCompatibilityTest, EnableQueryExtensions)
582{
583 EXPECT_FALSE(extensionEnabled("GL_EXT_occlusion_query_boolean"));
584 EXPECT_FALSE(extensionEnabled("GL_EXT_disjoint_timer_query"));
585 EXPECT_FALSE(extensionEnabled("GL_CHROMIUM_sync_query"));
586
587 // This extensions become core in in ES3/WebGL2.
588 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
589
590 GLQueryEXT badQuery;
591
592 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, badQuery);
593 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
594
595 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE, badQuery);
596 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
597
598 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, badQuery);
599 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
600
601 glQueryCounterEXT(GL_TIMESTAMP_EXT, badQuery);
602 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
603
604 glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, badQuery);
605 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
606
607 if (extensionRequestable("GL_EXT_occlusion_query_boolean"))
608 {
609 glRequestExtensionANGLE("GL_EXT_occlusion_query_boolean");
610 EXPECT_GL_NO_ERROR();
611
612 GLQueryEXT query;
613 glBeginQueryEXT(GL_ANY_SAMPLES_PASSED_EXT, query);
614 glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT);
615 EXPECT_GL_NO_ERROR();
616 }
617
618 if (extensionRequestable("GL_EXT_disjoint_timer_query"))
619 {
620 glRequestExtensionANGLE("GL_EXT_disjoint_timer_query");
621 EXPECT_GL_NO_ERROR();
622
623 GLQueryEXT query1;
624 glBeginQueryEXT(GL_TIME_ELAPSED_EXT, query1);
625 glEndQueryEXT(GL_TIME_ELAPSED_EXT);
626 EXPECT_GL_NO_ERROR();
627
628 GLQueryEXT query2;
629 glQueryCounterEXT(query2, GL_TIMESTAMP_EXT);
630 EXPECT_GL_NO_ERROR();
631 }
632
633 if (extensionRequestable("GL_CHROMIUM_sync_query"))
634 {
635 glRequestExtensionANGLE("GL_CHROMIUM_sync_query");
636 EXPECT_GL_NO_ERROR();
637
638 GLQueryEXT query;
639 glBeginQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM, query);
640 glEndQueryEXT(GL_COMMANDS_COMPLETED_CHROMIUM);
641 EXPECT_GL_NO_ERROR();
642 }
643}
644
Geoff Lang488130e2017-09-27 13:53:11 -0400645// Test enabling the GL_ANGLE_framebuffer_multisample extension
646TEST_P(WebGLCompatibilityTest, EnableFramebufferMultisampleExtension)
647{
648 EXPECT_FALSE(extensionEnabled("GL_ANGLE_framebuffer_multisample"));
649
650 // This extensions become core in in ES3/WebGL2.
651 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
652
653 GLint maxSamples = 0;
654 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
655 EXPECT_GL_ERROR(GL_INVALID_ENUM);
656
657 GLRenderbuffer renderbuffer;
658 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
659 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, 1, GL_RGBA4, 1, 1);
660 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
661
662 if (extensionRequestable("GL_ANGLE_framebuffer_multisample"))
663 {
664 glRequestExtensionANGLE("GL_ANGLE_framebuffer_multisample");
665 EXPECT_GL_NO_ERROR();
666
667 glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
668 EXPECT_GL_NO_ERROR();
669
670 glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, maxSamples, GL_RGBA4, 1, 1);
671 EXPECT_GL_NO_ERROR();
672 }
673}
674
Geoff Lang63c5a592017-09-27 14:08:16 -0400675// Test enabling the GL_ANGLE_instanced_arrays extension
676TEST_P(WebGLCompatibilityTest, EnableInstancedArraysExtension)
677{
678 EXPECT_FALSE(extensionEnabled("GL_ANGLE_instanced_arrays"));
679
680 // This extensions become core in in ES3/WebGL2.
681 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
682
683 GLint divisor = 0;
684 glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &divisor);
685 EXPECT_GL_ERROR(GL_INVALID_ENUM);
686
687 glVertexAttribDivisorANGLE(0, 1);
688 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
689
690 if (extensionRequestable("GL_ANGLE_instanced_arrays"))
691 {
692 glRequestExtensionANGLE("GL_ANGLE_instanced_arrays");
693 EXPECT_GL_NO_ERROR();
694
695 glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_DIVISOR, &divisor);
696 glVertexAttribDivisorANGLE(0, 1);
697 EXPECT_GL_NO_ERROR();
698 }
699}
700
Geoff Lang000dab82017-09-27 14:27:07 -0400701// Test enabling the GL_ANGLE_pack_reverse_row_order extension
702TEST_P(WebGLCompatibilityTest, EnablePackReverseRowOrderExtension)
703{
704 EXPECT_FALSE(extensionEnabled("GL_ANGLE_pack_reverse_row_order"));
705
706 GLint result = 0;
707 glGetIntegerv(GL_PACK_REVERSE_ROW_ORDER_ANGLE, &result);
708 EXPECT_GL_ERROR(GL_INVALID_ENUM);
709
710 glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE);
711 EXPECT_GL_ERROR(GL_INVALID_ENUM);
712
713 if (extensionRequestable("GL_ANGLE_pack_reverse_row_order"))
714 {
715 glRequestExtensionANGLE("GL_ANGLE_pack_reverse_row_order");
716 EXPECT_GL_NO_ERROR();
717
718 glGetIntegerv(GL_PACK_REVERSE_ROW_ORDER_ANGLE, &result);
719 glPixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, GL_TRUE);
720 EXPECT_GL_NO_ERROR();
721 }
722}
723
724// Test enabling the GL_EXT_unpack_subimage extension
725TEST_P(WebGLCompatibilityTest, EnablePackUnpackSubImageExtension)
726{
727 EXPECT_FALSE(extensionEnabled("GL_EXT_unpack_subimage"));
728
729 // This extensions become core in in ES3/WebGL2.
730 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
731
732 constexpr GLenum parameters[] = {
733 GL_UNPACK_ROW_LENGTH_EXT, GL_UNPACK_SKIP_ROWS_EXT, GL_UNPACK_SKIP_PIXELS_EXT,
734 };
735
736 for (GLenum param : parameters)
737 {
738 GLint resultI = 0;
739 glGetIntegerv(param, &resultI);
740 EXPECT_GL_ERROR(GL_INVALID_ENUM);
741
742 GLfloat resultF = 0.0f;
743 glGetFloatv(param, &resultF);
744 EXPECT_GL_ERROR(GL_INVALID_ENUM);
745
746 glPixelStorei(param, 0);
747 EXPECT_GL_ERROR(GL_INVALID_ENUM);
748 }
749
750 if (extensionRequestable("GL_EXT_unpack_subimage"))
751 {
752 glRequestExtensionANGLE("GL_EXT_unpack_subimage");
753 EXPECT_GL_NO_ERROR();
754
755 for (GLenum param : parameters)
756 {
757 GLint resultI = 0;
758 glGetIntegerv(param, &resultI);
759
760 GLfloat resultF = 0.0f;
761 glGetFloatv(param, &resultF);
762
763 glPixelStorei(param, 0);
764
765 EXPECT_GL_NO_ERROR();
766 }
767 }
768}
769
770// Test enabling the GL_NV_pack_subimage extension
771TEST_P(WebGLCompatibilityTest, EnablePackPackSubImageExtension)
772{
773 EXPECT_FALSE(extensionEnabled("GL_NV_pack_subimage"));
774
775 // This extensions become core in in ES3/WebGL2.
776 ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3);
777
778 constexpr GLenum parameters[] = {
779 GL_PACK_ROW_LENGTH, GL_PACK_SKIP_ROWS, GL_PACK_SKIP_PIXELS,
780 };
781
782 for (GLenum param : parameters)
783 {
784 GLint resultI = 0;
785 glGetIntegerv(param, &resultI);
786 EXPECT_GL_ERROR(GL_INVALID_ENUM);
787
788 GLfloat resultF = 0.0f;
789 glGetFloatv(param, &resultF);
790 EXPECT_GL_ERROR(GL_INVALID_ENUM);
791
792 glPixelStorei(param, 0);
793 EXPECT_GL_ERROR(GL_INVALID_ENUM);
794 }
795
796 if (extensionRequestable("GL_NV_pack_subimage"))
797 {
798 glRequestExtensionANGLE("GL_NV_pack_subimage");
799 EXPECT_GL_NO_ERROR();
800
801 for (GLenum param : parameters)
802 {
803 GLint resultI = 0;
804 glGetIntegerv(param, &resultI);
805
806 GLfloat resultF = 0.0f;
807 glGetFloatv(param, &resultF);
808
809 glPixelStorei(param, 0);
810
811 EXPECT_GL_NO_ERROR();
812 }
813 }
814}
815
Geoff Langa0e0aeb2017-04-12 15:06:29 -0400816// Verify that the context generates the correct error when the framebuffer attachments are
817// different sizes
818TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMissmatch)
819{
820 GLFramebuffer fbo;
821 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
822
823 GLTexture textures[2];
824 glBindTexture(GL_TEXTURE_2D, textures[0]);
825 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
826 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
827
828 ASSERT_GL_NO_ERROR();
829 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
830
831 GLRenderbuffer renderbuffer;
832 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
833 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3);
834 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
835
836 ASSERT_GL_NO_ERROR();
837 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
838 glCheckFramebufferStatus(GL_FRAMEBUFFER));
839
840 if (extensionRequestable("GL_EXT_draw_buffers"))
841 {
842 glRequestExtensionANGLE("GL_EXT_draw_buffers");
843 EXPECT_GL_NO_ERROR();
844 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
845
846 glBindTexture(GL_TEXTURE_2D, textures[1]);
847 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
848 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
849 ASSERT_GL_NO_ERROR();
850
851 ASSERT_GL_NO_ERROR();
852 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
853 glCheckFramebufferStatus(GL_FRAMEBUFFER));
854
855 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
856
857 ASSERT_GL_NO_ERROR();
858 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
859
860 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
861
862 ASSERT_GL_NO_ERROR();
863 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
864 glCheckFramebufferStatus(GL_FRAMEBUFFER));
865 }
866}
867
Corentin Wallez327411e2016-12-09 11:09:17 -0500868// Test that client-side array buffers are forbidden in WebGL mode
869TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
870{
871 const std::string &vert =
872 "attribute vec3 a_pos;\n"
873 "void main()\n"
874 "{\n"
875 " gl_Position = vec4(a_pos, 1.0);\n"
876 "}\n";
877
878 const std::string &frag =
879 "precision highp float;\n"
880 "void main()\n"
881 "{\n"
882 " gl_FragColor = vec4(1.0);\n"
883 "}\n";
884
885 ANGLE_GL_PROGRAM(program, vert, frag);
886
887 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
888 ASSERT_NE(-1, posLocation);
889 glUseProgram(program.get());
890
891 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -0500892 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -0500893 glEnableVertexAttribArray(posLocation);
894
895 ASSERT_GL_NO_ERROR();
896 glDrawArrays(GL_TRIANGLES, 0, 6);
897 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
898}
899
900// Test that client-side element array buffers are forbidden in WebGL mode
901TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
902{
903 const std::string &vert =
904 "attribute vec3 a_pos;\n"
905 "void main()\n"
906 "{\n"
907 " gl_Position = vec4(a_pos, 1.0);\n"
908 "}\n";
909
910 const std::string &frag =
911 "precision highp float;\n"
912 "void main()\n"
913 "{\n"
914 " gl_FragColor = vec4(1.0);\n"
915 "}\n";
916
917 ANGLE_GL_PROGRAM(program, vert, frag);
918
919 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
920 ASSERT_NE(-1, posLocation);
921 glUseProgram(program.get());
922
923 const auto &vertices = GetQuadVertices();
924
925 GLBuffer vertexBuffer;
926 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
927 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
928 GL_STATIC_DRAW);
929
930 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
931 glEnableVertexAttribArray(posLocation);
932
Corentin Wallez327411e2016-12-09 11:09:17 -0500933 ASSERT_GL_NO_ERROR();
Corentin Wallezded1b5a2017-03-09 18:58:48 -0500934
935 // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also
936 // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate
937 // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check.
938 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1)));
Corentin Wallez327411e2016-12-09 11:09:17 -0500939 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
940}
941
Corentin Wallez672f7f32017-06-15 17:42:17 -0400942// Test that client-side array buffers are forbidden even if the program doesn't use the attribute
943TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBufferEvenNotUsedOnes)
944{
945 const std::string &vert =
946 "void main()\n"
947 "{\n"
948 " gl_Position = vec4(1.0);\n"
949 "}\n";
950
951 const std::string &frag =
952 "precision highp float;\n"
953 "void main()\n"
954 "{\n"
955 " gl_FragColor = vec4(1.0);\n"
956 "}\n";
957
958 ANGLE_GL_PROGRAM(program, vert, frag);
959
960 glUseProgram(program.get());
961
962 const auto &vertices = GetQuadVertices();
963 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
964 glEnableVertexAttribArray(0);
965
966 ASSERT_GL_NO_ERROR();
967 glDrawArrays(GL_TRIANGLES, 0, 6);
968 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
969}
970
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500971// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
972TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
973{
974 // Run the test in an FBO to make sure we have some stencil bits.
975 GLRenderbuffer renderbuffer;
976 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
977 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
978
979 GLFramebuffer framebuffer;
980 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
981 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
982 renderbuffer.get());
983
984 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
985 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
986 glUseProgram(program.get());
987 ASSERT_GL_NO_ERROR();
988
989 // Having ref and mask the same for front and back is valid.
990 glStencilMask(255);
991 glStencilFunc(GL_ALWAYS, 0, 255);
992 glDrawArrays(GL_TRIANGLES, 0, 6);
993 ASSERT_GL_NO_ERROR();
994
995 // Having a different front - back write mask generates an error.
996 glStencilMaskSeparate(GL_FRONT, 1);
997 glDrawArrays(GL_TRIANGLES, 0, 6);
998 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
999
1000 // Setting both write masks separately to the same value is valid.
1001 glStencilMaskSeparate(GL_BACK, 1);
1002 glDrawArrays(GL_TRIANGLES, 0, 6);
1003 ASSERT_GL_NO_ERROR();
1004
1005 // Having a different stencil front - back mask generates an error
1006 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
1007 glDrawArrays(GL_TRIANGLES, 0, 6);
1008 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1009
1010 // Setting both masks separately to the same value is valid.
1011 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
1012 glDrawArrays(GL_TRIANGLES, 0, 6);
1013 ASSERT_GL_NO_ERROR();
1014
1015 // Having a different stencil front - back reference generates an error
1016 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
1017 glDrawArrays(GL_TRIANGLES, 0, 6);
1018 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1019
1020 // Setting both references separately to the same value is valid.
1021 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
1022 glDrawArrays(GL_TRIANGLES, 0, 6);
1023 ASSERT_GL_NO_ERROR();
1024
1025 // Using different stencil funcs, everything being equal is valid.
1026 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
1027 glDrawArrays(GL_TRIANGLES, 0, 6);
1028 ASSERT_GL_NO_ERROR();
1029}
1030
Corentin Wallez506fc9c2016-12-21 16:53:33 -05001031// Test that GL_FIXED is forbidden
1032TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
1033{
1034 GLBuffer buffer;
1035 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1036 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1037
1038 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
1039 ASSERT_GL_NO_ERROR();
1040
1041 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
1042 EXPECT_GL_ERROR(GL_INVALID_ENUM);
1043}
1044
1045// Test the WebGL limit of 255 for the attribute stride
1046TEST_P(WebGLCompatibilityTest, MaxStride)
1047{
1048 GLBuffer buffer;
1049 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1050 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
1051
1052 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
1053 ASSERT_GL_NO_ERROR();
1054
1055 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
1056 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1057}
1058
Corentin Wallezfd456442016-12-21 17:57:00 -05001059// Test the checks for OOB reads in the vertex buffers, non-instanced version
1060TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
1061{
1062 const std::string &vert =
1063 "attribute float a_pos;\n"
1064 "void main()\n"
1065 "{\n"
1066 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1067 "}\n";
1068
1069 const std::string &frag =
1070 "precision highp float;\n"
1071 "void main()\n"
1072 "{\n"
1073 " gl_FragColor = vec4(1.0);\n"
1074 "}\n";
1075
1076 ANGLE_GL_PROGRAM(program, vert, frag);
1077
1078 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1079 ASSERT_NE(-1, posLocation);
1080 glUseProgram(program.get());
1081
1082 GLBuffer buffer;
1083 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1084 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1085
1086 glEnableVertexAttribArray(posLocation);
1087
1088 const uint8_t* zeroOffset = nullptr;
1089
1090 // Test touching the last element is valid.
1091 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1092 glDrawArrays(GL_POINTS, 0, 4);
1093 ASSERT_GL_NO_ERROR();
1094
1095 // Test touching the last element + 1 is invalid.
1096 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1097 glDrawArrays(GL_POINTS, 0, 4);
1098 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1099
1100 // Test touching the last element is valid, using a stride.
1101 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1102 glDrawArrays(GL_POINTS, 0, 4);
1103 ASSERT_GL_NO_ERROR();
1104
1105 // Test touching the last element + 1 is invalid, using a stride.
1106 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1107 glDrawArrays(GL_POINTS, 0, 4);
1108 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1109
1110 // Test any offset is valid if no vertices are drawn.
1111 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1112 glDrawArrays(GL_POINTS, 0, 0);
1113 ASSERT_GL_NO_ERROR();
1114}
1115
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001116// Test the checks for OOB reads in the index buffer
1117TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -05001118{
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001119 const std::string &vert =
1120 "attribute float a_pos;\n"
1121 "void main()\n"
1122 "{\n"
1123 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1124 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -05001125
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001126 const std::string &frag =
1127 "precision highp float;\n"
1128 "void main()\n"
1129 "{\n"
1130 " gl_FragColor = vec4(1.0);\n"
1131 "}\n";
1132
1133 ANGLE_GL_PROGRAM(program, vert, frag);
1134
1135 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1136 ASSERT_NE(-1, posLocation);
1137 glUseProgram(program.get());
1138
1139 GLBuffer vertexBuffer;
1140 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1141 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1142
1143 glEnableVertexAttribArray(posLocation);
1144
1145 const uint8_t *zeroOffset = nullptr;
1146 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
1147
1148 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset);
1149
1150 GLBuffer indexBuffer;
1151 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1152 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -05001153 ASSERT_GL_NO_ERROR();
1154
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001155 // Test touching the last index is valid
1156 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1157 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -05001158
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001159 // Test touching the last + 1 element is invalid
1160 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
1161 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -05001162
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001163 // Test any offset if valid if count is zero
1164 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
1165 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -05001166
1167 // Test touching the first index is valid
1168 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
1169 ASSERT_GL_NO_ERROR();
1170
1171 // Test touching the first - 1 index is invalid
1172 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
1173 // the historic behavior of WebGL implementations
1174 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
1175 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -05001176}
1177
Frank Henigman6137ddc2017-02-10 18:55:07 -05001178// Test depth range with 'near' more or less than 'far.'
1179TEST_P(WebGLCompatibilityTest, DepthRange)
1180{
1181 glDepthRangef(0, 1);
1182 ASSERT_GL_NO_ERROR();
1183
1184 glDepthRangef(.5, .5);
1185 ASSERT_GL_NO_ERROR();
1186
1187 glDepthRangef(1, 0);
1188 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1189}
1190
Frank Henigman146e8a12017-03-02 23:22:37 -05001191// Test all blend function combinations.
1192// In WebGL it is invalid to combine constant color with constant alpha.
1193TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
1194{
1195 constexpr GLenum srcFunc[] = {
1196 GL_ZERO,
1197 GL_ONE,
1198 GL_SRC_COLOR,
1199 GL_ONE_MINUS_SRC_COLOR,
1200 GL_DST_COLOR,
1201 GL_ONE_MINUS_DST_COLOR,
1202 GL_SRC_ALPHA,
1203 GL_ONE_MINUS_SRC_ALPHA,
1204 GL_DST_ALPHA,
1205 GL_ONE_MINUS_DST_ALPHA,
1206 GL_CONSTANT_COLOR,
1207 GL_ONE_MINUS_CONSTANT_COLOR,
1208 GL_CONSTANT_ALPHA,
1209 GL_ONE_MINUS_CONSTANT_ALPHA,
1210 GL_SRC_ALPHA_SATURATE,
1211 };
1212
1213 constexpr GLenum dstFunc[] = {
1214 GL_ZERO, GL_ONE,
1215 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
1216 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
1217 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
1218 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
1219 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
1220 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
1221 };
1222
1223 for (GLenum src : srcFunc)
1224 {
1225 for (GLenum dst : dstFunc)
1226 {
1227 glBlendFunc(src, dst);
1228 CheckBlendFunctions(src, dst);
1229 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
1230 CheckBlendFunctions(src, dst);
1231 }
1232 }
1233}
1234
Geoff Langfc32e8b2017-05-31 14:16:59 -04001235// Test that binding/querying uniforms and attributes with invalid names generates errors
1236TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
1237{
1238 const std::string validAttribName =
1239 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
1240 const std::string validUniformName =
1241 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
Geoff Langa71a98e2017-06-19 15:15:00 -04001242 std::vector<char> invalidSet = {'"', '$', '`', '@', '\''};
1243 if (getClientMajorVersion() < 3)
1244 {
1245 invalidSet.push_back('\\');
1246 }
Geoff Langfc32e8b2017-05-31 14:16:59 -04001247
1248 std::string vert = "attribute float ";
1249 vert += validAttribName;
1250 vert +=
1251 ";\n"
1252 "void main()\n"
1253 "{\n"
1254 " gl_Position = vec4(1.0);\n"
1255 "}\n";
1256
1257 std::string frag =
1258 "precision highp float;\n"
1259 "uniform vec4 ";
1260 frag += validUniformName;
Geoff Langcab92ee2017-07-19 17:32:07 -04001261 // Insert illegal characters into comments
Geoff Langfc32e8b2017-05-31 14:16:59 -04001262 frag +=
1263 ";\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001264 " // $ \" @ /*\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001265 "void main()\n"
Geoff Langcab92ee2017-07-19 17:32:07 -04001266 "{/*\n"
1267 " ` @ $\n"
1268 " */gl_FragColor = vec4(1.0);\n"
Geoff Langfc32e8b2017-05-31 14:16:59 -04001269 "}\n";
1270
1271 ANGLE_GL_PROGRAM(program, vert, frag);
1272 EXPECT_GL_NO_ERROR();
1273
1274 for (char invalidChar : invalidSet)
1275 {
1276 std::string invalidName = validAttribName + invalidChar;
1277 glGetAttribLocation(program, invalidName.c_str());
1278 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1279 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1280
1281 glBindAttribLocation(program, 0, invalidName.c_str());
1282 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1283 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1284 }
1285
1286 for (char invalidChar : invalidSet)
1287 {
1288 std::string invalidName = validUniformName + invalidChar;
1289 glGetUniformLocation(program, invalidName.c_str());
1290 EXPECT_GL_ERROR(GL_INVALID_VALUE)
1291 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
1292 }
1293
1294 for (char invalidChar : invalidSet)
1295 {
1296 std::string invalidAttribName = validAttribName + invalidChar;
1297 const char *invalidVert[] = {
1298 "attribute float ",
1299 invalidAttribName.c_str(),
1300 ";\n",
1301 "void main()\n",
1302 "{\n",
1303 " gl_Position = vec4(1.0);\n",
1304 "}\n",
1305 };
1306
1307 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1308 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
1309 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1310 glDeleteShader(shader);
1311 }
1312}
1313
Geoff Langcab92ee2017-07-19 17:32:07 -04001314// Test that line continuation is handled correctly when valdiating shader source
1315TEST_P(WebGL2CompatibilityTest, ShaderSourceLineContinuation)
1316{
1317 const char *validVert =
1318 "#version 300 es\n"
1319 "precision mediump float;\n"
1320 "\n"
1321 "void main ()\n"
1322 "{\n"
1323 " float f\\\n"
1324 "oo = 1.0;\n"
1325 " gl_Position = vec4(foo);\n"
1326 "}\n";
1327
1328 const char *invalidVert =
1329 "#version 300 es\n"
1330 "precision mediump float;\n"
1331 "\n"
1332 "void main ()\n"
1333 "{\n"
1334 " float f\\$\n"
1335 "oo = 1.0;\n"
1336 " gl_Position = vec4(foo);\n"
1337 "}\n";
1338
1339 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1340 glShaderSource(shader, 1, &validVert, nullptr);
1341 EXPECT_GL_NO_ERROR();
1342 glShaderSource(shader, 1, &invalidVert, nullptr);
1343 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1344 glDeleteShader(shader);
1345}
1346
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001347// Tests bindAttribLocations for reserved prefixes and length limits
1348TEST_P(WebGLCompatibilityTest, BindAttribLocationLimitation)
1349{
1350 constexpr int maxLocStringLength = 256;
1351 const std::string tooLongString(maxLocStringLength + 1, '_');
1352
1353 glBindAttribLocation(0, 0, "_webgl_var");
1354
1355 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1356
1357 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
1358
1359 EXPECT_GL_ERROR(GL_INVALID_VALUE);
1360}
1361
Corentin Wallezfd456442016-12-21 17:57:00 -05001362// Test the checks for OOB reads in the vertex buffers, instanced version
1363TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
1364{
1365 const std::string &vert =
1366 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -04001367 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -05001368 "void main()\n"
1369 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -04001370 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -05001371 "}\n";
1372
1373 const std::string &frag =
1374 "precision highp float;\n"
1375 "void main()\n"
1376 "{\n"
1377 " gl_FragColor = vec4(1.0);\n"
1378 "}\n";
1379
1380 ANGLE_GL_PROGRAM(program, vert, frag);
1381
1382 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1383 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -04001384
1385 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
1386 ASSERT_NE(-1, wLocation);
1387
Corentin Wallezfd456442016-12-21 17:57:00 -05001388 glUseProgram(program.get());
1389
1390 GLBuffer buffer;
1391 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1392 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1393
1394 glEnableVertexAttribArray(posLocation);
1395 glVertexAttribDivisor(posLocation, 1);
1396
Geoff Lang407d4e72017-04-12 14:54:11 -04001397 glEnableVertexAttribArray(wLocation);
1398 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
1399 glVertexAttribDivisor(wLocation, 0);
1400
Corentin Wallezfd456442016-12-21 17:57:00 -05001401 const uint8_t* zeroOffset = nullptr;
1402
1403 // Test touching the last element is valid.
1404 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
1405 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1406 ASSERT_GL_NO_ERROR();
1407
1408 // Test touching the last element + 1 is invalid.
1409 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
1410 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1411 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1412
1413 // Test touching the last element is valid, using a stride.
1414 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
1415 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1416 ASSERT_GL_NO_ERROR();
1417
1418 // Test touching the last element + 1 is invalid, using a stride.
1419 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
1420 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1421 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1422
1423 // Test any offset is valid if no vertices are drawn.
1424 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
1425 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
1426 ASSERT_GL_NO_ERROR();
1427}
1428
Corentin Wallez0dc97812017-06-22 14:38:44 -04001429// Test that having no attributes with a zero divisor is valid in WebGL2
Geoff Lang407d4e72017-04-12 14:54:11 -04001430TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
1431{
1432 const std::string &vert =
1433 "attribute float a_pos;\n"
1434 "void main()\n"
1435 "{\n"
1436 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
1437 "}\n";
1438
1439 const std::string &frag =
1440 "precision highp float;\n"
1441 "void main()\n"
1442 "{\n"
1443 " gl_FragColor = vec4(1.0);\n"
1444 "}\n";
1445
1446 ANGLE_GL_PROGRAM(program, vert, frag);
1447
1448 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1449 ASSERT_NE(-1, posLocation);
1450
1451 glUseProgram(program.get());
1452
1453 GLBuffer buffer;
1454 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1455 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1456
1457 glEnableVertexAttribArray(posLocation);
1458 glVertexAttribDivisor(posLocation, 1);
1459
Geoff Lang407d4e72017-04-12 14:54:11 -04001460 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1461 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
Geoff Lang407d4e72017-04-12 14:54:11 -04001462 ASSERT_GL_NO_ERROR();
1463}
1464
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001465// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1466TEST_P(WebGLCompatibilityTest, NPOT)
1467{
1468 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1469
1470 // Create a texture and set an NPOT mip 0, should always be acceptable.
1471 GLTexture texture;
1472 glBindTexture(GL_TEXTURE_2D, texture.get());
1473 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1474 ASSERT_GL_NO_ERROR();
1475
1476 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1477 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1478 if (getClientMajorVersion() < 3)
1479 {
1480 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1481 }
1482 else
1483 {
1484 ASSERT_GL_NO_ERROR();
1485 }
1486
1487 if (extensionRequestable("GL_OES_texture_npot"))
1488 {
1489 glRequestExtensionANGLE("GL_OES_texture_npot");
1490 ASSERT_GL_NO_ERROR();
1491
1492 // Try again to set NPOT mip 1
1493 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1494 ASSERT_GL_NO_ERROR();
1495 }
1496}
1497
Jamie Madillcad97ee2017-02-02 18:52:44 -05001498template <typename T>
1499void FillTexture2D(GLuint texture,
1500 GLsizei width,
1501 GLsizei height,
1502 const T &onePixelData,
1503 GLint level,
1504 GLint internalFormat,
1505 GLenum format,
1506 GLenum type)
1507{
1508 std::vector<T> allPixelsData(width * height, onePixelData);
1509
1510 glBindTexture(GL_TEXTURE_2D, texture);
1511 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
1512 allPixelsData.data());
1513 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1514 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1515 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1516 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1517}
1518
Frank Henigman875bbba2017-02-08 16:38:17 -05001519// Test that unset gl_Position defaults to (0,0,0,0).
1520TEST_P(WebGLCompatibilityTest, DefaultPosition)
1521{
1522 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
1523 // and green otherwise. The center of each quadrant will be red if and only if all
1524 // four corners are red.
1525 const std::string vertexShader =
1526 "attribute vec3 pos;\n"
1527 "varying vec4 color;\n"
1528 "void main() {\n"
1529 " if (gl_Position == vec4(0,0,0,0)) {\n"
1530 " color = vec4(1,0,0,1);\n"
1531 " } else {\n"
1532 " color = vec4(0,1,0,1);\n"
1533 " }\n"
1534 " gl_Position = vec4(pos,1);\n"
1535 "}\n";
1536
1537 const std::string fragmentShader =
1538 "precision mediump float;\n"
1539 "varying vec4 color;\n"
1540 "void main() {\n"
1541 " gl_FragColor = color;\n"
1542 "}\n";
1543
1544 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1545 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
1546 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1547 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1548 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1549 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1550}
1551
Jamie Madilla4595b82017-01-11 17:36:34 -05001552// Tests that a rendering feedback loop triggers a GL error under WebGL.
1553// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
1554TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
1555{
1556 const std::string vertexShader =
1557 "attribute vec4 a_position;\n"
1558 "varying vec2 v_texCoord;\n"
1559 "void main() {\n"
1560 " gl_Position = a_position;\n"
1561 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
1562 "}\n";
1563
1564 const std::string fragmentShader =
1565 "precision mediump float;\n"
1566 "varying vec2 v_texCoord;\n"
1567 "uniform sampler2D u_texture;\n"
1568 "void main() {\n"
1569 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
1570 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
1571 "}\n";
1572
1573 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001574 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001575
1576 ASSERT_GL_NO_ERROR();
1577
1578 GLFramebuffer framebuffer;
1579 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1580 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1581
1582 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1583
1584 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1585
1586 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
1587 ASSERT_NE(-1, uniformLoc);
1588
1589 glUseProgram(program.get());
1590 glUniform1i(uniformLoc, 0);
1591 glDisable(GL_BLEND);
1592 glDisable(GL_DEPTH_TEST);
1593 ASSERT_GL_NO_ERROR();
1594
1595 // Drawing with a texture that is also bound to the current framebuffer should fail
1596 glBindTexture(GL_TEXTURE_2D, texture.get());
1597 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1598 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1599
1600 // Ensure that the texture contents did not change after the previous render
1601 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1602 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1603 ASSERT_GL_NO_ERROR();
1604 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1605
1606 // Drawing when texture is bound to an inactive uniform should succeed
1607 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001608 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001609
1610 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1611 glActiveTexture(GL_TEXTURE1);
1612 glBindTexture(GL_TEXTURE_2D, texture.get());
1613 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1614 ASSERT_GL_NO_ERROR();
1615 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1616}
1617
Bryan Bernhart58806562017-01-05 13:09:31 -08001618// Test for the max draw buffers and color attachments.
1619TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
1620{
1621 // This test only applies to ES2.
1622 if (getClientMajorVersion() != 2)
1623 {
1624 return;
1625 }
1626
1627 GLFramebuffer fbo[2];
1628 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
1629
1630 // Test that is valid when we bind with a single attachment point.
1631 GLTexture texture;
1632 glBindTexture(GL_TEXTURE_2D, texture.get());
1633 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1634 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1635 ASSERT_GL_NO_ERROR();
1636
1637 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
1638 // attachment point.
1639 if (extensionRequestable("GL_EXT_draw_buffers"))
1640 {
1641 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1642 EXPECT_GL_NO_ERROR();
1643 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1644
1645 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
1646
1647 GLTexture texture2;
1648 glBindTexture(GL_TEXTURE_2D, texture2.get());
1649 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1650 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
1651 0);
1652 ASSERT_GL_NO_ERROR();
1653 }
1654}
1655
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001656// Test that the offset in the index buffer is forced to be a multiple of the element size
1657TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
1658{
1659 const std::string &vert =
1660 "attribute vec3 a_pos;\n"
1661 "void main()\n"
1662 "{\n"
1663 " gl_Position = vec4(a_pos, 1.0);\n"
1664 "}\n";
1665
1666 const std::string &frag =
1667 "precision highp float;\n"
1668 "void main()\n"
1669 "{\n"
1670 " gl_FragColor = vec4(1.0);\n"
1671 "}\n";
1672
1673 ANGLE_GL_PROGRAM(program, vert, frag);
1674
1675 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1676 ASSERT_NE(-1, posLocation);
1677 glUseProgram(program.get());
1678
1679 const auto &vertices = GetQuadVertices();
1680
1681 GLBuffer vertexBuffer;
1682 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1683 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1684 GL_STATIC_DRAW);
1685
1686 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1687 glEnableVertexAttribArray(posLocation);
1688
1689 GLBuffer indexBuffer;
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001690 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0, 0};
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001691 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1692 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1693
1694 ASSERT_GL_NO_ERROR();
1695
1696 const char *zeroIndices = nullptr;
1697
1698 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1699 ASSERT_GL_NO_ERROR();
1700
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001701 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001702 ASSERT_GL_NO_ERROR();
1703
Brandon Jonesed5b46f2017-07-21 08:39:17 -07001704 glDrawElements(GL_TRIANGLES, 4, GL_UNSIGNED_SHORT, zeroIndices + 1);
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001705 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1706}
1707
1708// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1709// size
1710TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1711{
1712 const char *zeroOffset = nullptr;
1713
1714 // Base case, vector of two floats
1715 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1716 ASSERT_GL_NO_ERROR();
1717
1718 // Test setting a non-multiple offset
1719 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1720 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1721 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1722 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1723 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1724 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1725
1726 // Test setting a non-multiple stride
1727 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1728 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1729 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1730 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1731 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1732 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1733}
1734
Jamie Madillcad97ee2017-02-02 18:52:44 -05001735void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1736 const std::array<GLenum, 2> &drawBuffers,
1737 GLenum expectedError)
1738{
1739 glDrawBuffersEXT(2, drawBuffers.data());
1740
1741 // Make sure framebuffer is complete before feedback loop detection
1742 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1743
1744 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1745
1746 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1747 // it should be NO_ERROR"
1748 EXPECT_GL_ERROR(expectedError);
1749}
1750
1751// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1752// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1753TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1754{
1755 const std::string vertexShader =
1756 "attribute vec4 aPosition;\n"
1757 "varying vec2 texCoord;\n"
1758 "void main() {\n"
1759 " gl_Position = aPosition;\n"
1760 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1761 "}\n";
1762
1763 const std::string fragmentShader =
1764 "#extension GL_EXT_draw_buffers : require\n"
1765 "precision mediump float;\n"
1766 "uniform sampler2D tex;\n"
1767 "varying vec2 texCoord;\n"
1768 "void main() {\n"
1769 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1770 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1771 "}\n";
1772
1773 GLsizei width = 8;
1774 GLsizei height = 8;
1775
1776 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1777 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1778 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1779 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1780 {
1781 // No WEBGL_draw_buffers support -- this is legal.
1782 return;
1783 }
1784
1785 GLint maxDrawBuffers = 0;
1786 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1787
1788 if (maxDrawBuffers < 2)
1789 {
1790 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1791 return;
1792 }
1793
1794 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1795 glUseProgram(program.get());
1796 glViewport(0, 0, width, height);
1797
1798 GLTexture tex0;
1799 GLTexture tex1;
1800 GLFramebuffer fbo;
1801 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1802 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1803 ASSERT_GL_NO_ERROR();
1804
1805 glBindTexture(GL_TEXTURE_2D, tex1.get());
1806 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1807 ASSERT_NE(-1, texLoc);
1808 glUniform1i(texLoc, 0);
1809 ASSERT_GL_NO_ERROR();
1810
1811 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1812 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1813 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1814 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1815
1816 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1817 GL_INVALID_OPERATION);
1818 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1819 GL_INVALID_OPERATION);
1820 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1821}
1822
Jamie Madill07be8bf2017-02-02 19:59:57 -05001823// Test tests that texture copying feedback loops are properly rejected in WebGL.
1824// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1825TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1826{
1827 GLTexture texture;
1828 glBindTexture(GL_TEXTURE_2D, texture.get());
1829 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1830 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1831 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1832 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1833 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1834
1835 GLTexture texture2;
1836 glBindTexture(GL_TEXTURE_2D, texture2.get());
1837 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1838 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1839 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1840 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1841 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1842
1843 GLFramebuffer framebuffer;
1844 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1845 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1846
1847 // framebuffer should be FRAMEBUFFER_COMPLETE.
1848 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1849 ASSERT_GL_NO_ERROR();
1850
1851 // testing copyTexImage2D
1852
1853 // copyTexImage2D to same texture but different level
1854 glBindTexture(GL_TEXTURE_2D, texture.get());
1855 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1856 EXPECT_GL_NO_ERROR();
1857
1858 // copyTexImage2D to same texture same level, invalid feedback loop
1859 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1860 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1861
1862 // copyTexImage2D to different texture
1863 glBindTexture(GL_TEXTURE_2D, texture2.get());
1864 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1865 EXPECT_GL_NO_ERROR();
1866
1867 // testing copyTexSubImage2D
1868
1869 // copyTexSubImage2D to same texture but different level
1870 glBindTexture(GL_TEXTURE_2D, texture.get());
1871 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1872 EXPECT_GL_NO_ERROR();
1873
1874 // copyTexSubImage2D to same texture same level, invalid feedback loop
1875 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1876 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1877
1878 // copyTexSubImage2D to different texture
1879 glBindTexture(GL_TEXTURE_2D, texture2.get());
1880 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1881 EXPECT_GL_NO_ERROR();
1882}
1883
1884void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1885 const std::array<GLenum, 2> &drawBuffers,
1886 GLenum expectedError)
1887{
1888 glDrawBuffers(2, drawBuffers.data());
1889
1890 // Make sure framebuffer is complete before feedback loop detection
1891 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1892
1893 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1894
1895 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1896 // it should be NO_ERROR"
1897 EXPECT_GL_ERROR(expectedError);
1898}
1899
Yuly Novikov817232e2017-02-22 18:36:10 -05001900// Tests invariance matching rules between built in varyings.
1901// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1902TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1903{
1904 const std::string vertexShaderVariant =
1905 "varying vec4 v_varying;\n"
1906 "void main()\n"
1907 "{\n"
1908 " gl_PointSize = 1.0;\n"
1909 " gl_Position = v_varying;\n"
1910 "}";
1911 const std::string fragmentShaderInvariantGlFragCoord =
1912 "invariant gl_FragCoord;\n"
1913 "void main()\n"
1914 "{\n"
1915 " gl_FragColor = gl_FragCoord;\n"
1916 "}";
1917 const std::string fragmentShaderInvariantGlPointCoord =
1918 "invariant gl_PointCoord;\n"
1919 "void main()\n"
1920 "{\n"
1921 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1922 "}";
1923
1924 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1925 EXPECT_EQ(0u, program);
1926
1927 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1928 EXPECT_EQ(0u, program);
1929}
1930
Yuly Novikovcaa5cda2017-06-15 21:14:03 -04001931// Tests global namespace conflicts between uniforms and attributes.
1932// Based on WebGL test conformance/glsl/misc/shaders-with-name-conflicts.html.
1933TEST_P(WebGLCompatibilityTest, GlobalNamesConflict)
1934{
1935 const std::string vertexShader =
1936 "attribute vec4 foo;\n"
1937 "void main()\n"
1938 "{\n"
1939 " gl_Position = foo;\n"
1940 "}";
1941 const std::string fragmentShader =
1942 "precision mediump float;\n"
1943 "uniform vec4 foo;\n"
1944 "void main()\n"
1945 "{\n"
1946 " gl_FragColor = foo;\n"
1947 "}";
1948
1949 GLuint program = CompileProgram(vertexShader, fragmentShader);
1950 EXPECT_EQ(0u, program);
1951}
1952
Geoff Lang966c9402017-04-18 12:38:27 -04001953// Test dimension and image size validation of compressed textures
1954TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
1955{
1956 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
1957 {
1958 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
1959 }
1960
1961 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
1962 {
1963 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
1964 << std::endl;
1965 return;
1966 }
1967
1968 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
1969
1970 GLTexture texture;
1971 glBindTexture(GL_TEXTURE_2D, texture);
1972
1973 // Regular case, verify that it works
1974 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1975 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1976 ASSERT_GL_NO_ERROR();
1977
1978 // Test various dimensions that are not valid
1979 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
1980 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1981 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1982
1983 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
1984 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1985 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1986
1987 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1988 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1989 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1990
1991 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1992 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1993 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1994
1995 // Test various image sizes that are not valid
1996 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1997 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
1998 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1999
2000 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2001 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
2002 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2003
2004 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
2005 CompressedImageDXT1);
2006 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2007
2008 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
2009 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2010 ASSERT_GL_ERROR(GL_INVALID_VALUE);
2011
2012 // Fill a full mip chain and verify that it works
2013 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
2014 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2015 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
2016 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2017 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
2018 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2019 ASSERT_GL_NO_ERROR();
2020
2021 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2022 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2023 ASSERT_GL_NO_ERROR();
2024
2025 // Test that non-block size sub-uploads are not valid for the 0 mip
2026 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2027 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2028 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2029
2030 // Test that non-block size sub-uploads are valid for if they fill the whole mip
2031 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2032 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2033 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2034 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2035 ASSERT_GL_NO_ERROR();
2036
2037 // Test that if the format miss-matches the texture, an error is generated
2038 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2039 sizeof(CompressedImageDXT1), CompressedImageDXT1);
2040 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2041}
2042
Geoff Lang677bb6f2017-04-05 12:40:40 -04002043TEST_P(WebGLCompatibilityTest, L32FTextures)
2044{
2045 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
2046 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
2047
2048 for (auto extension : FloatingPointTextureExtensions)
2049 {
2050 if (strlen(extension) > 0 && extensionRequestable(extension))
2051 {
2052 glRequestExtensionANGLE(extension);
2053 ASSERT_GL_NO_ERROR();
2054 }
2055
2056 // Unsized L 32F
2057 {
2058 bool texture = extensionEnabled("GL_OES_texture_float");
2059 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2060 bool render = false;
2061 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
2062 textureData, readPixelData);
2063 }
2064
2065 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2066 {
2067 // Sized L 32F
2068 bool texture = extensionEnabled("GL_OES_texture_float") &&
2069 extensionEnabled("GL_EXT_texture_storage");
2070 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2071 bool render = false;
2072 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
2073 render, textureData, readPixelData);
2074 }
2075 }
2076}
2077
2078TEST_P(WebGLCompatibilityTest, A32FTextures)
2079{
2080 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
2081 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
2082
2083 for (auto extension : FloatingPointTextureExtensions)
2084 {
2085 if (strlen(extension) > 0 && extensionRequestable(extension))
2086 {
2087 glRequestExtensionANGLE(extension);
2088 ASSERT_GL_NO_ERROR();
2089 }
2090
2091 // Unsized A 32F
2092 {
2093 bool texture = extensionEnabled("GL_OES_texture_float");
2094 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2095 bool render = false;
2096 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
2097 textureData, readPixelData);
2098 }
2099
2100 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2101 {
2102 // Sized A 32F
2103 bool texture = extensionEnabled("GL_OES_texture_float") &&
2104 extensionEnabled("GL_EXT_texture_storage");
2105 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2106 bool render = false;
2107 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
2108 textureData, readPixelData);
2109 }
2110 }
2111}
2112
2113TEST_P(WebGLCompatibilityTest, LA32FTextures)
2114{
2115 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
2116 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
2117 textureData[1]};
2118
2119 for (auto extension : FloatingPointTextureExtensions)
2120 {
2121 if (strlen(extension) > 0 && extensionRequestable(extension))
2122 {
2123 glRequestExtensionANGLE(extension);
2124 ASSERT_GL_NO_ERROR();
2125 }
2126
2127 // Unsized LA 32F
2128 {
2129 bool texture = extensionEnabled("GL_OES_texture_float");
2130 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2131 bool render = false;
2132 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2133 filter, render, textureData, readPixelData);
2134 }
2135
2136 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2137 {
2138 // Sized LA 32F
2139 bool texture = extensionEnabled("GL_OES_texture_float") &&
2140 extensionEnabled("GL_EXT_texture_storage");
2141 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2142 bool render = false;
2143 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
2144 filter, render, textureData, readPixelData);
2145 }
2146 }
2147}
2148
2149TEST_P(WebGLCompatibilityTest, R32FTextures)
2150{
2151 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
2152
2153 for (auto extension : FloatingPointTextureExtensions)
2154 {
2155 if (strlen(extension) > 0 && extensionRequestable(extension))
2156 {
2157 glRequestExtensionANGLE(extension);
2158 ASSERT_GL_NO_ERROR();
2159 }
2160
2161 // Unsized R 32F
2162 {
2163 bool texture =
2164 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
2165 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2166 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2167 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2168 }
2169
2170 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2171 {
2172 // Sized R 32F
2173 bool texture =
2174 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2175 extensionEnabled("GL_EXT_texture_rg") &&
2176 extensionEnabled("GL_EXT_texture_storage"));
2177 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2178 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2179 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
2180 }
2181 }
2182}
2183
2184TEST_P(WebGLCompatibilityTest, RG32FTextures)
2185{
2186 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
2187
2188 for (auto extension : FloatingPointTextureExtensions)
2189 {
2190 if (strlen(extension) > 0 && extensionRequestable(extension))
2191 {
2192 glRequestExtensionANGLE(extension);
2193 ASSERT_GL_NO_ERROR();
2194 }
2195
2196 // Unsized RG 32F
2197 {
2198 bool texture =
2199 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
2200 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2201 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2202 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2203 }
2204
2205 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2206 {
2207 // Sized RG 32F
2208 bool texture =
2209 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2210 extensionEnabled("GL_EXT_texture_rg") &&
2211 extensionEnabled("GL_EXT_texture_storage"));
2212 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2213 bool render = extensionEnabled("GL_EXT_color_buffer_float");
2214 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
2215 }
2216 }
2217}
2218
2219TEST_P(WebGLCompatibilityTest, RGB32FTextures)
2220{
Geoff Lang40762ef2017-05-08 13:47:03 -04002221 if (IsLinux() && IsIntel())
2222 {
2223 std::cout << "Test skipped on Linux Intel." << std::endl;
2224 return;
2225 }
2226
Geoff Lang677bb6f2017-04-05 12:40:40 -04002227 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
2228
2229 for (auto extension : FloatingPointTextureExtensions)
2230 {
2231 if (strlen(extension) > 0 && extensionRequestable(extension))
2232 {
2233 glRequestExtensionANGLE(extension);
2234 ASSERT_GL_NO_ERROR();
2235 }
2236
2237 // Unsized RGB 32F
2238 {
2239 bool texture = extensionEnabled("GL_OES_texture_float");
2240 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2241 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2242 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
2243 }
2244
2245 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2246 {
2247 // Sized RGBA 32F
2248 bool texture =
2249 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2250 extensionEnabled("GL_EXT_texture_storage"));
2251 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2252 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
2253 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
2254 data);
2255 }
2256 }
2257}
2258
2259TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
2260{
2261 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2262
2263 for (auto extension : FloatingPointTextureExtensions)
2264 {
2265 if (strlen(extension) > 0 && extensionRequestable(extension))
2266 {
2267 glRequestExtensionANGLE(extension);
2268 ASSERT_GL_NO_ERROR();
2269 }
2270
2271 // Unsized RGBA 32F
2272 {
2273 bool texture = extensionEnabled("GL_OES_texture_float");
2274 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2275 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2276 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2277 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
2278 }
2279
2280 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2281 {
2282 // Sized RGBA 32F
2283 bool texture =
2284 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
2285 extensionEnabled("GL_EXT_texture_storage"));
2286 bool filter = extensionEnabled("GL_OES_texture_float_linear");
2287 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
2288 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
2289 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
2290 data);
2291 }
2292 }
2293}
2294
2295TEST_P(WebGLCompatibilityTest, R16FTextures)
2296{
2297 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
2298 const GLushort textureData[] = {
2299 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2300 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2301
2302 for (auto extension : FloatingPointTextureExtensions)
2303 {
2304 if (strlen(extension) > 0 && extensionRequestable(extension))
2305 {
2306 glRequestExtensionANGLE(extension);
2307 ASSERT_GL_NO_ERROR();
2308 }
2309
2310 // Unsized R 16F (OES)
2311 {
2312 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2313 extensionEnabled("GL_EXT_texture_rg");
2314 bool filter = getClientMajorVersion() >= 3 ||
2315 extensionEnabled("GL_OES_texture_half_float_linear");
2316 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2317 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
2318 textureData, readPixelsData);
2319 }
2320
2321 // Unsized R 16F
2322 {
2323 bool texture = false;
2324 bool filter = false;
2325 bool render = false;
2326 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2327 textureData, readPixelsData);
2328 }
2329
2330 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2331 {
2332 // Sized R 16F
2333 bool texture = getClientMajorVersion() >= 3;
2334 bool filter = getClientMajorVersion() >= 3 ||
2335 extensionEnabled("GL_OES_texture_half_float_linear");
2336 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2337 extensionEnabled("GL_EXT_color_buffer_float");
2338 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
2339 textureData, readPixelsData);
2340 }
2341 }
2342}
2343
2344TEST_P(WebGLCompatibilityTest, RG16FTextures)
2345{
2346 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
2347 const GLushort textureData[] = {
2348 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2349 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2350
2351 for (auto extension : FloatingPointTextureExtensions)
2352 {
2353 if (strlen(extension) > 0 && extensionRequestable(extension))
2354 {
2355 glRequestExtensionANGLE(extension);
2356 ASSERT_GL_NO_ERROR();
2357 }
2358
2359 // Unsized RG 16F (OES)
2360 {
2361 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
2362 extensionEnabled("GL_EXT_texture_rg");
2363 bool filter = getClientMajorVersion() >= 3 ||
2364 extensionEnabled("GL_OES_texture_half_float_linear");
2365 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
2366 extensionEnabled("GL_EXT_texture_rg");
2367 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
2368 textureData, readPixelsData);
2369 }
2370
2371 // Unsized RG 16F
2372 {
2373 bool texture = false;
2374 bool filter = false;
2375 bool render = false;
2376 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2377 textureData, readPixelsData);
2378 }
2379
2380 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2381 {
2382 // Sized RG 16F
2383 bool texture = getClientMajorVersion() >= 3;
2384 bool filter = getClientMajorVersion() >= 3 ||
2385 extensionEnabled("GL_OES_texture_half_float_linear");
2386 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2387 extensionEnabled("GL_EXT_color_buffer_float");
2388 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
2389 textureData, readPixelsData);
2390 }
2391 }
2392}
2393
2394TEST_P(WebGLCompatibilityTest, RGB16FTextures)
2395{
Geoff Lang40762ef2017-05-08 13:47:03 -04002396 if (IsOzone() && IsIntel())
2397 {
2398 std::cout << "Test skipped on Intel Ozone." << std::endl;
2399 return;
2400 }
2401
Geoff Lang677bb6f2017-04-05 12:40:40 -04002402 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
2403 const GLushort textureData[] = {
2404 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2405 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2406
2407 for (auto extension : FloatingPointTextureExtensions)
2408 {
2409 if (strlen(extension) > 0 && extensionRequestable(extension))
2410 {
2411 glRequestExtensionANGLE(extension);
2412 ASSERT_GL_NO_ERROR();
2413 }
2414
2415 // Unsized RGB 16F (OES)
2416 {
2417 bool texture = extensionEnabled("GL_OES_texture_half_float");
2418 bool filter = getClientMajorVersion() >= 3 ||
2419 extensionEnabled("GL_OES_texture_half_float_linear");
2420 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2421 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
2422 textureData, readPixelsData);
2423 }
2424
2425 // Unsized RGB 16F
2426 {
2427 bool texture = false;
2428 bool filter = false;
2429 bool render = false;
2430 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2431 textureData, readPixelsData);
2432 }
2433
2434 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2435 {
2436 // Sized RGB 16F
2437 bool texture = getClientMajorVersion() >= 3;
2438 bool filter = getClientMajorVersion() >= 3 ||
2439 extensionEnabled("GL_OES_texture_half_float_linear");
2440 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
2441 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
2442 textureData, readPixelsData);
2443 }
2444 }
2445}
2446
2447TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
2448{
Geoff Lang40762ef2017-05-08 13:47:03 -04002449 if (IsOzone() && IsIntel())
2450 {
2451 std::cout << "Test skipped on Intel Ozone." << std::endl;
2452 return;
2453 }
2454
Geoff Lang677bb6f2017-04-05 12:40:40 -04002455 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
2456 const GLushort textureData[] = {
2457 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
2458 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
2459
2460 for (auto extension : FloatingPointTextureExtensions)
2461 {
2462 if (strlen(extension) > 0 && extensionRequestable(extension))
2463 {
2464 glRequestExtensionANGLE(extension);
2465 ASSERT_GL_NO_ERROR();
2466 }
2467
2468 // Unsized RGBA 16F (OES)
2469 {
2470 bool texture = extensionEnabled("GL_OES_texture_half_float");
2471 bool filter = getClientMajorVersion() >= 3 ||
2472 extensionEnabled("GL_OES_texture_half_float_linear");
2473 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2474 extensionEnabled("GL_EXT_color_buffer_float");
2475 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2476 textureData, readPixelsData);
2477 }
2478
2479 // Unsized RGBA 16F
2480 {
2481 bool texture = false;
2482 bool filter = false;
2483 bool render = false;
2484 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2485 textureData, readPixelsData);
2486 }
2487
2488 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2489 {
2490 // Sized RGBA 16F
2491 bool texture = getClientMajorVersion() >= 3;
2492 bool filter = getClientMajorVersion() >= 3 ||
2493 extensionEnabled("GL_OES_texture_half_float_linear");
2494 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2495 extensionEnabled("GL_EXT_color_buffer_float");
2496 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2497 textureData, readPixelsData);
2498 }
2499 }
2500}
2501
Geoff Lang6e898aa2017-06-02 11:17:26 -04002502// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2503// accepted by glTexImage2D
2504TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2505{
2506 if (getClientMajorVersion() != 2)
2507 {
2508 std::cout << "Test skipped because it is only valid for WebGL1 contexts." << std::endl;
2509 return;
2510 }
2511
2512 if (!extensionRequestable("GL_OES_texture_float"))
2513 {
2514 std::cout << "Test skipped because GL_OES_texture_float is not requestable." << std::endl;
2515 return;
2516 }
2517 glRequestExtensionANGLE("GL_OES_texture_float");
2518 ASSERT_GL_NO_ERROR();
2519
2520 GLTexture texture;
2521 glBindTexture(GL_TEXTURE_2D, texture);
2522
2523 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2524 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2525
2526 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2527 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2528
2529 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2530 {
2531 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2532 ASSERT_GL_NO_ERROR();
2533
2534 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2535 EXPECT_GL_NO_ERROR();
2536 }
2537
2538 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2539 {
2540 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2541 ASSERT_GL_NO_ERROR();
2542
2543 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2544 EXPECT_GL_NO_ERROR();
2545 }
2546}
2547
Jamie Madill07be8bf2017-02-02 19:59:57 -05002548// This tests that rendering feedback loops works as expected with WebGL 2.
2549// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2550TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2551{
2552 const std::string vertexShader =
2553 "#version 300 es\n"
2554 "in vec4 aPosition;\n"
2555 "out vec2 texCoord;\n"
2556 "void main() {\n"
2557 " gl_Position = aPosition;\n"
2558 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2559 "}\n";
2560
2561 const std::string fragmentShader =
2562 "#version 300 es\n"
2563 "precision mediump float;\n"
2564 "uniform sampler2D tex;\n"
2565 "in vec2 texCoord;\n"
2566 "out vec4 oColor;\n"
2567 "void main() {\n"
2568 " oColor = texture(tex, texCoord);\n"
2569 "}\n";
2570
2571 GLsizei width = 8;
2572 GLsizei height = 8;
2573
2574 GLint maxDrawBuffers = 0;
2575 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2576 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2577 ASSERT_GE(maxDrawBuffers, 2);
2578
2579 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2580 glUseProgram(program.get());
2581 glViewport(0, 0, width, height);
2582
2583 GLTexture tex0;
2584 GLTexture tex1;
2585 GLFramebuffer fbo;
2586 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2587 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2588 ASSERT_GL_NO_ERROR();
2589
2590 glBindTexture(GL_TEXTURE_2D, tex1.get());
2591 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2592 ASSERT_NE(-1, texLoc);
2593 glUniform1i(texLoc, 0);
2594
2595 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2596 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2597 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2598 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2599 ASSERT_GL_NO_ERROR();
2600
2601 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2602 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2603 GL_INVALID_OPERATION);
2604 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2605}
2606
Jamie Madill1d37bc52017-02-02 19:59:58 -05002607// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2608// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2609TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2610{
2611 const std::string vertexShader =
2612 "#version 300 es\n"
2613 "in vec4 aPosition;\n"
2614 "out vec2 texCoord;\n"
2615 "void main() {\n"
2616 " gl_Position = aPosition;\n"
2617 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2618 "}\n";
2619
2620 const std::string fragmentShader =
2621 "#version 300 es\n"
2622 "precision mediump float;\n"
2623 "uniform sampler2D tex;\n"
2624 "in vec2 texCoord;\n"
2625 "out vec4 oColor;\n"
2626 "void main() {\n"
2627 " oColor = texture(tex, texCoord);\n"
2628 "}\n";
2629
2630 GLsizei width = 8;
2631 GLsizei height = 8;
2632
2633 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2634 glUseProgram(program.get());
2635
2636 glViewport(0, 0, width, height);
2637
2638 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2639 glUniform1i(texLoc, 0);
2640
2641 // Create textures and allocate storage
2642 GLTexture tex0;
2643 GLTexture tex1;
2644 GLRenderbuffer rb;
2645 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2646 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2647 GL_UNSIGNED_INT);
2648 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2649 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2650 ASSERT_GL_NO_ERROR();
2651
2652 GLFramebuffer fbo;
2653 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2654 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2655
2656 // Test rendering and sampling feedback loop for depth buffer
2657 glBindTexture(GL_TEXTURE_2D, tex1.get());
2658 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2659 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2660
2661 // The same image is used as depth buffer during rendering.
2662 glEnable(GL_DEPTH_TEST);
2663 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2664 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2665
2666 // The same image is used as depth buffer. But depth mask is false.
2667 glDepthMask(GL_FALSE);
2668 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2669 EXPECT_GL_NO_ERROR();
2670
2671 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2672 glDepthMask(GL_TRUE);
2673 glDisable(GL_DEPTH_TEST);
2674 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2675 EXPECT_GL_NO_ERROR();
2676
2677 // Test rendering and sampling feedback loop for stencil buffer
2678 glBindTexture(GL_RENDERBUFFER, rb.get());
2679 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2680 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2681 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2682 constexpr GLint stencilClearValue = 0x40;
2683 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2684
2685 // The same image is used as stencil buffer during rendering.
2686 glEnable(GL_STENCIL_TEST);
2687 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2688 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2689
2690 // The same image is used as stencil buffer. But stencil mask is zero.
2691 glStencilMask(0x0);
2692 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2693 EXPECT_GL_NO_ERROR();
2694
2695 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2696 glStencilMask(0xffff);
2697 glDisable(GL_STENCIL_TEST);
2698 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2699 EXPECT_GL_NO_ERROR();
2700}
2701
Jamie Madillfd3dd432017-02-02 19:59:59 -05002702// The source and the target for CopyTexSubImage3D are the same 3D texture.
2703// But the level of the 3D texture != the level of the read attachment.
2704TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2705{
2706 GLTexture texture;
2707 GLFramebuffer framebuffer;
2708
2709 glBindTexture(GL_TEXTURE_3D, texture.get());
2710 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2711
2712 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2713 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2714 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2715 ASSERT_GL_NO_ERROR();
2716
2717 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2718 EXPECT_GL_NO_ERROR();
2719}
2720
2721// The source and the target for CopyTexSubImage3D are the same 3D texture.
2722// But the zoffset of the 3D texture != the layer of the read attachment.
2723TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2724{
2725 GLTexture texture;
2726 GLFramebuffer framebuffer;
2727
2728 glBindTexture(GL_TEXTURE_3D, texture.get());
2729 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2730
2731 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2732 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2733 ASSERT_GL_NO_ERROR();
2734
2735 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2736 EXPECT_GL_NO_ERROR();
2737}
2738
2739// The source and the target for CopyTexSubImage3D are the same 3D texture.
2740// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2741TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2742{
2743 GLTexture texture;
2744 GLFramebuffer framebuffer;
2745
2746 glBindTexture(GL_TEXTURE_3D, texture.get());
2747 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2748
2749 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2750 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2751 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2752 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2753 ASSERT_GL_NO_ERROR();
2754
2755 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2756 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2757}
2758
Corentin Wallez59c41592017-07-11 13:19:54 -04002759// Verify that errors are generated when there isn't a defined conversion between the clear type and
2760// the buffer type.
Geoff Lang76e65652017-03-27 14:58:02 -04002761TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2762{
2763 if (IsD3D11())
2764 {
2765 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2766 return;
2767 }
2768
2769 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2770 constexpr int clearInt[] = {0, 0, 0, 0};
2771 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2772
2773 GLTexture texture;
2774 GLFramebuffer framebuffer;
2775
2776 glBindTexture(GL_TEXTURE_2D, texture.get());
2777 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2778
2779 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2780 ASSERT_GL_NO_ERROR();
2781
2782 // Unsigned integer buffer
2783 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2784 ASSERT_GL_NO_ERROR();
2785
2786 glClearBufferfv(GL_COLOR, 0, clearFloat);
2787 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2788
2789 glClearBufferiv(GL_COLOR, 0, clearInt);
2790 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2791
2792 glClearBufferuiv(GL_COLOR, 0, clearUint);
2793 EXPECT_GL_NO_ERROR();
2794
2795 glClear(GL_COLOR_BUFFER_BIT);
2796 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2797
2798 // Integer buffer
2799 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2800 ASSERT_GL_NO_ERROR();
2801
2802 glClearBufferfv(GL_COLOR, 0, clearFloat);
2803 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2804
2805 glClearBufferiv(GL_COLOR, 0, clearInt);
2806 EXPECT_GL_NO_ERROR();
2807
2808 glClearBufferuiv(GL_COLOR, 0, clearUint);
2809 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2810
2811 glClear(GL_COLOR_BUFFER_BIT);
2812 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2813
2814 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002815 if (extensionRequestable("GL_EXT_color_buffer_float"))
2816 {
2817 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2818 }
Geoff Lang76e65652017-03-27 14:58:02 -04002819
Geoff Lang677bb6f2017-04-05 12:40:40 -04002820 if (extensionEnabled("GL_EXT_color_buffer_float"))
2821 {
2822 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2823 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002824
Geoff Lang677bb6f2017-04-05 12:40:40 -04002825 glClearBufferfv(GL_COLOR, 0, clearFloat);
2826 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002827
Geoff Lang677bb6f2017-04-05 12:40:40 -04002828 glClearBufferiv(GL_COLOR, 0, clearInt);
2829 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002830
Geoff Lang677bb6f2017-04-05 12:40:40 -04002831 glClearBufferuiv(GL_COLOR, 0, clearUint);
2832 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2833
2834 glClear(GL_COLOR_BUFFER_BIT);
2835 EXPECT_GL_NO_ERROR();
2836 }
Geoff Lang76e65652017-03-27 14:58:02 -04002837
2838 // Normalized uint buffer
2839 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2840 ASSERT_GL_NO_ERROR();
2841
2842 glClearBufferfv(GL_COLOR, 0, clearFloat);
2843 EXPECT_GL_NO_ERROR();
2844
2845 glClearBufferiv(GL_COLOR, 0, clearInt);
2846 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2847
2848 glClearBufferuiv(GL_COLOR, 0, clearUint);
2849 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2850
2851 glClear(GL_COLOR_BUFFER_BIT);
2852 EXPECT_GL_NO_ERROR();
2853}
2854
Corentin Wallez59c41592017-07-11 13:19:54 -04002855// Test the interaction of WebGL compatibility clears with default framebuffers
2856TEST_P(WebGL2CompatibilityTest, ClearBufferDefaultFramebuffer)
2857{
2858 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2859 constexpr int clearInt[] = {0, 0, 0, 0};
2860 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2861
2862 // glClear works as usual, this is also a regression test for a bug where we
2863 // iterated on maxDrawBuffers for default framebuffers, triggering an assert
2864 glClear(GL_COLOR_BUFFER_BIT);
2865 EXPECT_GL_NO_ERROR();
2866
2867 // Default framebuffers are normalized uints, so only glClearBufferfv works.
2868 glClearBufferfv(GL_COLOR, 0, clearFloat);
2869 EXPECT_GL_NO_ERROR();
2870
2871 glClearBufferiv(GL_COLOR, 0, clearInt);
2872 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2873
2874 glClearBufferuiv(GL_COLOR, 0, clearUint);
2875 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2876}
2877
Geoff Lange4915782017-04-12 15:19:07 -04002878// Verify that errors are generate when trying to blit from an image to itself
2879TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2880{
2881 GLTexture textures[2];
2882 glBindTexture(GL_TEXTURE_2D, textures[0]);
2883 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2884 glBindTexture(GL_TEXTURE_2D, textures[1]);
2885 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2886
2887 GLRenderbuffer renderbuffers[2];
2888 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2889 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2890 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2891 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2892
2893 GLFramebuffer framebuffers[2];
2894 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2895 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2896
2897 ASSERT_GL_NO_ERROR();
2898
2899 // Same texture
2900 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2901 0);
2902 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2903 0);
2904 ASSERT_GL_NO_ERROR();
2905 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2906 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2907
2908 // Same textures but different renderbuffers
2909 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2910 renderbuffers[0]);
2911 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2912 renderbuffers[1]);
2913 ASSERT_GL_NO_ERROR();
2914 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2915 ASSERT_GL_NO_ERROR();
2916 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2917 GL_NEAREST);
2918 ASSERT_GL_NO_ERROR();
2919 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2920 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2921 GL_NEAREST);
2922 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2923
2924 // Same renderbuffers but different textures
2925 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2926 0);
2927 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2928 0);
2929 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2930 renderbuffers[0]);
2931 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2932 renderbuffers[0]);
2933 ASSERT_GL_NO_ERROR();
2934 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2935 ASSERT_GL_NO_ERROR();
2936 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2937 GL_NEAREST);
2938 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2939 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2940 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2941 GL_NEAREST);
2942 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2943}
2944
Geoff Lange0cff192017-05-30 13:04:56 -04002945// Verify that errors are generated when the fragment shader output doesn't match the bound color
2946// buffer types
2947TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
2948{
2949 const std::string vertexShader =
2950 "#version 300 es\n"
2951 "void main() {\n"
2952 " gl_Position = vec4(0, 0, 0, 1);\n"
2953 "}\n";
2954
2955 const std::string fragmentShader =
2956 "#version 300 es\n"
2957 "precision mediump float;\n"
2958 "layout(location = 0) out vec4 floatOutput;\n"
2959 "layout(location = 1) out uvec4 uintOutput;\n"
2960 "layout(location = 2) out ivec4 intOutput;\n"
2961 "void main() {\n"
2962 " floatOutput = vec4(0, 0, 0, 1);\n"
2963 " uintOutput = uvec4(0, 0, 0, 1);\n"
2964 " intOutput = ivec4(0, 0, 0, 1);\n"
2965 "}\n";
2966
2967 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2968 glUseProgram(program.get());
2969
2970 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
2971 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
2972 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
2973
2974 GLFramebuffer fbo;
2975 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2976
2977 GLRenderbuffer floatRenderbuffer;
2978 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
2979 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2980 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2981 floatRenderbuffer);
2982
2983 GLRenderbuffer uintRenderbuffer;
2984 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
2985 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
2986 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2987 uintRenderbuffer);
2988
2989 GLRenderbuffer intRenderbuffer;
2990 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
2991 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
2992 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2993 intRenderbuffer);
2994
2995 ASSERT_GL_NO_ERROR();
2996
2997 GLint maxDrawBuffers = 0;
2998 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2999 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
3000 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
3001 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
3002 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
3003
3004 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
3005
3006 // Check that the correct case generates no errors
3007 glDrawArrays(GL_TRIANGLES, 0, 6);
3008 EXPECT_GL_NO_ERROR();
3009
3010 // Unbind some buffers and verify that there are still no errors
3011 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3012 0);
3013 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3014 0);
3015 glDrawArrays(GL_TRIANGLES, 0, 6);
3016 EXPECT_GL_NO_ERROR();
3017
3018 // Swap the int and uint buffers to and verify that an error is generated
3019 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3020 intRenderbuffer);
3021 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3022 uintRenderbuffer);
3023 glDrawArrays(GL_TRIANGLES, 0, 6);
3024 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3025
3026 // Swap the float and uint buffers to and verify that an error is generated
3027 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
3028 floatRenderbuffer);
3029 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
3030 uintRenderbuffer);
3031 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
3032 intRenderbuffer);
3033 glDrawArrays(GL_TRIANGLES, 0, 6);
3034 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3035}
3036
Geoff Lang9ab5b822017-05-30 16:19:23 -04003037// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
3038// types
3039TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMissmatch)
3040{
3041 const std::string vertexShader =
3042 "#version 300 es\n"
3043 "in vec4 floatInput;\n"
3044 "in uvec4 uintInput;\n"
3045 "in ivec4 intInput;\n"
3046 "void main() {\n"
3047 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
3048 "}\n";
3049
3050 const std::string fragmentShader =
3051 "#version 300 es\n"
3052 "precision mediump float;\n"
3053 "out vec4 outputColor;\n"
3054 "void main() {\n"
3055 " outputColor = vec4(0, 0, 0, 1);"
3056 "}\n";
3057
3058 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3059 glUseProgram(program.get());
3060
3061 GLint floatLocation = glGetAttribLocation(program, "floatInput");
3062 GLint uintLocation = glGetAttribLocation(program, "uintInput");
3063 GLint intLocation = glGetAttribLocation(program, "intInput");
3064
3065 // Default attributes are of float types
3066 glDrawArrays(GL_TRIANGLES, 0, 6);
3067 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3068
3069 // Set the default attributes to the correct types, should succeed
3070 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
3071 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
3072 glDrawArrays(GL_TRIANGLES, 0, 6);
3073 EXPECT_GL_NO_ERROR();
3074
3075 // Change the default float attribute to an integer, should fail
3076 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
3077 glDrawArrays(GL_TRIANGLES, 0, 6);
3078 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3079
3080 // Use a buffer for some attributes
3081 GLBuffer buffer;
3082 glBindBuffer(GL_ARRAY_BUFFER, buffer);
3083 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
3084 glEnableVertexAttribArray(floatLocation);
3085 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3086 glDrawArrays(GL_TRIANGLES, 0, 6);
3087 EXPECT_GL_NO_ERROR();
3088
3089 // Use a float pointer attrib for a uint input
3090 glEnableVertexAttribArray(uintLocation);
3091 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
3092 glDrawArrays(GL_TRIANGLES, 0, 6);
3093 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3094
3095 // Use a uint pointer for the uint input
3096 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
3097 glDrawArrays(GL_TRIANGLES, 0, 6);
3098 EXPECT_GL_NO_ERROR();
3099}
3100
Corentin Walleze7557742017-06-01 13:09:57 -04003101// Tests the WebGL removal of undefined behavior when attachments aren't written to.
3102TEST_P(WebGLCompatibilityTest, DrawBuffers)
3103{
Corentin Walleze7557742017-06-01 13:09:57 -04003104 // Make sure we can use at least 4 attachments for the tests.
3105 bool useEXT = false;
3106 if (getClientMajorVersion() < 3)
3107 {
3108 if (!extensionRequestable("GL_EXT_draw_buffers"))
3109 {
3110 std::cout << "Test skipped because draw buffers are not available" << std::endl;
3111 return;
3112 }
3113
3114 glRequestExtensionANGLE("GL_EXT_draw_buffers");
3115 useEXT = true;
3116 EXPECT_GL_NO_ERROR();
3117 }
3118
3119 GLint maxDrawBuffers = 0;
3120 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
3121 if (maxDrawBuffers < 4)
3122 {
3123 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
3124 return;
3125 }
3126
3127 // Clears all the renderbuffers to red.
3128 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
3129 GLFramebuffer clearFBO;
3130 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
3131
3132 glClearColor(1, 0, 0, 1);
3133 for (int i = 0; i < 4; ++i)
3134 {
3135 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3136 renderbuffers[i]);
3137 glClear(GL_COLOR_BUFFER_BIT);
3138 }
3139 ASSERT_GL_NO_ERROR();
3140 };
3141
3142 // Checks that the renderbuffers specified by mask have the correct color
3143 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
3144 GLFramebuffer readFBO;
3145 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
3146
3147 for (int i = 0; i < 4; ++i)
3148 {
3149 if (mask & (1 << i))
3150 {
3151 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
3152 GL_RENDERBUFFER, renderbuffers[i]);
3153 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
3154 }
3155 }
3156 ASSERT_GL_NO_ERROR();
3157 };
3158
3159 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
3160 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
3161 if (useEXT)
3162 {
3163 glDrawBuffersEXT(numBuffers, buffers);
3164 }
3165 else
3166 {
3167 glDrawBuffers(numBuffers, buffers);
3168 }
3169 };
3170
3171 // Initialized the test framebuffer
3172 GLFramebuffer drawFBO;
3173 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3174
3175 GLRenderbuffer renderbuffers[4];
3176 for (int i = 0; i < 4; ++i)
3177 {
3178 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
3179 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
3180 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
3181 renderbuffers[i]);
3182 }
3183
3184 ASSERT_GL_NO_ERROR();
3185
3186 const char *vertESSL1 =
3187 "attribute vec4 a_pos;\n"
3188 "void main()\n"
3189 "{\n"
3190 " gl_Position = a_pos;\n"
3191 "}\n";
3192 const char *vertESSL3 =
3193 "#version 300 es\n"
3194 "in vec4 a_pos;\n"
3195 "void main()\n"
3196 "{\n"
3197 " gl_Position = a_pos;\n"
3198 "}\n";
3199
3200 GLenum allDrawBuffers[] = {
3201 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3202 };
3203
3204 GLenum halfDrawBuffers[] = {
3205 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
3206 };
3207
3208 // Test that when using gl_FragColor, only the first attachment is written to.
3209 const char *fragESSL1 =
3210 "precision highp float;\n"
3211 "void main()\n"
3212 "{\n"
3213 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
3214 "}\n";
3215 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
3216
3217 {
3218 ClearEverythingToRed(renderbuffers);
3219
3220 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3221 DrawBuffers(useEXT, 4, allDrawBuffers);
3222 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
3223 ASSERT_GL_NO_ERROR();
3224
3225 CheckColors(renderbuffers, 0b0001, GLColor::green);
3226 CheckColors(renderbuffers, 0b1110, GLColor::red);
3227 }
3228
3229 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
3230 // written to.
3231 {
3232 ClearEverythingToRed(renderbuffers);
3233
3234 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3235 DrawBuffers(useEXT, 4, halfDrawBuffers);
3236 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
3237 ASSERT_GL_NO_ERROR();
3238
3239 CheckColors(renderbuffers, 0b1111, GLColor::red);
3240 }
3241
3242 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
3243 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
3244 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
3245 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
3246 // attachments not declared in the shader should not be written to.
3247 const char *writeOddOutputsVert;
3248 const char *writeOddOutputsFrag;
3249 GLColor unwrittenColor;
3250 if (useEXT)
3251 {
3252 // In the extension, when an attachment isn't written to, it should get 0's
3253 unwrittenColor = GLColor(0, 0, 0, 0);
3254 writeOddOutputsVert = vertESSL1;
3255 writeOddOutputsFrag =
3256 "#extension GL_EXT_draw_buffers : require\n"
3257 "precision highp float;\n"
3258 "void main()\n"
3259 "{\n"
3260 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3261 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
3262 "}\n";
3263 }
3264 else
3265 {
3266 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
3267 // because of the preceding clears.
3268 unwrittenColor = GLColor::red;
3269 writeOddOutputsVert = vertESSL3;
3270 writeOddOutputsFrag =
3271 "#version 300 es\n"
3272 "precision highp float;\n"
3273 "layout(location = 1) out vec4 output1;"
3274 "layout(location = 3) out vec4 output2;"
3275 "void main()\n"
3276 "{\n"
3277 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3278 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
3279 "}\n";
3280 }
3281 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
3282
3283 // Test that attachments not written to get the "unwritten" color
3284 {
3285 ClearEverythingToRed(renderbuffers);
3286
3287 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3288 DrawBuffers(useEXT, 4, allDrawBuffers);
3289 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
3290 ASSERT_GL_NO_ERROR();
3291
3292 CheckColors(renderbuffers, 0b1010, GLColor::green);
3293 CheckColors(renderbuffers, 0b0101, unwrittenColor);
3294 }
3295
3296 // Test that attachments not written to get the "unwritten" color but that even when the
3297 // extension is used, disabled attachments are not written at all and stay red.
3298 {
3299 ClearEverythingToRed(renderbuffers);
3300
3301 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
3302 DrawBuffers(useEXT, 4, halfDrawBuffers);
3303 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
3304 ASSERT_GL_NO_ERROR();
3305
3306 CheckColors(renderbuffers, 0b1000, GLColor::green);
3307 CheckColors(renderbuffers, 0b0100, unwrittenColor);
3308 CheckColors(renderbuffers, 0b0011, GLColor::red);
3309 }
3310}
3311
Geoff Lang536eca12017-09-13 11:23:35 -04003312// Test that it's possible to generate mipmaps on unsized floating point textures once the
3313// extensions have been enabled
3314TEST_P(WebGLCompatibilityTest, GenerateMipmapUnsizedFloatingPointTexture)
3315{
3316 if (extensionRequestable("GL_OES_texture_float"))
3317 {
3318 glRequestExtensionANGLE("GL_OES_texture_float");
3319 }
3320 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3321
3322 GLTexture texture;
3323 glBindTexture(GL_TEXTURE_2D, texture);
3324
3325 constexpr GLColor32F data[4] = {
3326 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3327 };
3328 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_FLOAT, data);
3329 ASSERT_GL_NO_ERROR();
3330
3331 glGenerateMipmap(GL_TEXTURE_2D);
3332 EXPECT_GL_NO_ERROR();
3333}
3334// Test that it's possible to generate mipmaps on unsized floating point textures once the
3335// extensions have been enabled
3336TEST_P(WebGLCompatibilityTest, GenerateMipmapSizedFloatingPointTexture)
3337{
3338 if (extensionRequestable("GL_OES_texture_float"))
3339 {
3340 glRequestExtensionANGLE("GL_OES_texture_float");
3341 }
3342 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_OES_texture_float"));
3343
3344 if (extensionRequestable("GL_EXT_texture_storage"))
3345 {
3346 glRequestExtensionANGLE("GL_EXT_texture_storage");
3347 }
3348 ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_EXT_texture_storage"));
3349
3350 GLTexture texture;
3351 glBindTexture(GL_TEXTURE_2D, texture);
3352
3353 constexpr GLColor32F data[4] = {
3354 kFloatRed, kFloatRed, kFloatGreen, kFloatBlue,
3355 };
3356 glTexStorage2DEXT(GL_TEXTURE_2D, 2, GL_RGBA32F, 2, 2);
3357 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_FLOAT, data);
3358 ASSERT_GL_NO_ERROR();
3359
3360 glGenerateMipmap(GL_TEXTURE_2D);
3361 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3362
3363 if (extensionRequestable("GL_EXT_color_buffer_float"))
3364 {
3365 // Format is renderable but not filterable
3366 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
3367 glGenerateMipmap(GL_TEXTURE_2D);
3368 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3369 }
3370
3371 if (extensionRequestable("GL_EXT_color_buffer_float_linear"))
3372 {
3373 // Format is renderable but not filterable
3374 glRequestExtensionANGLE("GL_EXT_color_buffer_float_linear");
3375
3376 if (extensionEnabled("GL_EXT_color_buffer_float"))
3377 {
3378 // Format is filterable and renderable
3379 glGenerateMipmap(GL_TEXTURE_2D);
3380 EXPECT_GL_NO_ERROR();
3381 }
3382 else
3383 {
3384 // Format is filterable but not renderable
3385 glGenerateMipmap(GL_TEXTURE_2D);
3386 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
3387 }
3388 }
3389}
3390
Frank Henigmanfccbac22017-05-28 17:29:26 -04003391// Linking should fail when corresponding vertex/fragment uniform blocks have different precision
3392// qualifiers.
3393TEST_P(WebGL2CompatibilityTest, UniformBlockPrecisionMismatch)
3394{
3395 const std::string vertexShader =
3396 "#version 300 es\n"
3397 "uniform Block { mediump vec4 val; };\n"
3398 "void main() { gl_Position = val; }\n";
3399 const std::string fragmentShader =
3400 "#version 300 es\n"
3401 "uniform Block { highp vec4 val; };\n"
3402 "out highp vec4 out_FragColor;\n"
3403 "void main() { out_FragColor = val; }\n";
3404
3405 GLuint vs = CompileShader(GL_VERTEX_SHADER, vertexShader);
3406 ASSERT_NE(0u, vs);
3407 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fragmentShader);
3408 ASSERT_NE(0u, fs);
3409
3410 GLuint program = glCreateProgram();
3411
3412 glAttachShader(program, vs);
3413 glDeleteShader(vs);
3414 glAttachShader(program, fs);
3415 glDeleteShader(fs);
3416
3417 glLinkProgram(program);
3418 GLint linkStatus;
3419 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
3420 ASSERT_EQ(0, linkStatus);
3421
3422 glDeleteProgram(program);
3423}
3424
Geoff Lang69df2422017-07-05 12:42:31 -04003425// Test no attribute vertex shaders
3426TEST_P(WebGL2CompatibilityTest, NoAttributeVertexShader)
3427{
3428 const std::string vertexShader =
3429 "#version 300 es\n"
3430 "void main()\n"
3431 "{\n"
3432 "\n"
3433 " ivec2 xy = ivec2(gl_VertexID % 2, (gl_VertexID / 2 + gl_VertexID / 3) % 2);\n"
3434 " gl_Position = vec4(vec2(xy) * 2. - 1., 0, 1);\n"
3435 "}";
3436 const std::string fragmentShader =
3437 "#version 300 es\n"
3438 "precision mediump float;\n"
3439 "out vec4 result;\n"
3440 "void main()\n"
3441 "{\n"
3442 " result = vec4(0, 1, 0, 1);\n"
3443 "}";
3444
3445 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
3446 glUseProgram(program);
3447
3448 glDrawArrays(GL_TRIANGLES, 0, 6);
3449 ASSERT_GL_NO_ERROR();
3450 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
3451}
3452
Brandon Jonesed5b46f2017-07-21 08:39:17 -07003453// Tests bindAttribLocations for length limit
3454TEST_P(WebGL2CompatibilityTest, BindAttribLocationLimitation)
3455{
3456 constexpr int maxLocStringLength = 1024;
3457 const std::string tooLongString(maxLocStringLength + 1, '_');
3458
3459 glBindAttribLocation(0, 0, static_cast<const GLchar *>(tooLongString.c_str()));
3460
3461 EXPECT_GL_ERROR(GL_INVALID_VALUE);
3462}
3463
Geoff Langc287ea62016-09-16 14:46:51 -04003464// Use this to select which configurations (e.g. which renderer, which GLES major version) these
3465// tests should be run against.
3466ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
3467 ES2_D3D9(),
3468 ES2_D3D11(),
3469 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04003470 ES2_OPENGL(),
3471 ES3_OPENGL(),
3472 ES2_OPENGLES(),
3473 ES3_OPENGLES());
3474
Jamie Madill07be8bf2017-02-02 19:59:57 -05003475ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04003476} // namespace