blob: 644f982327837d97d4e30b4c10c44b589a653e2a [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
Jamie Madill07be8bf2017-02-02 19:59:57 -05002034// This tests that rendering feedback loops works as expected with WebGL 2.
2035// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
2036TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
2037{
2038 const std::string vertexShader =
2039 "#version 300 es\n"
2040 "in vec4 aPosition;\n"
2041 "out vec2 texCoord;\n"
2042 "void main() {\n"
2043 " gl_Position = aPosition;\n"
2044 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2045 "}\n";
2046
2047 const std::string fragmentShader =
2048 "#version 300 es\n"
2049 "precision mediump float;\n"
2050 "uniform sampler2D tex;\n"
2051 "in vec2 texCoord;\n"
2052 "out vec4 oColor;\n"
2053 "void main() {\n"
2054 " oColor = texture(tex, texCoord);\n"
2055 "}\n";
2056
2057 GLsizei width = 8;
2058 GLsizei height = 8;
2059
2060 GLint maxDrawBuffers = 0;
2061 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2062 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
2063 ASSERT_GE(maxDrawBuffers, 2);
2064
2065 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2066 glUseProgram(program.get());
2067 glViewport(0, 0, width, height);
2068
2069 GLTexture tex0;
2070 GLTexture tex1;
2071 GLFramebuffer fbo;
2072 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2073 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2074 ASSERT_GL_NO_ERROR();
2075
2076 glBindTexture(GL_TEXTURE_2D, tex1.get());
2077 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2078 ASSERT_NE(-1, texLoc);
2079 glUniform1i(texLoc, 0);
2080
2081 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
2082 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2083 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2084 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
2085 ASSERT_GL_NO_ERROR();
2086
2087 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
2088 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
2089 GL_INVALID_OPERATION);
2090 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2091}
2092
Jamie Madill1d37bc52017-02-02 19:59:58 -05002093// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2094// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2095TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2096{
2097 const std::string vertexShader =
2098 "#version 300 es\n"
2099 "in vec4 aPosition;\n"
2100 "out vec2 texCoord;\n"
2101 "void main() {\n"
2102 " gl_Position = aPosition;\n"
2103 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2104 "}\n";
2105
2106 const std::string fragmentShader =
2107 "#version 300 es\n"
2108 "precision mediump float;\n"
2109 "uniform sampler2D tex;\n"
2110 "in vec2 texCoord;\n"
2111 "out vec4 oColor;\n"
2112 "void main() {\n"
2113 " oColor = texture(tex, texCoord);\n"
2114 "}\n";
2115
2116 GLsizei width = 8;
2117 GLsizei height = 8;
2118
2119 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2120 glUseProgram(program.get());
2121
2122 glViewport(0, 0, width, height);
2123
2124 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2125 glUniform1i(texLoc, 0);
2126
2127 // Create textures and allocate storage
2128 GLTexture tex0;
2129 GLTexture tex1;
2130 GLRenderbuffer rb;
2131 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2132 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2133 GL_UNSIGNED_INT);
2134 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2135 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2136 ASSERT_GL_NO_ERROR();
2137
2138 GLFramebuffer fbo;
2139 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2140 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2141
2142 // Test rendering and sampling feedback loop for depth buffer
2143 glBindTexture(GL_TEXTURE_2D, tex1.get());
2144 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2145 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2146
2147 // The same image is used as depth buffer during rendering.
2148 glEnable(GL_DEPTH_TEST);
2149 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2150 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2151
2152 // The same image is used as depth buffer. But depth mask is false.
2153 glDepthMask(GL_FALSE);
2154 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2155 EXPECT_GL_NO_ERROR();
2156
2157 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2158 glDepthMask(GL_TRUE);
2159 glDisable(GL_DEPTH_TEST);
2160 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2161 EXPECT_GL_NO_ERROR();
2162
2163 // Test rendering and sampling feedback loop for stencil buffer
2164 glBindTexture(GL_RENDERBUFFER, rb.get());
2165 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2166 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2167 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2168 constexpr GLint stencilClearValue = 0x40;
2169 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2170
2171 // The same image is used as stencil buffer during rendering.
2172 glEnable(GL_STENCIL_TEST);
2173 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2174 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2175
2176 // The same image is used as stencil buffer. But stencil mask is zero.
2177 glStencilMask(0x0);
2178 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2179 EXPECT_GL_NO_ERROR();
2180
2181 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2182 glStencilMask(0xffff);
2183 glDisable(GL_STENCIL_TEST);
2184 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2185 EXPECT_GL_NO_ERROR();
2186}
2187
Jamie Madillfd3dd432017-02-02 19:59:59 -05002188// The source and the target for CopyTexSubImage3D are the same 3D texture.
2189// But the level of the 3D texture != the level of the read attachment.
2190TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2191{
2192 GLTexture texture;
2193 GLFramebuffer framebuffer;
2194
2195 glBindTexture(GL_TEXTURE_3D, texture.get());
2196 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2197
2198 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2199 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2200 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2201 ASSERT_GL_NO_ERROR();
2202
2203 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2204 EXPECT_GL_NO_ERROR();
2205}
2206
2207// The source and the target for CopyTexSubImage3D are the same 3D texture.
2208// But the zoffset of the 3D texture != the layer of the read attachment.
2209TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2210{
2211 GLTexture texture;
2212 GLFramebuffer framebuffer;
2213
2214 glBindTexture(GL_TEXTURE_3D, texture.get());
2215 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2216
2217 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2218 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2219 ASSERT_GL_NO_ERROR();
2220
2221 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2222 EXPECT_GL_NO_ERROR();
2223}
2224
2225// The source and the target for CopyTexSubImage3D are the same 3D texture.
2226// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2227TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2228{
2229 GLTexture texture;
2230 GLFramebuffer framebuffer;
2231
2232 glBindTexture(GL_TEXTURE_3D, texture.get());
2233 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2234
2235 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2236 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2237 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2238 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2239 ASSERT_GL_NO_ERROR();
2240
2241 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2242 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2243}
2244
Geoff Lang76e65652017-03-27 14:58:02 -04002245// Verify that errors are generated when there isn not a defined conversion between the clear type
2246// and the buffer type.
2247TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2248{
2249 if (IsD3D11())
2250 {
2251 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2252 return;
2253 }
2254
2255 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2256 constexpr int clearInt[] = {0, 0, 0, 0};
2257 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2258
2259 GLTexture texture;
2260 GLFramebuffer framebuffer;
2261
2262 glBindTexture(GL_TEXTURE_2D, texture.get());
2263 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2264
2265 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2266 ASSERT_GL_NO_ERROR();
2267
2268 // Unsigned integer buffer
2269 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2270 ASSERT_GL_NO_ERROR();
2271
2272 glClearBufferfv(GL_COLOR, 0, clearFloat);
2273 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2274
2275 glClearBufferiv(GL_COLOR, 0, clearInt);
2276 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2277
2278 glClearBufferuiv(GL_COLOR, 0, clearUint);
2279 EXPECT_GL_NO_ERROR();
2280
2281 glClear(GL_COLOR_BUFFER_BIT);
2282 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2283
2284 // Integer buffer
2285 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2286 ASSERT_GL_NO_ERROR();
2287
2288 glClearBufferfv(GL_COLOR, 0, clearFloat);
2289 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2290
2291 glClearBufferiv(GL_COLOR, 0, clearInt);
2292 EXPECT_GL_NO_ERROR();
2293
2294 glClearBufferuiv(GL_COLOR, 0, clearUint);
2295 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2296
2297 glClear(GL_COLOR_BUFFER_BIT);
2298 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2299
2300 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002301 if (extensionRequestable("GL_EXT_color_buffer_float"))
2302 {
2303 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2304 }
Geoff Lang76e65652017-03-27 14:58:02 -04002305
Geoff Lang677bb6f2017-04-05 12:40:40 -04002306 if (extensionEnabled("GL_EXT_color_buffer_float"))
2307 {
2308 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2309 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002310
Geoff Lang677bb6f2017-04-05 12:40:40 -04002311 glClearBufferfv(GL_COLOR, 0, clearFloat);
2312 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002313
Geoff Lang677bb6f2017-04-05 12:40:40 -04002314 glClearBufferiv(GL_COLOR, 0, clearInt);
2315 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002316
Geoff Lang677bb6f2017-04-05 12:40:40 -04002317 glClearBufferuiv(GL_COLOR, 0, clearUint);
2318 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2319
2320 glClear(GL_COLOR_BUFFER_BIT);
2321 EXPECT_GL_NO_ERROR();
2322 }
Geoff Lang76e65652017-03-27 14:58:02 -04002323
2324 // Normalized uint buffer
2325 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2326 ASSERT_GL_NO_ERROR();
2327
2328 glClearBufferfv(GL_COLOR, 0, clearFloat);
2329 EXPECT_GL_NO_ERROR();
2330
2331 glClearBufferiv(GL_COLOR, 0, clearInt);
2332 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2333
2334 glClearBufferuiv(GL_COLOR, 0, clearUint);
2335 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2336
2337 glClear(GL_COLOR_BUFFER_BIT);
2338 EXPECT_GL_NO_ERROR();
2339}
2340
Geoff Lange4915782017-04-12 15:19:07 -04002341// Verify that errors are generate when trying to blit from an image to itself
2342TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2343{
2344 GLTexture textures[2];
2345 glBindTexture(GL_TEXTURE_2D, textures[0]);
2346 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2347 glBindTexture(GL_TEXTURE_2D, textures[1]);
2348 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2349
2350 GLRenderbuffer renderbuffers[2];
2351 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2352 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2353 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2354 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2355
2356 GLFramebuffer framebuffers[2];
2357 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2358 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2359
2360 ASSERT_GL_NO_ERROR();
2361
2362 // Same texture
2363 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2364 0);
2365 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2366 0);
2367 ASSERT_GL_NO_ERROR();
2368 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2369 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2370
2371 // Same textures but different renderbuffers
2372 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2373 renderbuffers[0]);
2374 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2375 renderbuffers[1]);
2376 ASSERT_GL_NO_ERROR();
2377 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2378 ASSERT_GL_NO_ERROR();
2379 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2380 GL_NEAREST);
2381 ASSERT_GL_NO_ERROR();
2382 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2383 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2384 GL_NEAREST);
2385 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2386
2387 // Same renderbuffers but different textures
2388 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2389 0);
2390 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2391 0);
2392 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2393 renderbuffers[0]);
2394 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2395 renderbuffers[0]);
2396 ASSERT_GL_NO_ERROR();
2397 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2398 ASSERT_GL_NO_ERROR();
2399 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2400 GL_NEAREST);
2401 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2402 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2403 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2404 GL_NEAREST);
2405 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2406}
2407
Geoff Lange0cff192017-05-30 13:04:56 -04002408// Verify that errors are generated when the fragment shader output doesn't match the bound color
2409// buffer types
2410TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch)
2411{
2412 const std::string vertexShader =
2413 "#version 300 es\n"
2414 "void main() {\n"
2415 " gl_Position = vec4(0, 0, 0, 1);\n"
2416 "}\n";
2417
2418 const std::string fragmentShader =
2419 "#version 300 es\n"
2420 "precision mediump float;\n"
2421 "layout(location = 0) out vec4 floatOutput;\n"
2422 "layout(location = 1) out uvec4 uintOutput;\n"
2423 "layout(location = 2) out ivec4 intOutput;\n"
2424 "void main() {\n"
2425 " floatOutput = vec4(0, 0, 0, 1);\n"
2426 " uintOutput = uvec4(0, 0, 0, 1);\n"
2427 " intOutput = ivec4(0, 0, 0, 1);\n"
2428 "}\n";
2429
2430 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2431 glUseProgram(program.get());
2432
2433 GLuint floatLocation = glGetFragDataLocation(program, "floatOutput");
2434 GLuint uintLocation = glGetFragDataLocation(program, "uintOutput");
2435 GLuint intLocation = glGetFragDataLocation(program, "intOutput");
2436
2437 GLFramebuffer fbo;
2438 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2439
2440 GLRenderbuffer floatRenderbuffer;
2441 glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer);
2442 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2443 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2444 floatRenderbuffer);
2445
2446 GLRenderbuffer uintRenderbuffer;
2447 glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer);
2448 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1);
2449 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2450 uintRenderbuffer);
2451
2452 GLRenderbuffer intRenderbuffer;
2453 glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer);
2454 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1);
2455 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2456 intRenderbuffer);
2457
2458 ASSERT_GL_NO_ERROR();
2459
2460 GLint maxDrawBuffers = 0;
2461 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2462 std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE);
2463 drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation;
2464 drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation;
2465 drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation;
2466
2467 glDrawBuffers(maxDrawBuffers, drawBuffers.data());
2468
2469 // Check that the correct case generates no errors
2470 glDrawArrays(GL_TRIANGLES, 0, 6);
2471 EXPECT_GL_NO_ERROR();
2472
2473 // Unbind some buffers and verify that there are still no errors
2474 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2475 0);
2476 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2477 0);
2478 glDrawArrays(GL_TRIANGLES, 0, 6);
2479 EXPECT_GL_NO_ERROR();
2480
2481 // Swap the int and uint buffers to and verify that an error is generated
2482 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2483 intRenderbuffer);
2484 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2485 uintRenderbuffer);
2486 glDrawArrays(GL_TRIANGLES, 0, 6);
2487 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2488
2489 // Swap the float and uint buffers to and verify that an error is generated
2490 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER,
2491 floatRenderbuffer);
2492 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER,
2493 uintRenderbuffer);
2494 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER,
2495 intRenderbuffer);
2496 glDrawArrays(GL_TRIANGLES, 0, 6);
2497 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2498}
2499
Geoff Lang9ab5b822017-05-30 16:19:23 -04002500// Verify that errors are generated when the vertex shader intput doesn't match the bound attribute
2501// types
2502TEST_P(WebGL2CompatibilityTest, VertexShaderAttributeTypeMissmatch)
2503{
2504 const std::string vertexShader =
2505 "#version 300 es\n"
2506 "in vec4 floatInput;\n"
2507 "in uvec4 uintInput;\n"
2508 "in ivec4 intInput;\n"
2509 "void main() {\n"
2510 " gl_Position = vec4(floatInput.x, uintInput.x, intInput.x, 1);\n"
2511 "}\n";
2512
2513 const std::string fragmentShader =
2514 "#version 300 es\n"
2515 "precision mediump float;\n"
2516 "out vec4 outputColor;\n"
2517 "void main() {\n"
2518 " outputColor = vec4(0, 0, 0, 1);"
2519 "}\n";
2520
2521 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2522 glUseProgram(program.get());
2523
2524 GLint floatLocation = glGetAttribLocation(program, "floatInput");
2525 GLint uintLocation = glGetAttribLocation(program, "uintInput");
2526 GLint intLocation = glGetAttribLocation(program, "intInput");
2527
2528 // Default attributes are of float types
2529 glDrawArrays(GL_TRIANGLES, 0, 6);
2530 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2531
2532 // Set the default attributes to the correct types, should succeed
2533 glVertexAttribI4ui(uintLocation, 0, 0, 0, 1);
2534 glVertexAttribI4i(intLocation, 0, 0, 0, 1);
2535 glDrawArrays(GL_TRIANGLES, 0, 6);
2536 EXPECT_GL_NO_ERROR();
2537
2538 // Change the default float attribute to an integer, should fail
2539 glVertexAttribI4ui(floatLocation, 0, 0, 0, 1);
2540 glDrawArrays(GL_TRIANGLES, 0, 6);
2541 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2542
2543 // Use a buffer for some attributes
2544 GLBuffer buffer;
2545 glBindBuffer(GL_ARRAY_BUFFER, buffer);
2546 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
2547 glEnableVertexAttribArray(floatLocation);
2548 glVertexAttribPointer(floatLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2549 glDrawArrays(GL_TRIANGLES, 0, 6);
2550 EXPECT_GL_NO_ERROR();
2551
2552 // Use a float pointer attrib for a uint input
2553 glEnableVertexAttribArray(uintLocation);
2554 glVertexAttribPointer(uintLocation, 4, GL_FLOAT, GL_FALSE, 0, nullptr);
2555 glDrawArrays(GL_TRIANGLES, 0, 6);
2556 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2557
2558 // Use a uint pointer for the uint input
2559 glVertexAttribIPointer(uintLocation, 4, GL_UNSIGNED_INT, 0, nullptr);
2560 glDrawArrays(GL_TRIANGLES, 0, 6);
2561 EXPECT_GL_NO_ERROR();
2562}
2563
Corentin Walleze7557742017-06-01 13:09:57 -04002564// Tests the WebGL removal of undefined behavior when attachments aren't written to.
2565TEST_P(WebGLCompatibilityTest, DrawBuffers)
2566{
2567 if (IsD3D9() || IsD3D11())
2568 {
2569 std::cout << "Test skipped on " << GetParam() << std::endl;
2570 return;
2571 }
2572
2573 // Make sure we can use at least 4 attachments for the tests.
2574 bool useEXT = false;
2575 if (getClientMajorVersion() < 3)
2576 {
2577 if (!extensionRequestable("GL_EXT_draw_buffers"))
2578 {
2579 std::cout << "Test skipped because draw buffers are not available" << std::endl;
2580 return;
2581 }
2582
2583 glRequestExtensionANGLE("GL_EXT_draw_buffers");
2584 useEXT = true;
2585 EXPECT_GL_NO_ERROR();
2586 }
2587
2588 GLint maxDrawBuffers = 0;
2589 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
2590 if (maxDrawBuffers < 4)
2591 {
2592 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
2593 return;
2594 }
2595
2596 // Clears all the renderbuffers to red.
2597 auto ClearEverythingToRed = [](GLRenderbuffer *renderbuffers) {
2598 GLFramebuffer clearFBO;
2599 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, clearFBO);
2600
2601 glClearColor(1, 0, 0, 1);
2602 for (int i = 0; i < 4; ++i)
2603 {
2604 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2605 renderbuffers[i]);
2606 glClear(GL_COLOR_BUFFER_BIT);
2607 }
2608 ASSERT_GL_NO_ERROR();
2609 };
2610
2611 // Checks that the renderbuffers specified by mask have the correct color
2612 auto CheckColors = [](GLRenderbuffer *renderbuffers, int mask, GLColor color) {
2613 GLFramebuffer readFBO;
2614 glBindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
2615
2616 for (int i = 0; i < 4; ++i)
2617 {
2618 if (mask & (1 << i))
2619 {
2620 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2621 GL_RENDERBUFFER, renderbuffers[i]);
2622 EXPECT_PIXEL_COLOR_EQ(0, 0, color);
2623 }
2624 }
2625 ASSERT_GL_NO_ERROR();
2626 };
2627
2628 // Depending on whether we are using the extension or ES3, a different entrypoint must be called
2629 auto DrawBuffers = [](bool useEXT, int numBuffers, GLenum *buffers) {
2630 if (useEXT)
2631 {
2632 glDrawBuffersEXT(numBuffers, buffers);
2633 }
2634 else
2635 {
2636 glDrawBuffers(numBuffers, buffers);
2637 }
2638 };
2639
2640 // Initialized the test framebuffer
2641 GLFramebuffer drawFBO;
2642 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2643
2644 GLRenderbuffer renderbuffers[4];
2645 for (int i = 0; i < 4; ++i)
2646 {
2647 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[i]);
2648 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1);
2649 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_RENDERBUFFER,
2650 renderbuffers[i]);
2651 }
2652
2653 ASSERT_GL_NO_ERROR();
2654
2655 const char *vertESSL1 =
2656 "attribute vec4 a_pos;\n"
2657 "void main()\n"
2658 "{\n"
2659 " gl_Position = a_pos;\n"
2660 "}\n";
2661 const char *vertESSL3 =
2662 "#version 300 es\n"
2663 "in vec4 a_pos;\n"
2664 "void main()\n"
2665 "{\n"
2666 " gl_Position = a_pos;\n"
2667 "}\n";
2668
2669 GLenum allDrawBuffers[] = {
2670 GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2671 };
2672
2673 GLenum halfDrawBuffers[] = {
2674 GL_NONE, GL_NONE, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3,
2675 };
2676
2677 // Test that when using gl_FragColor, only the first attachment is written to.
2678 const char *fragESSL1 =
2679 "precision highp float;\n"
2680 "void main()\n"
2681 "{\n"
2682 " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
2683 "}\n";
2684 ANGLE_GL_PROGRAM(programESSL1, vertESSL1, fragESSL1);
2685
2686 {
2687 ClearEverythingToRed(renderbuffers);
2688
2689 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2690 DrawBuffers(useEXT, 4, allDrawBuffers);
2691 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2692 ASSERT_GL_NO_ERROR();
2693
2694 CheckColors(renderbuffers, 0b0001, GLColor::green);
2695 CheckColors(renderbuffers, 0b1110, GLColor::red);
2696 }
2697
2698 // Test that when using gl_FragColor, but the first draw buffer is 0, then no attachment is
2699 // written to.
2700 {
2701 ClearEverythingToRed(renderbuffers);
2702
2703 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2704 DrawBuffers(useEXT, 4, halfDrawBuffers);
2705 drawQuad(programESSL1, "a_pos", 0.5, 1.0, true);
2706 ASSERT_GL_NO_ERROR();
2707
2708 CheckColors(renderbuffers, 0b1111, GLColor::red);
2709 }
2710
2711 // Test what happens when rendering to a subset of the outputs. There is a behavior difference
2712 // between the extension and ES3. In the extension gl_FragData is implicitly declared as an
2713 // array of size MAX_DRAW_BUFFERS, so the WebGL spec stipulates that elements not written to
2714 // should default to 0. On the contrary, in ES3 outputs are specified one by one, so
2715 // attachments not declared in the shader should not be written to.
2716 const char *writeOddOutputsVert;
2717 const char *writeOddOutputsFrag;
2718 GLColor unwrittenColor;
2719 if (useEXT)
2720 {
2721 // In the extension, when an attachment isn't written to, it should get 0's
2722 unwrittenColor = GLColor(0, 0, 0, 0);
2723 writeOddOutputsVert = vertESSL1;
2724 writeOddOutputsFrag =
2725 "#extension GL_EXT_draw_buffers : require\n"
2726 "precision highp float;\n"
2727 "void main()\n"
2728 "{\n"
2729 " gl_FragData[1] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2730 " gl_FragData[3] = vec4(0.0, 1.0, 0.0, 1.0);\n"
2731 "}\n";
2732 }
2733 else
2734 {
2735 // In ES3 if an attachment isn't declared, it shouldn't get written and should be red
2736 // because of the preceding clears.
2737 unwrittenColor = GLColor::red;
2738 writeOddOutputsVert = vertESSL3;
2739 writeOddOutputsFrag =
2740 "#version 300 es\n"
2741 "precision highp float;\n"
2742 "layout(location = 1) out vec4 output1;"
2743 "layout(location = 3) out vec4 output2;"
2744 "void main()\n"
2745 "{\n"
2746 " output1 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2747 " output2 = vec4(0.0, 1.0, 0.0, 1.0);\n"
2748 "}\n";
2749 }
2750 ANGLE_GL_PROGRAM(writeOddOutputsProgram, writeOddOutputsVert, writeOddOutputsFrag);
2751
2752 // Test that attachments not written to get the "unwritten" color
2753 {
2754 ClearEverythingToRed(renderbuffers);
2755
2756 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2757 DrawBuffers(useEXT, 4, allDrawBuffers);
2758 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2759 ASSERT_GL_NO_ERROR();
2760
2761 CheckColors(renderbuffers, 0b1010, GLColor::green);
2762 CheckColors(renderbuffers, 0b0101, unwrittenColor);
2763 }
2764
2765 // Test that attachments not written to get the "unwritten" color but that even when the
2766 // extension is used, disabled attachments are not written at all and stay red.
2767 {
2768 ClearEverythingToRed(renderbuffers);
2769
2770 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, drawFBO);
2771 DrawBuffers(useEXT, 4, halfDrawBuffers);
2772 drawQuad(writeOddOutputsProgram, "a_pos", 0.5, 1.0, true);
2773 ASSERT_GL_NO_ERROR();
2774
2775 CheckColors(renderbuffers, 0b1000, GLColor::green);
2776 CheckColors(renderbuffers, 0b0100, unwrittenColor);
2777 CheckColors(renderbuffers, 0b0011, GLColor::red);
2778 }
2779}
2780
Geoff Langc287ea62016-09-16 14:46:51 -04002781// Use this to select which configurations (e.g. which renderer, which GLES major version) these
2782// tests should be run against.
2783ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
2784 ES2_D3D9(),
2785 ES2_D3D11(),
2786 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04002787 ES2_OPENGL(),
2788 ES3_OPENGL(),
2789 ES2_OPENGLES(),
2790 ES3_OPENGLES());
2791
Jamie Madill07be8bf2017-02-02 19:59:57 -05002792ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04002793} // namespace