blob: 8b8208a4f750cafc25011f17f874cfb3e699f476 [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",
40 "GL_OES_texture_float",
41 "GL_OES_texture_float_linear",
42 "GL_OES_texture_half_float",
43 "GL_OES_texture_half_float_linear",
44 "GL_EXT_color_buffer_half_float",
45 "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
297 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
298 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
306 glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr);
307 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 Langa0e0aeb2017-04-12 15:06:29 -0400450// Verify that the context generates the correct error when the framebuffer attachments are
451// different sizes
452TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMissmatch)
453{
454 GLFramebuffer fbo;
455 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
456
457 GLTexture textures[2];
458 glBindTexture(GL_TEXTURE_2D, textures[0]);
459 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
460 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
461
462 ASSERT_GL_NO_ERROR();
463 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
464
465 GLRenderbuffer renderbuffer;
466 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
467 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3);
468 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
469
470 ASSERT_GL_NO_ERROR();
471 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
472 glCheckFramebufferStatus(GL_FRAMEBUFFER));
473
474 if (extensionRequestable("GL_EXT_draw_buffers"))
475 {
476 glRequestExtensionANGLE("GL_EXT_draw_buffers");
477 EXPECT_GL_NO_ERROR();
478 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
479
480 glBindTexture(GL_TEXTURE_2D, textures[1]);
481 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
482 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0);
483 ASSERT_GL_NO_ERROR();
484
485 ASSERT_GL_NO_ERROR();
486 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
487 glCheckFramebufferStatus(GL_FRAMEBUFFER));
488
489 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
490
491 ASSERT_GL_NO_ERROR();
492 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
493
494 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
495
496 ASSERT_GL_NO_ERROR();
497 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS,
498 glCheckFramebufferStatus(GL_FRAMEBUFFER));
499 }
500}
501
Corentin Wallez327411e2016-12-09 11:09:17 -0500502// Test that client-side array buffers are forbidden in WebGL mode
503TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer)
504{
505 const std::string &vert =
506 "attribute vec3 a_pos;\n"
507 "void main()\n"
508 "{\n"
509 " gl_Position = vec4(a_pos, 1.0);\n"
510 "}\n";
511
512 const std::string &frag =
513 "precision highp float;\n"
514 "void main()\n"
515 "{\n"
516 " gl_FragColor = vec4(1.0);\n"
517 "}\n";
518
519 ANGLE_GL_PROGRAM(program, vert, frag);
520
521 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
522 ASSERT_NE(-1, posLocation);
523 glUseProgram(program.get());
524
525 const auto &vertices = GetQuadVertices();
Corentin Wallezfd456442016-12-21 17:57:00 -0500526 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data());
Corentin Wallez327411e2016-12-09 11:09:17 -0500527 glEnableVertexAttribArray(posLocation);
528
529 ASSERT_GL_NO_ERROR();
530 glDrawArrays(GL_TRIANGLES, 0, 6);
531 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
532}
533
534// Test that client-side element array buffers are forbidden in WebGL mode
535TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer)
536{
537 const std::string &vert =
538 "attribute vec3 a_pos;\n"
539 "void main()\n"
540 "{\n"
541 " gl_Position = vec4(a_pos, 1.0);\n"
542 "}\n";
543
544 const std::string &frag =
545 "precision highp float;\n"
546 "void main()\n"
547 "{\n"
548 " gl_FragColor = vec4(1.0);\n"
549 "}\n";
550
551 ANGLE_GL_PROGRAM(program, vert, frag);
552
553 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
554 ASSERT_NE(-1, posLocation);
555 glUseProgram(program.get());
556
557 const auto &vertices = GetQuadVertices();
558
559 GLBuffer vertexBuffer;
560 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
561 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
562 GL_STATIC_DRAW);
563
564 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
565 glEnableVertexAttribArray(posLocation);
566
Corentin Wallez327411e2016-12-09 11:09:17 -0500567 ASSERT_GL_NO_ERROR();
Corentin Wallezded1b5a2017-03-09 18:58:48 -0500568
569 // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also
570 // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate
571 // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check.
572 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1)));
Corentin Wallez327411e2016-12-09 11:09:17 -0500573 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
574}
575
Corentin Wallezb1d0a2552016-12-19 16:15:54 -0500576// Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back
577TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef)
578{
579 // Run the test in an FBO to make sure we have some stencil bits.
580 GLRenderbuffer renderbuffer;
581 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get());
582 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32);
583
584 GLFramebuffer framebuffer;
585 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
586 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
587 renderbuffer.get());
588
589 ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }",
590 "void main() { gl_FragColor = vec4(0, 1, 0, 1); }")
591 glUseProgram(program.get());
592 ASSERT_GL_NO_ERROR();
593
594 // Having ref and mask the same for front and back is valid.
595 glStencilMask(255);
596 glStencilFunc(GL_ALWAYS, 0, 255);
597 glDrawArrays(GL_TRIANGLES, 0, 6);
598 ASSERT_GL_NO_ERROR();
599
600 // Having a different front - back write mask generates an error.
601 glStencilMaskSeparate(GL_FRONT, 1);
602 glDrawArrays(GL_TRIANGLES, 0, 6);
603 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
604
605 // Setting both write masks separately to the same value is valid.
606 glStencilMaskSeparate(GL_BACK, 1);
607 glDrawArrays(GL_TRIANGLES, 0, 6);
608 ASSERT_GL_NO_ERROR();
609
610 // Having a different stencil front - back mask generates an error
611 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1);
612 glDrawArrays(GL_TRIANGLES, 0, 6);
613 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
614
615 // Setting both masks separately to the same value is valid.
616 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1);
617 glDrawArrays(GL_TRIANGLES, 0, 6);
618 ASSERT_GL_NO_ERROR();
619
620 // Having a different stencil front - back reference generates an error
621 glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1);
622 glDrawArrays(GL_TRIANGLES, 0, 6);
623 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
624
625 // Setting both references separately to the same value is valid.
626 glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1);
627 glDrawArrays(GL_TRIANGLES, 0, 6);
628 ASSERT_GL_NO_ERROR();
629
630 // Using different stencil funcs, everything being equal is valid.
631 glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1);
632 glDrawArrays(GL_TRIANGLES, 0, 6);
633 ASSERT_GL_NO_ERROR();
634}
635
Corentin Wallez506fc9c2016-12-21 16:53:33 -0500636// Test that GL_FIXED is forbidden
637TEST_P(WebGLCompatibilityTest, ForbidsGLFixed)
638{
639 GLBuffer buffer;
640 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
641 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
642
643 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr);
644 ASSERT_GL_NO_ERROR();
645
646 glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr);
647 EXPECT_GL_ERROR(GL_INVALID_ENUM);
648}
649
650// Test the WebGL limit of 255 for the attribute stride
651TEST_P(WebGLCompatibilityTest, MaxStride)
652{
653 GLBuffer buffer;
654 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
655 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
656
657 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr);
658 ASSERT_GL_NO_ERROR();
659
660 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr);
661 EXPECT_GL_ERROR(GL_INVALID_VALUE);
662}
663
Corentin Wallezfd456442016-12-21 17:57:00 -0500664// Test the checks for OOB reads in the vertex buffers, non-instanced version
665TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced)
666{
667 const std::string &vert =
668 "attribute float a_pos;\n"
669 "void main()\n"
670 "{\n"
671 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
672 "}\n";
673
674 const std::string &frag =
675 "precision highp float;\n"
676 "void main()\n"
677 "{\n"
678 " gl_FragColor = vec4(1.0);\n"
679 "}\n";
680
681 ANGLE_GL_PROGRAM(program, vert, frag);
682
683 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
684 ASSERT_NE(-1, posLocation);
685 glUseProgram(program.get());
686
687 GLBuffer buffer;
688 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
689 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
690
691 glEnableVertexAttribArray(posLocation);
692
693 const uint8_t* zeroOffset = nullptr;
694
695 // Test touching the last element is valid.
696 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
697 glDrawArrays(GL_POINTS, 0, 4);
698 ASSERT_GL_NO_ERROR();
699
700 // Test touching the last element + 1 is invalid.
701 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
702 glDrawArrays(GL_POINTS, 0, 4);
703 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
704
705 // Test touching the last element is valid, using a stride.
706 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
707 glDrawArrays(GL_POINTS, 0, 4);
708 ASSERT_GL_NO_ERROR();
709
710 // Test touching the last element + 1 is invalid, using a stride.
711 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
712 glDrawArrays(GL_POINTS, 0, 4);
713 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
714
715 // Test any offset is valid if no vertices are drawn.
716 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
717 glDrawArrays(GL_POINTS, 0, 0);
718 ASSERT_GL_NO_ERROR();
719}
720
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500721// Test the checks for OOB reads in the index buffer
722TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer)
Geoff Lang5f319a42017-01-09 16:49:19 -0500723{
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500724 const std::string &vert =
725 "attribute float a_pos;\n"
726 "void main()\n"
727 "{\n"
728 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
729 "}\n";
Geoff Lang5f319a42017-01-09 16:49:19 -0500730
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500731 const std::string &frag =
732 "precision highp float;\n"
733 "void main()\n"
734 "{\n"
735 " gl_FragColor = vec4(1.0);\n"
736 "}\n";
737
738 ANGLE_GL_PROGRAM(program, vert, frag);
739
740 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
741 ASSERT_NE(-1, posLocation);
742 glUseProgram(program.get());
743
744 GLBuffer vertexBuffer;
745 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
746 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
747
748 glEnableVertexAttribArray(posLocation);
749
750 const uint8_t *zeroOffset = nullptr;
751 const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0};
752
753 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset);
754
755 GLBuffer indexBuffer;
756 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
757 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW);
Geoff Lang5f319a42017-01-09 16:49:19 -0500758 ASSERT_GL_NO_ERROR();
759
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500760 // Test touching the last index is valid
761 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
762 ASSERT_GL_NO_ERROR();
Geoff Lang5f319a42017-01-09 16:49:19 -0500763
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500764 // Test touching the last + 1 element is invalid
765 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5);
766 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang5f319a42017-01-09 16:49:19 -0500767
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500768 // Test any offset if valid if count is zero
769 glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42);
770 ASSERT_GL_NO_ERROR();
Corentin Wallezfe9306a2017-02-01 17:41:05 -0500771
772 // Test touching the first index is valid
773 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4);
774 ASSERT_GL_NO_ERROR();
775
776 // Test touching the first - 1 index is invalid
777 // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was
778 // the historic behavior of WebGL implementations
779 glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1);
780 EXPECT_GL_ERROR(GL_INVALID_VALUE);
Geoff Lang5f319a42017-01-09 16:49:19 -0500781}
782
Frank Henigman6137ddc2017-02-10 18:55:07 -0500783// Test depth range with 'near' more or less than 'far.'
784TEST_P(WebGLCompatibilityTest, DepthRange)
785{
786 glDepthRangef(0, 1);
787 ASSERT_GL_NO_ERROR();
788
789 glDepthRangef(.5, .5);
790 ASSERT_GL_NO_ERROR();
791
792 glDepthRangef(1, 0);
793 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
794}
795
Frank Henigman146e8a12017-03-02 23:22:37 -0500796// Test all blend function combinations.
797// In WebGL it is invalid to combine constant color with constant alpha.
798TEST_P(WebGLCompatibilityTest, BlendWithConstantColor)
799{
800 constexpr GLenum srcFunc[] = {
801 GL_ZERO,
802 GL_ONE,
803 GL_SRC_COLOR,
804 GL_ONE_MINUS_SRC_COLOR,
805 GL_DST_COLOR,
806 GL_ONE_MINUS_DST_COLOR,
807 GL_SRC_ALPHA,
808 GL_ONE_MINUS_SRC_ALPHA,
809 GL_DST_ALPHA,
810 GL_ONE_MINUS_DST_ALPHA,
811 GL_CONSTANT_COLOR,
812 GL_ONE_MINUS_CONSTANT_COLOR,
813 GL_CONSTANT_ALPHA,
814 GL_ONE_MINUS_CONSTANT_ALPHA,
815 GL_SRC_ALPHA_SATURATE,
816 };
817
818 constexpr GLenum dstFunc[] = {
819 GL_ZERO, GL_ONE,
820 GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
821 GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR,
822 GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
823 GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
824 GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
825 GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA,
826 };
827
828 for (GLenum src : srcFunc)
829 {
830 for (GLenum dst : dstFunc)
831 {
832 glBlendFunc(src, dst);
833 CheckBlendFunctions(src, dst);
834 glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE);
835 CheckBlendFunctions(src, dst);
836 }
837 }
838}
839
Geoff Langfc32e8b2017-05-31 14:16:59 -0400840// Test that binding/querying uniforms and attributes with invalid names generates errors
841TEST_P(WebGLCompatibilityTest, InvalidAttributeAndUniformNames)
842{
843 const std::string validAttribName =
844 "abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
845 const std::string validUniformName =
846 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890";
847 const char invalidSet[] = {'"', '$', '`', '@', '\\', '\''};
848
849 std::string vert = "attribute float ";
850 vert += validAttribName;
851 vert +=
852 ";\n"
853 "void main()\n"
854 "{\n"
855 " gl_Position = vec4(1.0);\n"
856 "}\n";
857
858 std::string frag =
859 "precision highp float;\n"
860 "uniform vec4 ";
861 frag += validUniformName;
862 frag +=
863 ";\n"
864 "void main()\n"
865 "{\n"
866 " gl_FragColor = vec4(1.0);\n"
867 "}\n";
868
869 ANGLE_GL_PROGRAM(program, vert, frag);
870 EXPECT_GL_NO_ERROR();
871
872 for (char invalidChar : invalidSet)
873 {
874 std::string invalidName = validAttribName + invalidChar;
875 glGetAttribLocation(program, invalidName.c_str());
876 EXPECT_GL_ERROR(GL_INVALID_VALUE)
877 << "glGetAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
878
879 glBindAttribLocation(program, 0, invalidName.c_str());
880 EXPECT_GL_ERROR(GL_INVALID_VALUE)
881 << "glBindAttribLocation unexpectedly succeeded for name \"" << invalidName << "\".";
882 }
883
884 for (char invalidChar : invalidSet)
885 {
886 std::string invalidName = validUniformName + invalidChar;
887 glGetUniformLocation(program, invalidName.c_str());
888 EXPECT_GL_ERROR(GL_INVALID_VALUE)
889 << "glGetUniformLocation unexpectedly succeeded for name \"" << invalidName << "\".";
890 }
891
892 for (char invalidChar : invalidSet)
893 {
894 std::string invalidAttribName = validAttribName + invalidChar;
895 const char *invalidVert[] = {
896 "attribute float ",
897 invalidAttribName.c_str(),
898 ";\n",
899 "void main()\n",
900 "{\n",
901 " gl_Position = vec4(1.0);\n",
902 "}\n",
903 };
904
905 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
906 glShaderSource(shader, static_cast<GLsizei>(ArraySize(invalidVert)), invalidVert, nullptr);
907 EXPECT_GL_ERROR(GL_INVALID_VALUE);
908 glDeleteShader(shader);
909 }
910}
911
Corentin Wallezfd456442016-12-21 17:57:00 -0500912// Test the checks for OOB reads in the vertex buffers, instanced version
913TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
914{
915 const std::string &vert =
916 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400917 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500918 "void main()\n"
919 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400920 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500921 "}\n";
922
923 const std::string &frag =
924 "precision highp float;\n"
925 "void main()\n"
926 "{\n"
927 " gl_FragColor = vec4(1.0);\n"
928 "}\n";
929
930 ANGLE_GL_PROGRAM(program, vert, frag);
931
932 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
933 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -0400934
935 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
936 ASSERT_NE(-1, wLocation);
937
Corentin Wallezfd456442016-12-21 17:57:00 -0500938 glUseProgram(program.get());
939
940 GLBuffer buffer;
941 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
942 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
943
944 glEnableVertexAttribArray(posLocation);
945 glVertexAttribDivisor(posLocation, 1);
946
Geoff Lang407d4e72017-04-12 14:54:11 -0400947 glEnableVertexAttribArray(wLocation);
948 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
949 glVertexAttribDivisor(wLocation, 0);
950
Corentin Wallezfd456442016-12-21 17:57:00 -0500951 const uint8_t* zeroOffset = nullptr;
952
953 // Test touching the last element is valid.
954 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
955 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
956 ASSERT_GL_NO_ERROR();
957
958 // Test touching the last element + 1 is invalid.
959 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
960 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
961 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
962
963 // Test touching the last element is valid, using a stride.
964 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
965 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
966 ASSERT_GL_NO_ERROR();
967
968 // Test touching the last element + 1 is invalid, using a stride.
969 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
970 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
971 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
972
973 // Test any offset is valid if no vertices are drawn.
974 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
975 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
976 ASSERT_GL_NO_ERROR();
977}
978
Geoff Lang407d4e72017-04-12 14:54:11 -0400979// Test that at least one attribute has a zero divisor for WebGL
980TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
981{
982 const std::string &vert =
983 "attribute float a_pos;\n"
984 "void main()\n"
985 "{\n"
986 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
987 "}\n";
988
989 const std::string &frag =
990 "precision highp float;\n"
991 "void main()\n"
992 "{\n"
993 " gl_FragColor = vec4(1.0);\n"
994 "}\n";
995
996 ANGLE_GL_PROGRAM(program, vert, frag);
997
998 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
999 ASSERT_NE(-1, posLocation);
1000
1001 glUseProgram(program.get());
1002
1003 GLBuffer buffer;
1004 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
1005 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
1006
1007 glEnableVertexAttribArray(posLocation);
1008 glVertexAttribDivisor(posLocation, 1);
1009
1010 // Test touching the last element is valid.
1011 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
1012 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
1013 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1014
1015 glVertexAttribDivisor(posLocation, 0);
1016 ASSERT_GL_NO_ERROR();
1017}
1018
Corentin Wallez0844f2d2017-01-31 17:02:59 -05001019// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
1020TEST_P(WebGLCompatibilityTest, NPOT)
1021{
1022 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
1023
1024 // Create a texture and set an NPOT mip 0, should always be acceptable.
1025 GLTexture texture;
1026 glBindTexture(GL_TEXTURE_2D, texture.get());
1027 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1028 ASSERT_GL_NO_ERROR();
1029
1030 // Try setting an NPOT mip 1 and verify the error if WebGL 1
1031 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1032 if (getClientMajorVersion() < 3)
1033 {
1034 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1035 }
1036 else
1037 {
1038 ASSERT_GL_NO_ERROR();
1039 }
1040
1041 if (extensionRequestable("GL_OES_texture_npot"))
1042 {
1043 glRequestExtensionANGLE("GL_OES_texture_npot");
1044 ASSERT_GL_NO_ERROR();
1045
1046 // Try again to set NPOT mip 1
1047 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1048 ASSERT_GL_NO_ERROR();
1049 }
1050}
1051
Jamie Madillcad97ee2017-02-02 18:52:44 -05001052template <typename T>
1053void FillTexture2D(GLuint texture,
1054 GLsizei width,
1055 GLsizei height,
1056 const T &onePixelData,
1057 GLint level,
1058 GLint internalFormat,
1059 GLenum format,
1060 GLenum type)
1061{
1062 std::vector<T> allPixelsData(width * height, onePixelData);
1063
1064 glBindTexture(GL_TEXTURE_2D, texture);
1065 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
1066 allPixelsData.data());
1067 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1068 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1069 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1070 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1071}
1072
Frank Henigman875bbba2017-02-08 16:38:17 -05001073// Test that unset gl_Position defaults to (0,0,0,0).
1074TEST_P(WebGLCompatibilityTest, DefaultPosition)
1075{
1076 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
1077 // and green otherwise. The center of each quadrant will be red if and only if all
1078 // four corners are red.
1079 const std::string vertexShader =
1080 "attribute vec3 pos;\n"
1081 "varying vec4 color;\n"
1082 "void main() {\n"
1083 " if (gl_Position == vec4(0,0,0,0)) {\n"
1084 " color = vec4(1,0,0,1);\n"
1085 " } else {\n"
1086 " color = vec4(0,1,0,1);\n"
1087 " }\n"
1088 " gl_Position = vec4(pos,1);\n"
1089 "}\n";
1090
1091 const std::string fragmentShader =
1092 "precision mediump float;\n"
1093 "varying vec4 color;\n"
1094 "void main() {\n"
1095 " gl_FragColor = color;\n"
1096 "}\n";
1097
1098 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1099 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
1100 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1101 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1102 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1103 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1104}
1105
Jamie Madilla4595b82017-01-11 17:36:34 -05001106// Tests that a rendering feedback loop triggers a GL error under WebGL.
1107// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
1108TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
1109{
1110 const std::string vertexShader =
1111 "attribute vec4 a_position;\n"
1112 "varying vec2 v_texCoord;\n"
1113 "void main() {\n"
1114 " gl_Position = a_position;\n"
1115 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
1116 "}\n";
1117
1118 const std::string fragmentShader =
1119 "precision mediump float;\n"
1120 "varying vec2 v_texCoord;\n"
1121 "uniform sampler2D u_texture;\n"
1122 "void main() {\n"
1123 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
1124 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
1125 "}\n";
1126
1127 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001128 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001129
1130 ASSERT_GL_NO_ERROR();
1131
1132 GLFramebuffer framebuffer;
1133 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1134 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1135
1136 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1137
1138 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1139
1140 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
1141 ASSERT_NE(-1, uniformLoc);
1142
1143 glUseProgram(program.get());
1144 glUniform1i(uniformLoc, 0);
1145 glDisable(GL_BLEND);
1146 glDisable(GL_DEPTH_TEST);
1147 ASSERT_GL_NO_ERROR();
1148
1149 // Drawing with a texture that is also bound to the current framebuffer should fail
1150 glBindTexture(GL_TEXTURE_2D, texture.get());
1151 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1152 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1153
1154 // Ensure that the texture contents did not change after the previous render
1155 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1156 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1157 ASSERT_GL_NO_ERROR();
1158 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1159
1160 // Drawing when texture is bound to an inactive uniform should succeed
1161 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001162 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001163
1164 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1165 glActiveTexture(GL_TEXTURE1);
1166 glBindTexture(GL_TEXTURE_2D, texture.get());
1167 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1168 ASSERT_GL_NO_ERROR();
1169 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1170}
1171
Bryan Bernhart58806562017-01-05 13:09:31 -08001172// Test for the max draw buffers and color attachments.
1173TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
1174{
1175 // This test only applies to ES2.
1176 if (getClientMajorVersion() != 2)
1177 {
1178 return;
1179 }
1180
1181 GLFramebuffer fbo[2];
1182 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
1183
1184 // Test that is valid when we bind with a single attachment point.
1185 GLTexture texture;
1186 glBindTexture(GL_TEXTURE_2D, texture.get());
1187 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1188 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1189 ASSERT_GL_NO_ERROR();
1190
1191 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
1192 // attachment point.
1193 if (extensionRequestable("GL_EXT_draw_buffers"))
1194 {
1195 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1196 EXPECT_GL_NO_ERROR();
1197 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1198
1199 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
1200
1201 GLTexture texture2;
1202 glBindTexture(GL_TEXTURE_2D, texture2.get());
1203 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1204 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
1205 0);
1206 ASSERT_GL_NO_ERROR();
1207 }
1208}
1209
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001210// Test that the offset in the index buffer is forced to be a multiple of the element size
1211TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
1212{
1213 const std::string &vert =
1214 "attribute vec3 a_pos;\n"
1215 "void main()\n"
1216 "{\n"
1217 " gl_Position = vec4(a_pos, 1.0);\n"
1218 "}\n";
1219
1220 const std::string &frag =
1221 "precision highp float;\n"
1222 "void main()\n"
1223 "{\n"
1224 " gl_FragColor = vec4(1.0);\n"
1225 "}\n";
1226
1227 ANGLE_GL_PROGRAM(program, vert, frag);
1228
1229 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1230 ASSERT_NE(-1, posLocation);
1231 glUseProgram(program.get());
1232
1233 const auto &vertices = GetQuadVertices();
1234
1235 GLBuffer vertexBuffer;
1236 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1237 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1238 GL_STATIC_DRAW);
1239
1240 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1241 glEnableVertexAttribArray(posLocation);
1242
1243 GLBuffer indexBuffer;
1244 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0};
1245 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1246 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1247
1248 ASSERT_GL_NO_ERROR();
1249
1250 const char *zeroIndices = nullptr;
1251
1252 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1253 ASSERT_GL_NO_ERROR();
1254
1255 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices);
1256 ASSERT_GL_NO_ERROR();
1257
1258 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1);
1259 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1260}
1261
1262// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1263// size
1264TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1265{
1266 const char *zeroOffset = nullptr;
1267
1268 // Base case, vector of two floats
1269 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1270 ASSERT_GL_NO_ERROR();
1271
1272 // Test setting a non-multiple offset
1273 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1274 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1275 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1276 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1277 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1278 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1279
1280 // Test setting a non-multiple stride
1281 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1282 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1283 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1284 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1285 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1286 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1287}
1288
Jamie Madillcad97ee2017-02-02 18:52:44 -05001289void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1290 const std::array<GLenum, 2> &drawBuffers,
1291 GLenum expectedError)
1292{
1293 glDrawBuffersEXT(2, drawBuffers.data());
1294
1295 // Make sure framebuffer is complete before feedback loop detection
1296 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1297
1298 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1299
1300 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1301 // it should be NO_ERROR"
1302 EXPECT_GL_ERROR(expectedError);
1303}
1304
1305// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1306// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1307TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1308{
1309 const std::string vertexShader =
1310 "attribute vec4 aPosition;\n"
1311 "varying vec2 texCoord;\n"
1312 "void main() {\n"
1313 " gl_Position = aPosition;\n"
1314 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1315 "}\n";
1316
1317 const std::string fragmentShader =
1318 "#extension GL_EXT_draw_buffers : require\n"
1319 "precision mediump float;\n"
1320 "uniform sampler2D tex;\n"
1321 "varying vec2 texCoord;\n"
1322 "void main() {\n"
1323 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1324 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1325 "}\n";
1326
1327 GLsizei width = 8;
1328 GLsizei height = 8;
1329
1330 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1331 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1332 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1333 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1334 {
1335 // No WEBGL_draw_buffers support -- this is legal.
1336 return;
1337 }
1338
1339 GLint maxDrawBuffers = 0;
1340 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1341
1342 if (maxDrawBuffers < 2)
1343 {
1344 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1345 return;
1346 }
1347
1348 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1349 glUseProgram(program.get());
1350 glViewport(0, 0, width, height);
1351
1352 GLTexture tex0;
1353 GLTexture tex1;
1354 GLFramebuffer fbo;
1355 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1356 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1357 ASSERT_GL_NO_ERROR();
1358
1359 glBindTexture(GL_TEXTURE_2D, tex1.get());
1360 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1361 ASSERT_NE(-1, texLoc);
1362 glUniform1i(texLoc, 0);
1363 ASSERT_GL_NO_ERROR();
1364
1365 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1366 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1367 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1368 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1369
1370 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1371 GL_INVALID_OPERATION);
1372 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1373 GL_INVALID_OPERATION);
1374 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1375}
1376
Jamie Madill07be8bf2017-02-02 19:59:57 -05001377// Test tests that texture copying feedback loops are properly rejected in WebGL.
1378// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1379TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1380{
1381 GLTexture texture;
1382 glBindTexture(GL_TEXTURE_2D, texture.get());
1383 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1385 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1386 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1387 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1388
1389 GLTexture texture2;
1390 glBindTexture(GL_TEXTURE_2D, texture2.get());
1391 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1392 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1394 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1396
1397 GLFramebuffer framebuffer;
1398 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1399 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1400
1401 // framebuffer should be FRAMEBUFFER_COMPLETE.
1402 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1403 ASSERT_GL_NO_ERROR();
1404
1405 // testing copyTexImage2D
1406
1407 // copyTexImage2D to same texture but different level
1408 glBindTexture(GL_TEXTURE_2D, texture.get());
1409 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1410 EXPECT_GL_NO_ERROR();
1411
1412 // copyTexImage2D to same texture same level, invalid feedback loop
1413 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1414 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1415
1416 // copyTexImage2D to different texture
1417 glBindTexture(GL_TEXTURE_2D, texture2.get());
1418 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1419 EXPECT_GL_NO_ERROR();
1420
1421 // testing copyTexSubImage2D
1422
1423 // copyTexSubImage2D to same texture but different level
1424 glBindTexture(GL_TEXTURE_2D, texture.get());
1425 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1426 EXPECT_GL_NO_ERROR();
1427
1428 // copyTexSubImage2D to same texture same level, invalid feedback loop
1429 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1430 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1431
1432 // copyTexSubImage2D to different texture
1433 glBindTexture(GL_TEXTURE_2D, texture2.get());
1434 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1435 EXPECT_GL_NO_ERROR();
1436}
1437
1438void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1439 const std::array<GLenum, 2> &drawBuffers,
1440 GLenum expectedError)
1441{
1442 glDrawBuffers(2, drawBuffers.data());
1443
1444 // Make sure framebuffer is complete before feedback loop detection
1445 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1446
1447 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1448
1449 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1450 // it should be NO_ERROR"
1451 EXPECT_GL_ERROR(expectedError);
1452}
1453
Yuly Novikov817232e2017-02-22 18:36:10 -05001454// Tests invariance matching rules between built in varyings.
1455// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1456TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1457{
1458 const std::string vertexShaderVariant =
1459 "varying vec4 v_varying;\n"
1460 "void main()\n"
1461 "{\n"
1462 " gl_PointSize = 1.0;\n"
1463 " gl_Position = v_varying;\n"
1464 "}";
1465 const std::string fragmentShaderInvariantGlFragCoord =
1466 "invariant gl_FragCoord;\n"
1467 "void main()\n"
1468 "{\n"
1469 " gl_FragColor = gl_FragCoord;\n"
1470 "}";
1471 const std::string fragmentShaderInvariantGlPointCoord =
1472 "invariant gl_PointCoord;\n"
1473 "void main()\n"
1474 "{\n"
1475 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1476 "}";
1477
1478 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1479 EXPECT_EQ(0u, program);
1480
1481 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1482 EXPECT_EQ(0u, program);
1483}
1484
Geoff Lang966c9402017-04-18 12:38:27 -04001485// Test dimension and image size validation of compressed textures
1486TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
1487{
1488 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
1489 {
1490 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
1491 }
1492
1493 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
1494 {
1495 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
1496 << std::endl;
1497 return;
1498 }
1499
1500 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
1501
1502 GLTexture texture;
1503 glBindTexture(GL_TEXTURE_2D, texture);
1504
1505 // Regular case, verify that it works
1506 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1507 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1508 ASSERT_GL_NO_ERROR();
1509
1510 // Test various dimensions that are not valid
1511 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
1512 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1513 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1514
1515 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
1516 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1517 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1518
1519 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1520 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1521 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1522
1523 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1524 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1525 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1526
1527 // Test various image sizes that are not valid
1528 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1529 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
1530 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1531
1532 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1533 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
1534 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1535
1536 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
1537 CompressedImageDXT1);
1538 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1539
1540 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
1541 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1542 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1543
1544 // Fill a full mip chain and verify that it works
1545 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1546 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1547 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1548 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1549 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1550 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1551 ASSERT_GL_NO_ERROR();
1552
1553 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1554 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1555 ASSERT_GL_NO_ERROR();
1556
1557 // Test that non-block size sub-uploads are not valid for the 0 mip
1558 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1559 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1560 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1561
1562 // Test that non-block size sub-uploads are valid for if they fill the whole mip
1563 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1564 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1565 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1566 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1567 ASSERT_GL_NO_ERROR();
1568
1569 // Test that if the format miss-matches the texture, an error is generated
1570 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1571 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1572 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1573}
1574
Geoff Lang677bb6f2017-04-05 12:40:40 -04001575TEST_P(WebGLCompatibilityTest, L32FTextures)
1576{
1577 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
1578 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
1579
1580 for (auto extension : FloatingPointTextureExtensions)
1581 {
1582 if (strlen(extension) > 0 && extensionRequestable(extension))
1583 {
1584 glRequestExtensionANGLE(extension);
1585 ASSERT_GL_NO_ERROR();
1586 }
1587
1588 // Unsized L 32F
1589 {
1590 bool texture = extensionEnabled("GL_OES_texture_float");
1591 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1592 bool render = false;
1593 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
1594 textureData, readPixelData);
1595 }
1596
1597 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1598 {
1599 // Sized L 32F
1600 bool texture = extensionEnabled("GL_OES_texture_float") &&
1601 extensionEnabled("GL_EXT_texture_storage");
1602 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1603 bool render = false;
1604 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
1605 render, textureData, readPixelData);
1606 }
1607 }
1608}
1609
1610TEST_P(WebGLCompatibilityTest, A32FTextures)
1611{
1612 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
1613 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
1614
1615 for (auto extension : FloatingPointTextureExtensions)
1616 {
1617 if (strlen(extension) > 0 && extensionRequestable(extension))
1618 {
1619 glRequestExtensionANGLE(extension);
1620 ASSERT_GL_NO_ERROR();
1621 }
1622
1623 // Unsized A 32F
1624 {
1625 bool texture = extensionEnabled("GL_OES_texture_float");
1626 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1627 bool render = false;
1628 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
1629 textureData, readPixelData);
1630 }
1631
1632 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1633 {
1634 // Sized A 32F
1635 bool texture = extensionEnabled("GL_OES_texture_float") &&
1636 extensionEnabled("GL_EXT_texture_storage");
1637 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1638 bool render = false;
1639 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
1640 textureData, readPixelData);
1641 }
1642 }
1643}
1644
1645TEST_P(WebGLCompatibilityTest, LA32FTextures)
1646{
1647 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
1648 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
1649 textureData[1]};
1650
1651 for (auto extension : FloatingPointTextureExtensions)
1652 {
1653 if (strlen(extension) > 0 && extensionRequestable(extension))
1654 {
1655 glRequestExtensionANGLE(extension);
1656 ASSERT_GL_NO_ERROR();
1657 }
1658
1659 // Unsized LA 32F
1660 {
1661 bool texture = extensionEnabled("GL_OES_texture_float");
1662 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1663 bool render = false;
1664 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1665 filter, render, textureData, readPixelData);
1666 }
1667
1668 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1669 {
1670 // Sized LA 32F
1671 bool texture = extensionEnabled("GL_OES_texture_float") &&
1672 extensionEnabled("GL_EXT_texture_storage");
1673 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1674 bool render = false;
1675 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1676 filter, render, textureData, readPixelData);
1677 }
1678 }
1679}
1680
1681TEST_P(WebGLCompatibilityTest, R32FTextures)
1682{
1683 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
1684
1685 for (auto extension : FloatingPointTextureExtensions)
1686 {
1687 if (strlen(extension) > 0 && extensionRequestable(extension))
1688 {
1689 glRequestExtensionANGLE(extension);
1690 ASSERT_GL_NO_ERROR();
1691 }
1692
1693 // Unsized R 32F
1694 {
1695 bool texture =
1696 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
1697 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1698 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1699 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1700 }
1701
1702 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1703 {
1704 // Sized R 32F
1705 bool texture =
1706 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1707 extensionEnabled("GL_EXT_texture_rg") &&
1708 extensionEnabled("GL_EXT_texture_storage"));
1709 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1710 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1711 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1712 }
1713 }
1714}
1715
1716TEST_P(WebGLCompatibilityTest, RG32FTextures)
1717{
1718 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
1719
1720 for (auto extension : FloatingPointTextureExtensions)
1721 {
1722 if (strlen(extension) > 0 && extensionRequestable(extension))
1723 {
1724 glRequestExtensionANGLE(extension);
1725 ASSERT_GL_NO_ERROR();
1726 }
1727
1728 // Unsized RG 32F
1729 {
1730 bool texture =
1731 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
1732 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1733 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1734 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1735 }
1736
1737 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1738 {
1739 // Sized RG 32F
1740 bool texture =
1741 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1742 extensionEnabled("GL_EXT_texture_rg") &&
1743 extensionEnabled("GL_EXT_texture_storage"));
1744 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1745 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1746 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1747 }
1748 }
1749}
1750
1751TEST_P(WebGLCompatibilityTest, RGB32FTextures)
1752{
Geoff Lang40762ef2017-05-08 13:47:03 -04001753 if (IsLinux() && IsIntel())
1754 {
1755 std::cout << "Test skipped on Linux Intel." << std::endl;
1756 return;
1757 }
1758
Geoff Lang677bb6f2017-04-05 12:40:40 -04001759 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
1760
1761 for (auto extension : FloatingPointTextureExtensions)
1762 {
1763 if (strlen(extension) > 0 && extensionRequestable(extension))
1764 {
1765 glRequestExtensionANGLE(extension);
1766 ASSERT_GL_NO_ERROR();
1767 }
1768
1769 // Unsized RGB 32F
1770 {
1771 bool texture = extensionEnabled("GL_OES_texture_float");
1772 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1773 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1774 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
1775 }
1776
1777 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1778 {
1779 // Sized RGBA 32F
1780 bool texture =
1781 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1782 extensionEnabled("GL_EXT_texture_storage"));
1783 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1784 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1785 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
1786 data);
1787 }
1788 }
1789}
1790
1791TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
1792{
1793 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
1794
1795 for (auto extension : FloatingPointTextureExtensions)
1796 {
1797 if (strlen(extension) > 0 && extensionRequestable(extension))
1798 {
1799 glRequestExtensionANGLE(extension);
1800 ASSERT_GL_NO_ERROR();
1801 }
1802
1803 // Unsized RGBA 32F
1804 {
1805 bool texture = extensionEnabled("GL_OES_texture_float");
1806 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1807 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1808 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1809 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
1810 }
1811
1812 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1813 {
1814 // Sized RGBA 32F
1815 bool texture =
1816 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1817 extensionEnabled("GL_EXT_texture_storage"));
1818 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1819 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1820 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1821 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
1822 data);
1823 }
1824 }
1825}
1826
1827TEST_P(WebGLCompatibilityTest, R16FTextures)
1828{
1829 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
1830 const GLushort textureData[] = {
1831 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1832 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1833
1834 for (auto extension : FloatingPointTextureExtensions)
1835 {
1836 if (strlen(extension) > 0 && extensionRequestable(extension))
1837 {
1838 glRequestExtensionANGLE(extension);
1839 ASSERT_GL_NO_ERROR();
1840 }
1841
1842 // Unsized R 16F (OES)
1843 {
1844 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1845 extensionEnabled("GL_EXT_texture_rg");
1846 bool filter = getClientMajorVersion() >= 3 ||
1847 extensionEnabled("GL_OES_texture_half_float_linear");
1848 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1849 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
1850 textureData, readPixelsData);
1851 }
1852
1853 // Unsized R 16F
1854 {
1855 bool texture = false;
1856 bool filter = false;
1857 bool render = false;
1858 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1859 textureData, readPixelsData);
1860 }
1861
1862 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1863 {
1864 // Sized R 16F
1865 bool texture = getClientMajorVersion() >= 3;
1866 bool filter = getClientMajorVersion() >= 3 ||
1867 extensionEnabled("GL_OES_texture_half_float_linear");
1868 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1869 extensionEnabled("GL_EXT_color_buffer_float");
1870 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1871 textureData, readPixelsData);
1872 }
1873 }
1874}
1875
1876TEST_P(WebGLCompatibilityTest, RG16FTextures)
1877{
1878 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
1879 const GLushort textureData[] = {
1880 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1881 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1882
1883 for (auto extension : FloatingPointTextureExtensions)
1884 {
1885 if (strlen(extension) > 0 && extensionRequestable(extension))
1886 {
1887 glRequestExtensionANGLE(extension);
1888 ASSERT_GL_NO_ERROR();
1889 }
1890
1891 // Unsized RG 16F (OES)
1892 {
1893 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1894 extensionEnabled("GL_EXT_texture_rg");
1895 bool filter = getClientMajorVersion() >= 3 ||
1896 extensionEnabled("GL_OES_texture_half_float_linear");
1897 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
1898 extensionEnabled("GL_EXT_texture_rg");
1899 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
1900 textureData, readPixelsData);
1901 }
1902
1903 // Unsized RG 16F
1904 {
1905 bool texture = false;
1906 bool filter = false;
1907 bool render = false;
1908 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1909 textureData, readPixelsData);
1910 }
1911
1912 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1913 {
1914 // Sized RG 16F
1915 bool texture = getClientMajorVersion() >= 3;
1916 bool filter = getClientMajorVersion() >= 3 ||
1917 extensionEnabled("GL_OES_texture_half_float_linear");
1918 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1919 extensionEnabled("GL_EXT_color_buffer_float");
1920 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1921 textureData, readPixelsData);
1922 }
1923 }
1924}
1925
1926TEST_P(WebGLCompatibilityTest, RGB16FTextures)
1927{
Geoff Lang40762ef2017-05-08 13:47:03 -04001928 if (IsOzone() && IsIntel())
1929 {
1930 std::cout << "Test skipped on Intel Ozone." << std::endl;
1931 return;
1932 }
1933
Geoff Lang677bb6f2017-04-05 12:40:40 -04001934 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
1935 const GLushort textureData[] = {
1936 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1937 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1938
1939 for (auto extension : FloatingPointTextureExtensions)
1940 {
1941 if (strlen(extension) > 0 && extensionRequestable(extension))
1942 {
1943 glRequestExtensionANGLE(extension);
1944 ASSERT_GL_NO_ERROR();
1945 }
1946
1947 // Unsized RGB 16F (OES)
1948 {
1949 bool texture = extensionEnabled("GL_OES_texture_half_float");
1950 bool filter = getClientMajorVersion() >= 3 ||
1951 extensionEnabled("GL_OES_texture_half_float_linear");
1952 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1953 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
1954 textureData, readPixelsData);
1955 }
1956
1957 // Unsized RGB 16F
1958 {
1959 bool texture = false;
1960 bool filter = false;
1961 bool render = false;
1962 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
1963 textureData, readPixelsData);
1964 }
1965
1966 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1967 {
1968 // Sized RGB 16F
1969 bool texture = getClientMajorVersion() >= 3;
1970 bool filter = getClientMajorVersion() >= 3 ||
1971 extensionEnabled("GL_OES_texture_half_float_linear");
1972 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1973 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
1974 textureData, readPixelsData);
1975 }
1976 }
1977}
1978
1979TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
1980{
Geoff Lang40762ef2017-05-08 13:47:03 -04001981 if (IsOzone() && IsIntel())
1982 {
1983 std::cout << "Test skipped on Intel Ozone." << std::endl;
1984 return;
1985 }
1986
Geoff Lang677bb6f2017-04-05 12:40:40 -04001987 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
1988 const GLushort textureData[] = {
1989 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1990 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1991
1992 for (auto extension : FloatingPointTextureExtensions)
1993 {
1994 if (strlen(extension) > 0 && extensionRequestable(extension))
1995 {
1996 glRequestExtensionANGLE(extension);
1997 ASSERT_GL_NO_ERROR();
1998 }
1999
2000 // Unsized RGBA 16F (OES)
2001 {
2002 bool texture = extensionEnabled("GL_OES_texture_half_float");
2003 bool filter = getClientMajorVersion() >= 3 ||
2004 extensionEnabled("GL_OES_texture_half_float_linear");
2005 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2006 extensionEnabled("GL_EXT_color_buffer_float");
2007 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
2008 textureData, readPixelsData);
2009 }
2010
2011 // Unsized RGBA 16F
2012 {
2013 bool texture = false;
2014 bool filter = false;
2015 bool render = false;
2016 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2017 textureData, readPixelsData);
2018 }
2019
2020 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
2021 {
2022 // Sized RGBA 16F
2023 bool texture = getClientMajorVersion() >= 3;
2024 bool filter = getClientMajorVersion() >= 3 ||
2025 extensionEnabled("GL_OES_texture_half_float_linear");
2026 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
2027 extensionEnabled("GL_EXT_color_buffer_float");
2028 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
2029 textureData, readPixelsData);
2030 }
2031 }
2032}
2033
Geoff Lang6e898aa2017-06-02 11:17:26 -04002034// Test that when GL_CHROMIUM_color_buffer_float_rgb[a] is enabled, sized GL_RGB[A]_32F formats are
2035// accepted by glTexImage2D
2036TEST_P(WebGLCompatibilityTest, SizedRGBA32FFormats)
2037{
2038 if (getClientMajorVersion() != 2)
2039 {
2040 std::cout << "Test skipped because it is only valid for WebGL1 contexts." << std::endl;
2041 return;
2042 }
2043
2044 if (!extensionRequestable("GL_OES_texture_float"))
2045 {
2046 std::cout << "Test skipped because GL_OES_texture_float is not requestable." << std::endl;
2047 return;
2048 }
2049 glRequestExtensionANGLE("GL_OES_texture_float");
2050 ASSERT_GL_NO_ERROR();
2051
2052 GLTexture texture;
2053 glBindTexture(GL_TEXTURE_2D, texture);
2054
2055 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2056 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2057
2058 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2059 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2060
2061 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgba"))
2062 {
2063 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgba");
2064 ASSERT_GL_NO_ERROR();
2065
2066 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2067 EXPECT_GL_NO_ERROR();
2068 }
2069
2070 if (extensionRequestable("GL_CHROMIUM_color_buffer_float_rgb"))
2071 {
2072 glRequestExtensionANGLE("GL_CHROMIUM_color_buffer_float_rgb");
2073 ASSERT_GL_NO_ERROR();
2074
2075 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 1, 1, 0, GL_RGB, GL_FLOAT, nullptr);
2076 EXPECT_GL_NO_ERROR();
2077 }
2078}
2079
Jamie Madill07be8bf2017-02-02 19:59:57 -05002080// This tests that rendering feedback loops works as expected with WebGL 2.
2081// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2082TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2083{
2084 const std::string vertexShader =
2085 "#version 300 es\n"
2086 "in vec4 aPosition;\n"
2087 "out vec2 texCoord;\n"
2088 "void main() {\n"
2089 " gl_Position = aPosition;\n"
2090 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2091 "}\n";
2092
2093 const std::string fragmentShader =
2094 "#version 300 es\n"
2095 "precision mediump float;\n"
2096 "uniform sampler2D tex;\n"
2097 "in vec2 texCoord;\n"
2098 "out vec4 oColor;\n"
2099 "void main() {\n"
2100 " oColor = texture(tex, texCoord);\n"
2101 "}\n";
2102
2103 GLsizei width = 8;
2104 GLsizei height = 8;
2105
2106 GLint maxDrawBuffers = 0;
2107 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2108 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2109 ASSERT_GE(maxDrawBuffers, 2);
2110
2111 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2112 glUseProgram(program.get());
2113 glViewport(0, 0, width, height);
2114
2115 GLTexture tex0;
2116 GLTexture tex1;
2117 GLFramebuffer fbo;
2118 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2119 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2120 ASSERT_GL_NO_ERROR();
2121
2122 glBindTexture(GL_TEXTURE_2D, tex1.get());
2123 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2124 ASSERT_NE(-1, texLoc);
2125 glUniform1i(texLoc, 0);
2126
2127 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2128 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2129 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2130 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2131 ASSERT_GL_NO_ERROR();
2132
2133 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2134 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2135 GL_INVALID_OPERATION);
2136 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2137}
2138
Jamie Madill1d37bc52017-02-02 19:59:58 -05002139// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2140// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2141TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2142{
2143 const std::string vertexShader =
2144 "#version 300 es\n"
2145 "in vec4 aPosition;\n"
2146 "out vec2 texCoord;\n"
2147 "void main() {\n"
2148 " gl_Position = aPosition;\n"
2149 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2150 "}\n";
2151
2152 const std::string fragmentShader =
2153 "#version 300 es\n"
2154 "precision mediump float;\n"
2155 "uniform sampler2D tex;\n"
2156 "in vec2 texCoord;\n"
2157 "out vec4 oColor;\n"
2158 "void main() {\n"
2159 " oColor = texture(tex, texCoord);\n"
2160 "}\n";
2161
2162 GLsizei width = 8;
2163 GLsizei height = 8;
2164
2165 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2166 glUseProgram(program.get());
2167
2168 glViewport(0, 0, width, height);
2169
2170 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2171 glUniform1i(texLoc, 0);
2172
2173 // Create textures and allocate storage
2174 GLTexture tex0;
2175 GLTexture tex1;
2176 GLRenderbuffer rb;
2177 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2178 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2179 GL_UNSIGNED_INT);
2180 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2181 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2182 ASSERT_GL_NO_ERROR();
2183
2184 GLFramebuffer fbo;
2185 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2186 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2187
2188 // Test rendering and sampling feedback loop for depth buffer
2189 glBindTexture(GL_TEXTURE_2D, tex1.get());
2190 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2191 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2192
2193 // The same image is used as depth buffer during rendering.
2194 glEnable(GL_DEPTH_TEST);
2195 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2196 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2197
2198 // The same image is used as depth buffer. But depth mask is false.
2199 glDepthMask(GL_FALSE);
2200 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2201 EXPECT_GL_NO_ERROR();
2202
2203 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2204 glDepthMask(GL_TRUE);
2205 glDisable(GL_DEPTH_TEST);
2206 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2207 EXPECT_GL_NO_ERROR();
2208
2209 // Test rendering and sampling feedback loop for stencil buffer
2210 glBindTexture(GL_RENDERBUFFER, rb.get());
2211 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2212 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2213 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2214 constexpr GLint stencilClearValue = 0x40;
2215 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2216
2217 // The same image is used as stencil buffer during rendering.
2218 glEnable(GL_STENCIL_TEST);
2219 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2220 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2221
2222 // The same image is used as stencil buffer. But stencil mask is zero.
2223 glStencilMask(0x0);
2224 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2225 EXPECT_GL_NO_ERROR();
2226
2227 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2228 glStencilMask(0xffff);
2229 glDisable(GL_STENCIL_TEST);
2230 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2231 EXPECT_GL_NO_ERROR();
2232}
2233
Jamie Madillfd3dd432017-02-02 19:59:59 -05002234// The source and the target for CopyTexSubImage3D are the same 3D texture.
2235// But the level of the 3D texture != the level of the read attachment.
2236TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2237{
2238 GLTexture texture;
2239 GLFramebuffer framebuffer;
2240
2241 glBindTexture(GL_TEXTURE_3D, texture.get());
2242 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2243
2244 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2245 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2246 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2247 ASSERT_GL_NO_ERROR();
2248
2249 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2250 EXPECT_GL_NO_ERROR();
2251}
2252
2253// The source and the target for CopyTexSubImage3D are the same 3D texture.
2254// But the zoffset of the 3D texture != the layer of the read attachment.
2255TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2256{
2257 GLTexture texture;
2258 GLFramebuffer framebuffer;
2259
2260 glBindTexture(GL_TEXTURE_3D, texture.get());
2261 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2262
2263 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2264 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2265 ASSERT_GL_NO_ERROR();
2266
2267 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2268 EXPECT_GL_NO_ERROR();
2269}
2270
2271// The source and the target for CopyTexSubImage3D are the same 3D texture.
2272// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2273TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2274{
2275 GLTexture texture;
2276 GLFramebuffer framebuffer;
2277
2278 glBindTexture(GL_TEXTURE_3D, texture.get());
2279 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2280
2281 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2282 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2283 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2284 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2285 ASSERT_GL_NO_ERROR();
2286
2287 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2288 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2289}
2290
Geoff Lang76e65652017-03-27 14:58:02 -04002291// Verify that errors are generated when there isn not a defined conversion between the clear type
2292// and the buffer type.
2293TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2294{
2295 if (IsD3D11())
2296 {
2297 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2298 return;
2299 }
2300
2301 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2302 constexpr int clearInt[] = {0, 0, 0, 0};
2303 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2304
2305 GLTexture texture;
2306 GLFramebuffer framebuffer;
2307
2308 glBindTexture(GL_TEXTURE_2D, texture.get());
2309 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2310
2311 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2312 ASSERT_GL_NO_ERROR();
2313
2314 // Unsigned integer buffer
2315 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2316 ASSERT_GL_NO_ERROR();
2317
2318 glClearBufferfv(GL_COLOR, 0, clearFloat);
2319 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2320
2321 glClearBufferiv(GL_COLOR, 0, clearInt);
2322 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2323
2324 glClearBufferuiv(GL_COLOR, 0, clearUint);
2325 EXPECT_GL_NO_ERROR();
2326
2327 glClear(GL_COLOR_BUFFER_BIT);
2328 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2329
2330 // Integer buffer
2331 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2332 ASSERT_GL_NO_ERROR();
2333
2334 glClearBufferfv(GL_COLOR, 0, clearFloat);
2335 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2336
2337 glClearBufferiv(GL_COLOR, 0, clearInt);
2338 EXPECT_GL_NO_ERROR();
2339
2340 glClearBufferuiv(GL_COLOR, 0, clearUint);
2341 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2342
2343 glClear(GL_COLOR_BUFFER_BIT);
2344 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2345
2346 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002347 if (extensionRequestable("GL_EXT_color_buffer_float"))
2348 {
2349 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2350 }
Geoff Lang76e65652017-03-27 14:58:02 -04002351
Geoff Lang677bb6f2017-04-05 12:40:40 -04002352 if (extensionEnabled("GL_EXT_color_buffer_float"))
2353 {
2354 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2355 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002356
Geoff Lang677bb6f2017-04-05 12:40:40 -04002357 glClearBufferfv(GL_COLOR, 0, clearFloat);
2358 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002359
Geoff Lang677bb6f2017-04-05 12:40:40 -04002360 glClearBufferiv(GL_COLOR, 0, clearInt);
2361 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002362
Geoff Lang677bb6f2017-04-05 12:40:40 -04002363 glClearBufferuiv(GL_COLOR, 0, clearUint);
2364 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2365
2366 glClear(GL_COLOR_BUFFER_BIT);
2367 EXPECT_GL_NO_ERROR();
2368 }
Geoff Lang76e65652017-03-27 14:58:02 -04002369
2370 // Normalized uint buffer
2371 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2372 ASSERT_GL_NO_ERROR();
2373
2374 glClearBufferfv(GL_COLOR, 0, clearFloat);
2375 EXPECT_GL_NO_ERROR();
2376
2377 glClearBufferiv(GL_COLOR, 0, clearInt);
2378 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2379
2380 glClearBufferuiv(GL_COLOR, 0, clearUint);
2381 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2382
2383 glClear(GL_COLOR_BUFFER_BIT);
2384 EXPECT_GL_NO_ERROR();
2385}
2386
Geoff Lange4915782017-04-12 15:19:07 -04002387// Verify that errors are generate when trying to blit from an image to itself
2388TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2389{
2390 GLTexture textures[2];
2391 glBindTexture(GL_TEXTURE_2D, textures[0]);
2392 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2393 glBindTexture(GL_TEXTURE_2D, textures[1]);
2394 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2395
2396 GLRenderbuffer renderbuffers[2];
2397 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2398 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2399 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2400 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2401
2402 GLFramebuffer framebuffers[2];
2403 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2404 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2405
2406 ASSERT_GL_NO_ERROR();
2407
2408 // Same texture
2409 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2410 0);
2411 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2412 0);
2413 ASSERT_GL_NO_ERROR();
2414 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2415 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2416
2417 // Same textures but different renderbuffers
2418 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2419 renderbuffers[0]);
2420 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2421 renderbuffers[1]);
2422 ASSERT_GL_NO_ERROR();
2423 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2424 ASSERT_GL_NO_ERROR();
2425 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2426 GL_NEAREST);
2427 ASSERT_GL_NO_ERROR();
2428 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2429 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2430 GL_NEAREST);
2431 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2432
2433 // Same renderbuffers but different textures
2434 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2435 0);
2436 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2437 0);
2438 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2439 renderbuffers[0]);
2440 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2441 renderbuffers[0]);
2442 ASSERT_GL_NO_ERROR();
2443 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2444 ASSERT_GL_NO_ERROR();
2445 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2446 GL_NEAREST);
2447 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2448 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2449 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2450 GL_NEAREST);
2451 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2452}
2453
Geoff Lange0cff192017-05-30 13:04:56 -04002454// Verify that errors are generated when the fragment shader output doesn't match the bound color
2455// buffer types
2456TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
2457{
2458 const std::string vertexShader =
2459 "#version 300 es\n"
2460 "void main() {\n"
2461 " gl_Position = vec4(0, 0, 0, 1);\n"
2462 "}\n";
2463
2464 const std::string fragmentShader =
2465 "#version 300 es\n"
2466 "precision mediump float;\n"
2467 "layout(location = 0) out vec4 floatOutput;\n"
2468 "layout(location = 1) out uvec4 uintOutput;\n"
2469 "layout(location = 2) out ivec4 intOutput;\n"
2470 "void main() {\n"
2471 " floatOutput = vec4(0, 0, 0, 1);\n"
2472 " uintOutput = uvec4(0, 0, 0, 1);\n"
2473 " intOutput = ivec4(0, 0, 0, 1);\n"
2474 "}\n";
2475
2476 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2477 glUseProgram(program.get());
2478
2479 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
2480 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
2481 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
2482
2483 GLFramebuffer fbo;
2484 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2485
2486 GLRenderbuffer floatRenderbuffer;
2487 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
2488 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2489 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2490 floatRenderbuffer);
2491
2492 GLRenderbuffer uintRenderbuffer;
2493 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
2494 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
2495 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2496 uintRenderbuffer);
2497
2498 GLRenderbuffer intRenderbuffer;
2499 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
2500 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
2501 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2502 intRenderbuffer);
2503
2504 ASSERT_GL_NO_ERROR();
2505
2506 GLint maxDrawBuffers = 0;
2507 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2508 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
2509 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
2510 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
2511 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
2512
2513 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2514
2515 // Check that the correct case generates no errors
2516 glDrawArrays(GL_TRIANGLES, 0, 6);
2517 EXPECT_GL_NO_ERROR();
2518
2519 // Unbind some buffers and verify that there are still no errors
2520 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2521 0);
2522 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2523 0);
2524 glDrawArrays(GL_TRIANGLES, 0, 6);
2525 EXPECT_GL_NO_ERROR();
2526
2527 // Swap the int and uint buffers to and verify that an error is generated
2528 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2529 intRenderbuffer);
2530 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2531 uintRenderbuffer);
2532 glDrawArrays(GL_TRIANGLES, 0, 6);
2533 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2534
2535 // Swap the float and uint buffers to and verify that an error is generated
2536 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2537 floatRenderbuffer);
2538 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2539 uintRenderbuffer);
2540 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2541 intRenderbuffer);
2542 glDrawArrays(GL_TRIANGLES, 0, 6);
2543 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2544}
2545
Geoff Lang9ab5b822017-05-30 16:19:23 -04002546// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
2547// types
2548TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMissmatch)
2549{
2550 const std::string vertexShader =
2551 "#version 300 es\n"
2552 "in vec4 floatInput;\n"
2553 "in uvec4 uintInput;\n"
2554 "in ivec4 intInput;\n"
2555 "void main() {\n"
2556 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
2557 "}\n";
2558
2559 const std::string fragmentShader =
2560 "#version 300 es\n"
2561 "precision mediump float;\n"
2562 "out vec4 outputColor;\n"
2563 "void main() {\n"
2564 " outputColor = vec4(0, 0, 0, 1);"
2565 "}\n";
2566
2567 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2568 glUseProgram(program.get());
2569
2570 GLint floatLocation = glGetAttribLocation(program, "floatInput");
2571 GLint uintLocation = glGetAttribLocation(program, "uintInput");
2572 GLint intLocation = glGetAttribLocation(program, "intInput");
2573
2574 // Default attributes are of float types
2575 glDrawArrays(GL_TRIANGLES, 0, 6);
2576 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2577
2578 // Set the default attributes to the correct types, should succeed
2579 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
2580 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
2581 glDrawArrays(GL_TRIANGLES, 0, 6);
2582 EXPECT_GL_NO_ERROR();
2583
2584 // Change the default float attribute to an integer, should fail
2585 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
2586 glDrawArrays(GL_TRIANGLES, 0, 6);
2587 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2588
2589 // Use a buffer for some attributes
2590 GLBuffer buffer;
2591 glBindBuffer(GL_ARRAY_BUFFER, buffer);
2592 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
2593 glEnableVertexAttribArray(floatLocation);
2594 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2595 glDrawArrays(GL_TRIANGLES, 0, 6);
2596 EXPECT_GL_NO_ERROR();
2597
2598 // Use a float pointer attrib for a uint input
2599 glEnableVertexAttribArray(uintLocation);
2600 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2601 glDrawArrays(GL_TRIANGLES, 0, 6);
2602 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2603
2604 // Use a uint pointer for the uint input
2605 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
2606 glDrawArrays(GL_TRIANGLES, 0, 6);
2607 EXPECT_GL_NO_ERROR();
2608}
2609
Corentin Walleze7557742017-06-01 13:09:57 -04002610// Tests the WebGL removal of undefined behavior when attachments aren't written to.
2611TEST_P(WebGLCompatibilityTest, DrawBuffers)
2612{
2613 if (IsD3D9() || IsD3D11())
2614 {
2615 std::cout << "Test skipped on " << GetParam() << std::endl;
2616 return;
2617 }
2618
2619 // Make sure we can use at least 4 attachments for the tests.
2620 bool useEXT = false;
2621 if (getClientMajorVersion() < 3)
2622 {
2623 if (!extensionRequestable("GL_EXT_draw_buffers"))
2624 {
2625 std::cout << "Test skipped because draw buffers are not available" << std::endl;
2626 return;
2627 }
2628
2629 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2630 useEXT = true;
2631 EXPECT_GL_NO_ERROR();
2632 }
2633
2634 GLint maxDrawBuffers = 0;
2635 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2636 if (maxDrawBuffers < 4)
2637 {
2638 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
2639 return;
2640 }
2641
2642 // Clears all the renderbuffers to red.
2643 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
2644 GLFramebuffer clearFBO;
2645 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
2646
2647 glClearColor(1, 0, 0, 1);
2648 for (int i = 0; i < 4; ++i)
2649 {
2650 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2651 renderbuffers[i]);
2652 glClear(GL_COLOR_BUFFER_BIT);
2653 }
2654 ASSERT_GL_NO_ERROR();
2655 };
2656
2657 // Checks that the renderbuffers specified by mask have the correct color
2658 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
2659 GLFramebuffer readFBO;
2660 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
2661
2662 for (int i = 0; i < 4; ++i)
2663 {
2664 if (mask & (1 << i))
2665 {
2666 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2667 GL_RENDERBUFFER, renderbuffers[i]);
2668 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
2669 }
2670 }
2671 ASSERT_GL_NO_ERROR();
2672 };
2673
2674 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
2675 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
2676 if (useEXT)
2677 {
2678 glDrawBuffersEXT(numBuffers, buffers);
2679 }
2680 else
2681 {
2682 glDrawBuffers(numBuffers, buffers);
2683 }
2684 };
2685
2686 // Initialized the test framebuffer
2687 GLFramebuffer drawFBO;
2688 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2689
2690 GLRenderbuffer renderbuffers[4];
2691 for (int i = 0; i < 4; ++i)
2692 {
2693 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
2694 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2695 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
2696 renderbuffers[i]);
2697 }
2698
2699 ASSERT_GL_NO_ERROR();
2700
2701 const char *vertESSL1 =
2702 "attribute vec4 a_pos;\n"
2703 "void main()\n"
2704 "{\n"
2705 " gl_Position = a_pos;\n"
2706 "}\n";
2707 const char *vertESSL3 =
2708 "#version 300 es\n"
2709 "in vec4 a_pos;\n"
2710 "void main()\n"
2711 "{\n"
2712 " gl_Position = a_pos;\n"
2713 "}\n";
2714
2715 GLenum allDrawBuffers[] = {
2716 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2717 };
2718
2719 GLenum halfDrawBuffers[] = {
2720 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2721 };
2722
2723 // Test that when using gl_FragColor, only the first attachment is written to.
2724 const char *fragESSL1 =
2725 "precision highp float;\n"
2726 "void main()\n"
2727 "{\n"
2728 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
2729 "}\n";
2730 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
2731
2732 {
2733 ClearEverythingToRed(renderbuffers);
2734
2735 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2736 DrawBuffers(useEXT, 4, allDrawBuffers);
2737 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2738 ASSERT_GL_NO_ERROR();
2739
2740 CheckColors(renderbuffers, 0b0001, GLColor::green);
2741 CheckColors(renderbuffers, 0b1110, GLColor::red);
2742 }
2743
2744 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
2745 // written to.
2746 {
2747 ClearEverythingToRed(renderbuffers);
2748
2749 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2750 DrawBuffers(useEXT, 4, halfDrawBuffers);
2751 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2752 ASSERT_GL_NO_ERROR();
2753
2754 CheckColors(renderbuffers, 0b1111, GLColor::red);
2755 }
2756
2757 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
2758 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
2759 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
2760 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
2761 // attachments not declared in the shader should not be written to.
2762 const char *writeOddOutputsVert;
2763 const char *writeOddOutputsFrag;
2764 GLColor unwrittenColor;
2765 if (useEXT)
2766 {
2767 // In the extension, when an attachment isn't written to, it should get 0's
2768 unwrittenColor = GLColor(0, 0, 0, 0);
2769 writeOddOutputsVert = vertESSL1;
2770 writeOddOutputsFrag =
2771 "#extension GL_EXT_draw_buffers : require\n"
2772 "precision highp float;\n"
2773 "void main()\n"
2774 "{\n"
2775 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2776 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2777 "}\n";
2778 }
2779 else
2780 {
2781 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
2782 // because of the preceding clears.
2783 unwrittenColor = GLColor::red;
2784 writeOddOutputsVert = vertESSL3;
2785 writeOddOutputsFrag =
2786 "#version 300 es\n"
2787 "precision highp float;\n"
2788 "layout(location = 1) out vec4 output1;"
2789 "layout(location = 3) out vec4 output2;"
2790 "void main()\n"
2791 "{\n"
2792 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2793 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2794 "}\n";
2795 }
2796 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
2797
2798 // Test that attachments not written to get the "unwritten" color
2799 {
2800 ClearEverythingToRed(renderbuffers);
2801
2802 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2803 DrawBuffers(useEXT, 4, allDrawBuffers);
2804 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2805 ASSERT_GL_NO_ERROR();
2806
2807 CheckColors(renderbuffers, 0b1010, GLColor::green);
2808 CheckColors(renderbuffers, 0b0101, unwrittenColor);
2809 }
2810
2811 // Test that attachments not written to get the "unwritten" color but that even when the
2812 // extension is used, disabled attachments are not written at all and stay red.
2813 {
2814 ClearEverythingToRed(renderbuffers);
2815
2816 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2817 DrawBuffers(useEXT, 4, halfDrawBuffers);
2818 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2819 ASSERT_GL_NO_ERROR();
2820
2821 CheckColors(renderbuffers, 0b1000, GLColor::green);
2822 CheckColors(renderbuffers, 0b0100, unwrittenColor);
2823 CheckColors(renderbuffers, 0b0011, GLColor::red);
2824 }
2825}
2826
Geoff Langc287ea62016-09-16 14:46:51 -04002827// Use this to select which configurations (e.g. which renderer, which GLES major version) these
2828// tests should be run against.
2829ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
2830 ES2_D3D9(),
2831 ES2_D3D11(),
2832 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04002833 ES2_OPENGL(),
2834 ES3_OPENGL(),
2835 ES2_OPENGLES(),
2836 ES3_OPENGLES());
2837
Jamie Madill07be8bf2017-02-02 19:59:57 -05002838ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04002839} // namespace