blob: c281f176fcb94c99436314e3e6e175eb3833c5e7 [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
Corentin Wallezfd456442016-12-21 17:57:00 -0500840// Test the checks for OOB reads in the vertex buffers, instanced version
841TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced)
842{
843 const std::string &vert =
844 "attribute float a_pos;\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400845 "attribute float a_w;\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500846 "void main()\n"
847 "{\n"
Geoff Lang407d4e72017-04-12 14:54:11 -0400848 " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n"
Corentin Wallezfd456442016-12-21 17:57:00 -0500849 "}\n";
850
851 const std::string &frag =
852 "precision highp float;\n"
853 "void main()\n"
854 "{\n"
855 " gl_FragColor = vec4(1.0);\n"
856 "}\n";
857
858 ANGLE_GL_PROGRAM(program, vert, frag);
859
860 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
861 ASSERT_NE(-1, posLocation);
Geoff Lang407d4e72017-04-12 14:54:11 -0400862
863 GLint wLocation = glGetAttribLocation(program.get(), "a_w");
864 ASSERT_NE(-1, wLocation);
865
Corentin Wallezfd456442016-12-21 17:57:00 -0500866 glUseProgram(program.get());
867
868 GLBuffer buffer;
869 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
870 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
871
872 glEnableVertexAttribArray(posLocation);
873 glVertexAttribDivisor(posLocation, 1);
874
Geoff Lang407d4e72017-04-12 14:54:11 -0400875 glEnableVertexAttribArray(wLocation);
876 glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0);
877 glVertexAttribDivisor(wLocation, 0);
878
Corentin Wallezfd456442016-12-21 17:57:00 -0500879 const uint8_t* zeroOffset = nullptr;
880
881 // Test touching the last element is valid.
882 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12);
883 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
884 ASSERT_GL_NO_ERROR();
885
886 // Test touching the last element + 1 is invalid.
887 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13);
888 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
889 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
890
891 // Test touching the last element is valid, using a stride.
892 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9);
893 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
894 ASSERT_GL_NO_ERROR();
895
896 // Test touching the last element + 1 is invalid, using a stride.
897 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10);
898 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
899 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
900
901 // Test any offset is valid if no vertices are drawn.
902 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32);
903 glDrawArraysInstanced(GL_POINTS, 0, 1, 0);
904 ASSERT_GL_NO_ERROR();
905}
906
Geoff Lang407d4e72017-04-12 14:54:11 -0400907// Test that at least one attribute has a zero divisor for WebGL
908TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor)
909{
910 const std::string &vert =
911 "attribute float a_pos;\n"
912 "void main()\n"
913 "{\n"
914 " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n"
915 "}\n";
916
917 const std::string &frag =
918 "precision highp float;\n"
919 "void main()\n"
920 "{\n"
921 " gl_FragColor = vec4(1.0);\n"
922 "}\n";
923
924 ANGLE_GL_PROGRAM(program, vert, frag);
925
926 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
927 ASSERT_NE(-1, posLocation);
928
929 glUseProgram(program.get());
930
931 GLBuffer buffer;
932 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
933 glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW);
934
935 glEnableVertexAttribArray(posLocation);
936 glVertexAttribDivisor(posLocation, 1);
937
938 // Test touching the last element is valid.
939 glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr);
940 glDrawArraysInstanced(GL_POINTS, 0, 1, 4);
941 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
942
943 glVertexAttribDivisor(posLocation, 0);
944 ASSERT_GL_NO_ERROR();
945}
946
Corentin Wallez0844f2d2017-01-31 17:02:59 -0500947// Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled
948TEST_P(WebGLCompatibilityTest, NPOT)
949{
950 EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot"));
951
952 // Create a texture and set an NPOT mip 0, should always be acceptable.
953 GLTexture texture;
954 glBindTexture(GL_TEXTURE_2D, texture.get());
955 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
956 ASSERT_GL_NO_ERROR();
957
958 // Try setting an NPOT mip 1 and verify the error if WebGL 1
959 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
960 if (getClientMajorVersion() < 3)
961 {
962 ASSERT_GL_ERROR(GL_INVALID_VALUE);
963 }
964 else
965 {
966 ASSERT_GL_NO_ERROR();
967 }
968
969 if (extensionRequestable("GL_OES_texture_npot"))
970 {
971 glRequestExtensionANGLE("GL_OES_texture_npot");
972 ASSERT_GL_NO_ERROR();
973
974 // Try again to set NPOT mip 1
975 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
976 ASSERT_GL_NO_ERROR();
977 }
978}
979
Jamie Madillcad97ee2017-02-02 18:52:44 -0500980template <typename T>
981void FillTexture2D(GLuint texture,
982 GLsizei width,
983 GLsizei height,
984 const T &onePixelData,
985 GLint level,
986 GLint internalFormat,
987 GLenum format,
988 GLenum type)
989{
990 std::vector<T> allPixelsData(width * height, onePixelData);
991
992 glBindTexture(GL_TEXTURE_2D, texture);
993 glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type,
994 allPixelsData.data());
995 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
996 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
997 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
998 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
999}
1000
Frank Henigman875bbba2017-02-08 16:38:17 -05001001// Test that unset gl_Position defaults to (0,0,0,0).
1002TEST_P(WebGLCompatibilityTest, DefaultPosition)
1003{
1004 // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set,
1005 // and green otherwise. The center of each quadrant will be red if and only if all
1006 // four corners are red.
1007 const std::string vertexShader =
1008 "attribute vec3 pos;\n"
1009 "varying vec4 color;\n"
1010 "void main() {\n"
1011 " if (gl_Position == vec4(0,0,0,0)) {\n"
1012 " color = vec4(1,0,0,1);\n"
1013 " } else {\n"
1014 " color = vec4(0,1,0,1);\n"
1015 " }\n"
1016 " gl_Position = vec4(pos,1);\n"
1017 "}\n";
1018
1019 const std::string fragmentShader =
1020 "precision mediump float;\n"
1021 "varying vec4 color;\n"
1022 "void main() {\n"
1023 " gl_FragColor = color;\n"
1024 "}\n";
1025
1026 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1027 drawQuad(program.get(), "pos", 0.0f, 1.0f, true);
1028 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1029 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1030 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red);
1031 EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red);
1032}
1033
Jamie Madilla4595b82017-01-11 17:36:34 -05001034// Tests that a rendering feedback loop triggers a GL error under WebGL.
1035// Based on WebGL test conformance/renderbuffers/feedback-loop.html.
1036TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop)
1037{
1038 const std::string vertexShader =
1039 "attribute vec4 a_position;\n"
1040 "varying vec2 v_texCoord;\n"
1041 "void main() {\n"
1042 " gl_Position = a_position;\n"
1043 " v_texCoord = (a_position.xy * 0.5) + 0.5;\n"
1044 "}\n";
1045
1046 const std::string fragmentShader =
1047 "precision mediump float;\n"
1048 "varying vec2 v_texCoord;\n"
1049 "uniform sampler2D u_texture;\n"
1050 "void main() {\n"
1051 " // Shader swizzles color channels so we can tell if the draw succeeded.\n"
1052 " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n"
1053 "}\n";
1054
1055 GLTexture texture;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001056 FillTexture2D(texture.get(), 1, 1, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001057
1058 ASSERT_GL_NO_ERROR();
1059
1060 GLFramebuffer framebuffer;
1061 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1062 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1063
1064 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1065
1066 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1067
1068 GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture");
1069 ASSERT_NE(-1, uniformLoc);
1070
1071 glUseProgram(program.get());
1072 glUniform1i(uniformLoc, 0);
1073 glDisable(GL_BLEND);
1074 glDisable(GL_DEPTH_TEST);
1075 ASSERT_GL_NO_ERROR();
1076
1077 // Drawing with a texture that is also bound to the current framebuffer should fail
1078 glBindTexture(GL_TEXTURE_2D, texture.get());
1079 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1080 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1081
1082 // Ensure that the texture contents did not change after the previous render
1083 glBindFramebuffer(GL_FRAMEBUFFER, 0);
1084 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1085 ASSERT_GL_NO_ERROR();
1086 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
1087
1088 // Drawing when texture is bound to an inactive uniform should succeed
1089 GLTexture texture2;
Jamie Madillcad97ee2017-02-02 18:52:44 -05001090 FillTexture2D(texture2.get(), 1, 1, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
Jamie Madilla4595b82017-01-11 17:36:34 -05001091
1092 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1093 glActiveTexture(GL_TEXTURE1);
1094 glBindTexture(GL_TEXTURE_2D, texture.get());
1095 drawQuad(program.get(), "a_position", 0.5f, 1.0f, true);
1096 ASSERT_GL_NO_ERROR();
1097 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
1098}
1099
Bryan Bernhart58806562017-01-05 13:09:31 -08001100// Test for the max draw buffers and color attachments.
1101TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints)
1102{
1103 // This test only applies to ES2.
1104 if (getClientMajorVersion() != 2)
1105 {
1106 return;
1107 }
1108
1109 GLFramebuffer fbo[2];
1110 glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get());
1111
1112 // Test that is valid when we bind with a single attachment point.
1113 GLTexture texture;
1114 glBindTexture(GL_TEXTURE_2D, texture.get());
1115 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1116 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1117 ASSERT_GL_NO_ERROR();
1118
1119 // Test that enabling the draw buffers extension will allow us to bind with a non-zero
1120 // attachment point.
1121 if (extensionRequestable("GL_EXT_draw_buffers"))
1122 {
1123 glRequestExtensionANGLE("GL_EXT_draw_buffers");
1124 EXPECT_GL_NO_ERROR();
1125 EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers"));
1126
1127 glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get());
1128
1129 GLTexture texture2;
1130 glBindTexture(GL_TEXTURE_2D, texture2.get());
1131 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1132 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(),
1133 0);
1134 ASSERT_GL_NO_ERROR();
1135 }
1136}
1137
Corentin Wallez3f6d4df2017-01-30 18:04:36 -05001138// Test that the offset in the index buffer is forced to be a multiple of the element size
1139TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction)
1140{
1141 const std::string &vert =
1142 "attribute vec3 a_pos;\n"
1143 "void main()\n"
1144 "{\n"
1145 " gl_Position = vec4(a_pos, 1.0);\n"
1146 "}\n";
1147
1148 const std::string &frag =
1149 "precision highp float;\n"
1150 "void main()\n"
1151 "{\n"
1152 " gl_FragColor = vec4(1.0);\n"
1153 "}\n";
1154
1155 ANGLE_GL_PROGRAM(program, vert, frag);
1156
1157 GLint posLocation = glGetAttribLocation(program.get(), "a_pos");
1158 ASSERT_NE(-1, posLocation);
1159 glUseProgram(program.get());
1160
1161 const auto &vertices = GetQuadVertices();
1162
1163 GLBuffer vertexBuffer;
1164 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
1165 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
1166 GL_STATIC_DRAW);
1167
1168 glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
1169 glEnableVertexAttribArray(posLocation);
1170
1171 GLBuffer indexBuffer;
1172 const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0};
1173 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get());
1174 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
1175
1176 ASSERT_GL_NO_ERROR();
1177
1178 const char *zeroIndices = nullptr;
1179
1180 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices);
1181 ASSERT_GL_NO_ERROR();
1182
1183 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices);
1184 ASSERT_GL_NO_ERROR();
1185
1186 glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1);
1187 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1188}
1189
1190// Test that the offset and stride in the vertex buffer is forced to be a multiple of the element
1191// size
1192TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction)
1193{
1194 const char *zeroOffset = nullptr;
1195
1196 // Base case, vector of two floats
1197 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset);
1198 ASSERT_GL_NO_ERROR();
1199
1200 // Test setting a non-multiple offset
1201 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1);
1202 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1203 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2);
1204 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1205 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3);
1206 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1207
1208 // Test setting a non-multiple stride
1209 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset);
1210 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1211 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset);
1212 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1213 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset);
1214 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1215}
1216
Jamie Madillcad97ee2017-02-02 18:52:44 -05001217void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program,
1218 const std::array<GLenum, 2> &drawBuffers,
1219 GLenum expectedError)
1220{
1221 glDrawBuffersEXT(2, drawBuffers.data());
1222
1223 // Make sure framebuffer is complete before feedback loop detection
1224 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1225
1226 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1227
1228 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1229 // it should be NO_ERROR"
1230 EXPECT_GL_ERROR(expectedError);
1231}
1232
1233// This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers.
1234// Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html
1235TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT)
1236{
1237 const std::string vertexShader =
1238 "attribute vec4 aPosition;\n"
1239 "varying vec2 texCoord;\n"
1240 "void main() {\n"
1241 " gl_Position = aPosition;\n"
1242 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1243 "}\n";
1244
1245 const std::string fragmentShader =
1246 "#extension GL_EXT_draw_buffers : require\n"
1247 "precision mediump float;\n"
1248 "uniform sampler2D tex;\n"
1249 "varying vec2 texCoord;\n"
1250 "void main() {\n"
1251 " gl_FragData[0] = texture2D(tex, texCoord);\n"
1252 " gl_FragData[1] = texture2D(tex, texCoord);\n"
1253 "}\n";
1254
1255 GLsizei width = 8;
1256 GLsizei height = 8;
1257
1258 // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers
1259 // extension and gl_FragData semantics are changed to enforce indexing by zero always.
1260 // TODO(jmadill): This extension should be disabled in WebGL 2 contexts.
1261 if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2)
1262 {
1263 // No WEBGL_draw_buffers support -- this is legal.
1264 return;
1265 }
1266
1267 GLint maxDrawBuffers = 0;
1268 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1269
1270 if (maxDrawBuffers < 2)
1271 {
1272 std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl;
1273 return;
1274 }
1275
1276 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1277 glUseProgram(program.get());
1278 glViewport(0, 0, width, height);
1279
1280 GLTexture tex0;
1281 GLTexture tex1;
1282 GLFramebuffer fbo;
1283 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1284 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1285 ASSERT_GL_NO_ERROR();
1286
1287 glBindTexture(GL_TEXTURE_2D, tex1.get());
1288 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1289 ASSERT_NE(-1, texLoc);
1290 glUniform1i(texLoc, 0);
1291 ASSERT_GL_NO_ERROR();
1292
1293 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1294 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1295 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1296 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1297
1298 drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}},
1299 GL_INVALID_OPERATION);
1300 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1301 GL_INVALID_OPERATION);
1302 drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
1303}
1304
Jamie Madill07be8bf2017-02-02 19:59:57 -05001305// Test tests that texture copying feedback loops are properly rejected in WebGL.
1306// Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html
1307TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops)
1308{
1309 GLTexture texture;
1310 glBindTexture(GL_TEXTURE_2D, texture.get());
1311 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1312 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1313 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1314 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1315 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1316
1317 GLTexture texture2;
1318 glBindTexture(GL_TEXTURE_2D, texture2.get());
1319 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1320 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1323 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1324
1325 GLFramebuffer framebuffer;
1326 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
1327 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
1328
1329 // framebuffer should be FRAMEBUFFER_COMPLETE.
1330 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1331 ASSERT_GL_NO_ERROR();
1332
1333 // testing copyTexImage2D
1334
1335 // copyTexImage2D to same texture but different level
1336 glBindTexture(GL_TEXTURE_2D, texture.get());
1337 glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0);
1338 EXPECT_GL_NO_ERROR();
1339
1340 // copyTexImage2D to same texture same level, invalid feedback loop
1341 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1342 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1343
1344 // copyTexImage2D to different texture
1345 glBindTexture(GL_TEXTURE_2D, texture2.get());
1346 glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0);
1347 EXPECT_GL_NO_ERROR();
1348
1349 // testing copyTexSubImage2D
1350
1351 // copyTexSubImage2D to same texture but different level
1352 glBindTexture(GL_TEXTURE_2D, texture.get());
1353 glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1);
1354 EXPECT_GL_NO_ERROR();
1355
1356 // copyTexSubImage2D to same texture same level, invalid feedback loop
1357 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1358 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
1359
1360 // copyTexSubImage2D to different texture
1361 glBindTexture(GL_TEXTURE_2D, texture2.get());
1362 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1363 EXPECT_GL_NO_ERROR();
1364}
1365
1366void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program,
1367 const std::array<GLenum, 2> &drawBuffers,
1368 GLenum expectedError)
1369{
1370 glDrawBuffers(2, drawBuffers.data());
1371
1372 // Make sure framebuffer is complete before feedback loop detection
1373 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
1374
1375 drawQuad(program, "aPosition", 0.5f, 1.0f, true);
1376
1377 // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise,
1378 // it should be NO_ERROR"
1379 EXPECT_GL_ERROR(expectedError);
1380}
1381
Yuly Novikov817232e2017-02-22 18:36:10 -05001382// Tests invariance matching rules between built in varyings.
1383// Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html.
1384TEST_P(WebGLCompatibilityTest, BuiltInInvariant)
1385{
1386 const std::string vertexShaderVariant =
1387 "varying vec4 v_varying;\n"
1388 "void main()\n"
1389 "{\n"
1390 " gl_PointSize = 1.0;\n"
1391 " gl_Position = v_varying;\n"
1392 "}";
1393 const std::string fragmentShaderInvariantGlFragCoord =
1394 "invariant gl_FragCoord;\n"
1395 "void main()\n"
1396 "{\n"
1397 " gl_FragColor = gl_FragCoord;\n"
1398 "}";
1399 const std::string fragmentShaderInvariantGlPointCoord =
1400 "invariant gl_PointCoord;\n"
1401 "void main()\n"
1402 "{\n"
1403 " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n"
1404 "}";
1405
1406 GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord);
1407 EXPECT_EQ(0u, program);
1408
1409 program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord);
1410 EXPECT_EQ(0u, program);
1411}
1412
Geoff Lang966c9402017-04-18 12:38:27 -04001413// Test dimension and image size validation of compressed textures
1414TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC)
1415{
1416 if (extensionRequestable("GL_EXT_texture_compression_dxt1"))
1417 {
1418 glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1");
1419 }
1420
1421 if (!extensionEnabled("GL_EXT_texture_compression_dxt1"))
1422 {
1423 std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available."
1424 << std::endl;
1425 return;
1426 }
1427
1428 constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa};
1429
1430 GLTexture texture;
1431 glBindTexture(GL_TEXTURE_2D, texture);
1432
1433 // Regular case, verify that it works
1434 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1435 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1436 ASSERT_GL_NO_ERROR();
1437
1438 // Test various dimensions that are not valid
1439 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0,
1440 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1441 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1442
1443 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0,
1444 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1445 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1446
1447 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1448 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1449 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1450
1451 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1452 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1453 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1454
1455 // Test various image sizes that are not valid
1456 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1457 sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1);
1458 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1459
1460 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1461 sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1);
1462 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1463
1464 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0,
1465 CompressedImageDXT1);
1466 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1467
1468 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0,
1469 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1470 ASSERT_GL_ERROR(GL_INVALID_VALUE);
1471
1472 // Fill a full mip chain and verify that it works
1473 glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
1474 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1475 glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0,
1476 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1477 glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0,
1478 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1479 ASSERT_GL_NO_ERROR();
1480
1481 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1482 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1483 ASSERT_GL_NO_ERROR();
1484
1485 // Test that non-block size sub-uploads are not valid for the 0 mip
1486 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1487 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1488 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1489
1490 // Test that non-block size sub-uploads are valid for if they fill the whole mip
1491 glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1492 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1493 glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1494 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1495 ASSERT_GL_NO_ERROR();
1496
1497 // Test that if the format miss-matches the texture, an error is generated
1498 glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1499 sizeof(CompressedImageDXT1), CompressedImageDXT1);
1500 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
1501}
1502
Geoff Lang677bb6f2017-04-05 12:40:40 -04001503TEST_P(WebGLCompatibilityTest, L32FTextures)
1504{
1505 constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f};
1506 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f};
1507
1508 for (auto extension : FloatingPointTextureExtensions)
1509 {
1510 if (strlen(extension) > 0 && extensionRequestable(extension))
1511 {
1512 glRequestExtensionANGLE(extension);
1513 ASSERT_GL_NO_ERROR();
1514 }
1515
1516 // Unsized L 32F
1517 {
1518 bool texture = extensionEnabled("GL_OES_texture_float");
1519 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1520 bool render = false;
1521 TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render,
1522 textureData, readPixelData);
1523 }
1524
1525 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1526 {
1527 // Sized L 32F
1528 bool texture = extensionEnabled("GL_OES_texture_float") &&
1529 extensionEnabled("GL_EXT_texture_storage");
1530 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1531 bool render = false;
1532 TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter,
1533 render, textureData, readPixelData);
1534 }
1535 }
1536}
1537
1538TEST_P(WebGLCompatibilityTest, A32FTextures)
1539{
1540 constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f};
1541 constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]};
1542
1543 for (auto extension : FloatingPointTextureExtensions)
1544 {
1545 if (strlen(extension) > 0 && extensionRequestable(extension))
1546 {
1547 glRequestExtensionANGLE(extension);
1548 ASSERT_GL_NO_ERROR();
1549 }
1550
1551 // Unsized A 32F
1552 {
1553 bool texture = extensionEnabled("GL_OES_texture_float");
1554 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1555 bool render = false;
1556 TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render,
1557 textureData, readPixelData);
1558 }
1559
1560 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1561 {
1562 // Sized A 32F
1563 bool texture = extensionEnabled("GL_OES_texture_float") &&
1564 extensionEnabled("GL_EXT_texture_storage");
1565 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1566 bool render = false;
1567 TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render,
1568 textureData, readPixelData);
1569 }
1570 }
1571}
1572
1573TEST_P(WebGLCompatibilityTest, LA32FTextures)
1574{
1575 constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f};
1576 constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0],
1577 textureData[1]};
1578
1579 for (auto extension : FloatingPointTextureExtensions)
1580 {
1581 if (strlen(extension) > 0 && extensionRequestable(extension))
1582 {
1583 glRequestExtensionANGLE(extension);
1584 ASSERT_GL_NO_ERROR();
1585 }
1586
1587 // Unsized LA 32F
1588 {
1589 bool texture = extensionEnabled("GL_OES_texture_float");
1590 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1591 bool render = false;
1592 TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1593 filter, render, textureData, readPixelData);
1594 }
1595
1596 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1597 {
1598 // Sized LA 32F
1599 bool texture = extensionEnabled("GL_OES_texture_float") &&
1600 extensionEnabled("GL_EXT_texture_storage");
1601 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1602 bool render = false;
1603 TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture,
1604 filter, render, textureData, readPixelData);
1605 }
1606 }
1607}
1608
1609TEST_P(WebGLCompatibilityTest, R32FTextures)
1610{
1611 constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f};
1612
1613 for (auto extension : FloatingPointTextureExtensions)
1614 {
1615 if (strlen(extension) > 0 && extensionRequestable(extension))
1616 {
1617 glRequestExtensionANGLE(extension);
1618 ASSERT_GL_NO_ERROR();
1619 }
1620
1621 // Unsized R 32F
1622 {
1623 bool texture =
1624 extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg");
1625 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1626 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1627 TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1628 }
1629
1630 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1631 {
1632 // Sized R 32F
1633 bool texture =
1634 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1635 extensionEnabled("GL_EXT_texture_rg") &&
1636 extensionEnabled("GL_EXT_texture_storage"));
1637 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1638 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1639 TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data);
1640 }
1641 }
1642}
1643
1644TEST_P(WebGLCompatibilityTest, RG32FTextures)
1645{
1646 constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f};
1647
1648 for (auto extension : FloatingPointTextureExtensions)
1649 {
1650 if (strlen(extension) > 0 && extensionRequestable(extension))
1651 {
1652 glRequestExtensionANGLE(extension);
1653 ASSERT_GL_NO_ERROR();
1654 }
1655
1656 // Unsized RG 32F
1657 {
1658 bool texture =
1659 (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"));
1660 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1661 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1662 TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1663 }
1664
1665 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1666 {
1667 // Sized RG 32F
1668 bool texture =
1669 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1670 extensionEnabled("GL_EXT_texture_rg") &&
1671 extensionEnabled("GL_EXT_texture_storage"));
1672 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1673 bool render = extensionEnabled("GL_EXT_color_buffer_float");
1674 TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data);
1675 }
1676 }
1677}
1678
1679TEST_P(WebGLCompatibilityTest, RGB32FTextures)
1680{
1681 constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f};
1682
1683 for (auto extension : FloatingPointTextureExtensions)
1684 {
1685 if (strlen(extension) > 0 && extensionRequestable(extension))
1686 {
1687 glRequestExtensionANGLE(extension);
1688 ASSERT_GL_NO_ERROR();
1689 }
1690
1691 // Unsized RGB 32F
1692 {
1693 bool texture = extensionEnabled("GL_OES_texture_float");
1694 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1695 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1696 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data);
1697 }
1698
1699 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1700 {
1701 // Sized RGBA 32F
1702 bool texture =
1703 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1704 extensionEnabled("GL_EXT_texture_storage"));
1705 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1706 bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb");
1707 TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data,
1708 data);
1709 }
1710 }
1711}
1712
1713TEST_P(WebGLCompatibilityTest, RGBA32FTextures)
1714{
1715 constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f};
1716
1717 for (auto extension : FloatingPointTextureExtensions)
1718 {
1719 if (strlen(extension) > 0 && extensionRequestable(extension))
1720 {
1721 glRequestExtensionANGLE(extension);
1722 ASSERT_GL_NO_ERROR();
1723 }
1724
1725 // Unsized RGBA 32F
1726 {
1727 bool texture = extensionEnabled("GL_OES_texture_float");
1728 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1729 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1730 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1731 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data);
1732 }
1733
1734 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1735 {
1736 // Sized RGBA 32F
1737 bool texture =
1738 (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") &&
1739 extensionEnabled("GL_EXT_texture_storage"));
1740 bool filter = extensionEnabled("GL_OES_texture_float_linear");
1741 bool render = extensionEnabled("GL_EXT_color_buffer_float") ||
1742 extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba");
1743 TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data,
1744 data);
1745 }
1746 }
1747}
1748
1749TEST_P(WebGLCompatibilityTest, R16FTextures)
1750{
1751 constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f};
1752 const GLushort textureData[] = {
1753 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1754 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1755
1756 for (auto extension : FloatingPointTextureExtensions)
1757 {
1758 if (strlen(extension) > 0 && extensionRequestable(extension))
1759 {
1760 glRequestExtensionANGLE(extension);
1761 ASSERT_GL_NO_ERROR();
1762 }
1763
1764 // Unsized R 16F (OES)
1765 {
1766 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1767 extensionEnabled("GL_EXT_texture_rg");
1768 bool filter = getClientMajorVersion() >= 3 ||
1769 extensionEnabled("GL_OES_texture_half_float_linear");
1770 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1771 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render,
1772 textureData, readPixelsData);
1773 }
1774
1775 // Unsized R 16F
1776 {
1777 bool texture = false;
1778 bool filter = false;
1779 bool render = false;
1780 TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1781 textureData, readPixelsData);
1782 }
1783
1784 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1785 {
1786 // Sized R 16F
1787 bool texture = getClientMajorVersion() >= 3;
1788 bool filter = getClientMajorVersion() >= 3 ||
1789 extensionEnabled("GL_OES_texture_half_float_linear");
1790 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1791 extensionEnabled("GL_EXT_color_buffer_float");
1792 TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render,
1793 textureData, readPixelsData);
1794 }
1795 }
1796}
1797
1798TEST_P(WebGLCompatibilityTest, RG16FTextures)
1799{
1800 constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f};
1801 const GLushort textureData[] = {
1802 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1803 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1804
1805 for (auto extension : FloatingPointTextureExtensions)
1806 {
1807 if (strlen(extension) > 0 && extensionRequestable(extension))
1808 {
1809 glRequestExtensionANGLE(extension);
1810 ASSERT_GL_NO_ERROR();
1811 }
1812
1813 // Unsized RG 16F (OES)
1814 {
1815 bool texture = extensionEnabled("GL_OES_texture_half_float") &&
1816 extensionEnabled("GL_EXT_texture_rg");
1817 bool filter = getClientMajorVersion() >= 3 ||
1818 extensionEnabled("GL_OES_texture_half_float_linear");
1819 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") &&
1820 extensionEnabled("GL_EXT_texture_rg");
1821 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render,
1822 textureData, readPixelsData);
1823 }
1824
1825 // Unsized RG 16F
1826 {
1827 bool texture = false;
1828 bool filter = false;
1829 bool render = false;
1830 TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1831 textureData, readPixelsData);
1832 }
1833
1834 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1835 {
1836 // Sized RG 16F
1837 bool texture = getClientMajorVersion() >= 3;
1838 bool filter = getClientMajorVersion() >= 3 ||
1839 extensionEnabled("GL_OES_texture_half_float_linear");
1840 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1841 extensionEnabled("GL_EXT_color_buffer_float");
1842 TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render,
1843 textureData, readPixelsData);
1844 }
1845 }
1846}
1847
1848TEST_P(WebGLCompatibilityTest, RGB16FTextures)
1849{
1850 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f};
1851 const GLushort textureData[] = {
1852 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1853 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1854
1855 for (auto extension : FloatingPointTextureExtensions)
1856 {
1857 if (strlen(extension) > 0 && extensionRequestable(extension))
1858 {
1859 glRequestExtensionANGLE(extension);
1860 ASSERT_GL_NO_ERROR();
1861 }
1862
1863 // Unsized RGB 16F (OES)
1864 {
1865 bool texture = extensionEnabled("GL_OES_texture_half_float");
1866 bool filter = getClientMajorVersion() >= 3 ||
1867 extensionEnabled("GL_OES_texture_half_float_linear");
1868 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1869 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render,
1870 textureData, readPixelsData);
1871 }
1872
1873 // Unsized RGB 16F
1874 {
1875 bool texture = false;
1876 bool filter = false;
1877 bool render = false;
1878 TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
1879 textureData, readPixelsData);
1880 }
1881
1882 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1883 {
1884 // Sized RGB 16F
1885 bool texture = getClientMajorVersion() >= 3;
1886 bool filter = getClientMajorVersion() >= 3 ||
1887 extensionEnabled("GL_OES_texture_half_float_linear");
1888 bool render = extensionEnabled("GL_EXT_color_buffer_half_float");
1889 TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render,
1890 textureData, readPixelsData);
1891 }
1892 }
1893}
1894
1895TEST_P(WebGLCompatibilityTest, RGBA16FTextures)
1896{
1897 constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f};
1898 const GLushort textureData[] = {
1899 gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]),
1900 gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])};
1901
1902 for (auto extension : FloatingPointTextureExtensions)
1903 {
1904 if (strlen(extension) > 0 && extensionRequestable(extension))
1905 {
1906 glRequestExtensionANGLE(extension);
1907 ASSERT_GL_NO_ERROR();
1908 }
1909
1910 // Unsized RGBA 16F (OES)
1911 {
1912 bool texture = extensionEnabled("GL_OES_texture_half_float");
1913 bool filter = getClientMajorVersion() >= 3 ||
1914 extensionEnabled("GL_OES_texture_half_float_linear");
1915 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1916 extensionEnabled("GL_EXT_color_buffer_float");
1917 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render,
1918 textureData, readPixelsData);
1919 }
1920
1921 // Unsized RGBA 16F
1922 {
1923 bool texture = false;
1924 bool filter = false;
1925 bool render = false;
1926 TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
1927 textureData, readPixelsData);
1928 }
1929
1930 if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage"))
1931 {
1932 // Sized RGBA 16F
1933 bool texture = getClientMajorVersion() >= 3;
1934 bool filter = getClientMajorVersion() >= 3 ||
1935 extensionEnabled("GL_OES_texture_half_float_linear");
1936 bool render = extensionEnabled("GL_EXT_color_buffer_half_float") ||
1937 extensionEnabled("GL_EXT_color_buffer_float");
1938 TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render,
1939 textureData, readPixelsData);
1940 }
1941 }
1942}
1943
Jamie Madill07be8bf2017-02-02 19:59:57 -05001944// This tests that rendering feedback loops works as expected with WebGL 2.
1945// Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html
1946TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers)
1947{
1948 const std::string vertexShader =
1949 "#version 300 es\n"
1950 "in vec4 aPosition;\n"
1951 "out vec2 texCoord;\n"
1952 "void main() {\n"
1953 " gl_Position = aPosition;\n"
1954 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
1955 "}\n";
1956
1957 const std::string fragmentShader =
1958 "#version 300 es\n"
1959 "precision mediump float;\n"
1960 "uniform sampler2D tex;\n"
1961 "in vec2 texCoord;\n"
1962 "out vec4 oColor;\n"
1963 "void main() {\n"
1964 " oColor = texture(tex, texCoord);\n"
1965 "}\n";
1966
1967 GLsizei width = 8;
1968 GLsizei height = 8;
1969
1970 GLint maxDrawBuffers = 0;
1971 glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
1972 // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS.
1973 ASSERT_GE(maxDrawBuffers, 2);
1974
1975 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
1976 glUseProgram(program.get());
1977 glViewport(0, 0, width, height);
1978
1979 GLTexture tex0;
1980 GLTexture tex1;
1981 GLFramebuffer fbo;
1982 FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1983 FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
1984 ASSERT_GL_NO_ERROR();
1985
1986 glBindTexture(GL_TEXTURE_2D, tex1.get());
1987 GLint texLoc = glGetUniformLocation(program.get(), "tex");
1988 ASSERT_NE(-1, texLoc);
1989 glUniform1i(texLoc, 0);
1990
1991 // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation
1992 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
1993 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
1994 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0);
1995 ASSERT_GL_NO_ERROR();
1996
1997 drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION);
1998 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}},
1999 GL_INVALID_OPERATION);
2000 drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR);
2001}
2002
Jamie Madill1d37bc52017-02-02 19:59:58 -05002003// This test covers detection of rendering feedback loops between the FBO and a depth Texture.
2004// Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html
2005TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil)
2006{
2007 const std::string vertexShader =
2008 "#version 300 es\n"
2009 "in vec4 aPosition;\n"
2010 "out vec2 texCoord;\n"
2011 "void main() {\n"
2012 " gl_Position = aPosition;\n"
2013 " texCoord = (aPosition.xy * 0.5) + 0.5;\n"
2014 "}\n";
2015
2016 const std::string fragmentShader =
2017 "#version 300 es\n"
2018 "precision mediump float;\n"
2019 "uniform sampler2D tex;\n"
2020 "in vec2 texCoord;\n"
2021 "out vec4 oColor;\n"
2022 "void main() {\n"
2023 " oColor = texture(tex, texCoord);\n"
2024 "}\n";
2025
2026 GLsizei width = 8;
2027 GLsizei height = 8;
2028
2029 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
2030 glUseProgram(program.get());
2031
2032 glViewport(0, 0, width, height);
2033
2034 GLint texLoc = glGetUniformLocation(program.get(), "tex");
2035 glUniform1i(texLoc, 0);
2036
2037 // Create textures and allocate storage
2038 GLTexture tex0;
2039 GLTexture tex1;
2040 GLRenderbuffer rb;
2041 FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
2042 FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
2043 GL_UNSIGNED_INT);
2044 glBindRenderbuffer(GL_RENDERBUFFER, rb.get());
2045 glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height);
2046 ASSERT_GL_NO_ERROR();
2047
2048 GLFramebuffer fbo;
2049 glBindFramebuffer(GL_FRAMEBUFFER, fbo.get());
2050 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0);
2051
2052 // Test rendering and sampling feedback loop for depth buffer
2053 glBindTexture(GL_TEXTURE_2D, tex1.get());
2054 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0);
2055 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2056
2057 // The same image is used as depth buffer during rendering.
2058 glEnable(GL_DEPTH_TEST);
2059 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2060 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2061
2062 // The same image is used as depth buffer. But depth mask is false.
2063 glDepthMask(GL_FALSE);
2064 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2065 EXPECT_GL_NO_ERROR();
2066
2067 // The same image is used as depth buffer. But depth test is not enabled during rendering.
2068 glDepthMask(GL_TRUE);
2069 glDisable(GL_DEPTH_TEST);
2070 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2071 EXPECT_GL_NO_ERROR();
2072
2073 // Test rendering and sampling feedback loop for stencil buffer
2074 glBindTexture(GL_RENDERBUFFER, rb.get());
2075 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
2076 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get());
2077 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
2078 constexpr GLint stencilClearValue = 0x40;
2079 glClearBufferiv(GL_STENCIL, 0, &stencilClearValue);
2080
2081 // The same image is used as stencil buffer during rendering.
2082 glEnable(GL_STENCIL_TEST);
2083 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2084 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2085
2086 // The same image is used as stencil buffer. But stencil mask is zero.
2087 glStencilMask(0x0);
2088 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2089 EXPECT_GL_NO_ERROR();
2090
2091 // The same image is used as stencil buffer. But stencil test is not enabled during rendering.
2092 glStencilMask(0xffff);
2093 glDisable(GL_STENCIL_TEST);
2094 drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true);
2095 EXPECT_GL_NO_ERROR();
2096}
2097
Jamie Madillfd3dd432017-02-02 19:59:59 -05002098// The source and the target for CopyTexSubImage3D are the same 3D texture.
2099// But the level of the 3D texture != the level of the read attachment.
2100TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels)
2101{
2102 GLTexture texture;
2103 GLFramebuffer framebuffer;
2104
2105 glBindTexture(GL_TEXTURE_3D, texture.get());
2106 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2107
2108 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2109 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2110 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0);
2111 ASSERT_GL_NO_ERROR();
2112
2113 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2114 EXPECT_GL_NO_ERROR();
2115}
2116
2117// The source and the target for CopyTexSubImage3D are the same 3D texture.
2118// But the zoffset of the 3D texture != the layer of the read attachment.
2119TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers)
2120{
2121 GLTexture texture;
2122 GLFramebuffer framebuffer;
2123
2124 glBindTexture(GL_TEXTURE_3D, texture.get());
2125 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2126
2127 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2128 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1);
2129 ASSERT_GL_NO_ERROR();
2130
2131 glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2);
2132 EXPECT_GL_NO_ERROR();
2133}
2134
2135// The source and the target for CopyTexSubImage3D are the same 3D texture.
2136// And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment.
2137TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D)
2138{
2139 GLTexture texture;
2140 GLFramebuffer framebuffer;
2141
2142 glBindTexture(GL_TEXTURE_3D, texture.get());
2143 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2144
2145 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2146 glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2147 glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2148 glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0);
2149 ASSERT_GL_NO_ERROR();
2150
2151 glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2);
2152 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2153}
2154
Geoff Lang76e65652017-03-27 14:58:02 -04002155// Verify that errors are generated when there isn not a defined conversion between the clear type
2156// and the buffer type.
2157TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity)
2158{
2159 if (IsD3D11())
2160 {
2161 std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl;
2162 return;
2163 }
2164
2165 constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f};
2166 constexpr int clearInt[] = {0, 0, 0, 0};
2167 constexpr unsigned int clearUint[] = {0, 0, 0, 0};
2168
2169 GLTexture texture;
2170 GLFramebuffer framebuffer;
2171
2172 glBindTexture(GL_TEXTURE_2D, texture.get());
2173 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get());
2174
2175 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0);
2176 ASSERT_GL_NO_ERROR();
2177
2178 // Unsigned integer buffer
2179 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr);
2180 ASSERT_GL_NO_ERROR();
2181
2182 glClearBufferfv(GL_COLOR, 0, clearFloat);
2183 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2184
2185 glClearBufferiv(GL_COLOR, 0, clearInt);
2186 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2187
2188 glClearBufferuiv(GL_COLOR, 0, clearUint);
2189 EXPECT_GL_NO_ERROR();
2190
2191 glClear(GL_COLOR_BUFFER_BIT);
2192 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2193
2194 // Integer buffer
2195 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr);
2196 ASSERT_GL_NO_ERROR();
2197
2198 glClearBufferfv(GL_COLOR, 0, clearFloat);
2199 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2200
2201 glClearBufferiv(GL_COLOR, 0, clearInt);
2202 EXPECT_GL_NO_ERROR();
2203
2204 glClearBufferuiv(GL_COLOR, 0, clearUint);
2205 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2206
2207 glClear(GL_COLOR_BUFFER_BIT);
2208 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2209
2210 // Float buffer
Geoff Lang677bb6f2017-04-05 12:40:40 -04002211 if (extensionRequestable("GL_EXT_color_buffer_float"))
2212 {
2213 glRequestExtensionANGLE("GL_EXT_color_buffer_float");
2214 }
Geoff Lang76e65652017-03-27 14:58:02 -04002215
Geoff Lang677bb6f2017-04-05 12:40:40 -04002216 if (extensionEnabled("GL_EXT_color_buffer_float"))
2217 {
2218 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr);
2219 ASSERT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002220
Geoff Lang677bb6f2017-04-05 12:40:40 -04002221 glClearBufferfv(GL_COLOR, 0, clearFloat);
2222 EXPECT_GL_NO_ERROR();
Geoff Lang76e65652017-03-27 14:58:02 -04002223
Geoff Lang677bb6f2017-04-05 12:40:40 -04002224 glClearBufferiv(GL_COLOR, 0, clearInt);
2225 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
Geoff Lang76e65652017-03-27 14:58:02 -04002226
Geoff Lang677bb6f2017-04-05 12:40:40 -04002227 glClearBufferuiv(GL_COLOR, 0, clearUint);
2228 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2229
2230 glClear(GL_COLOR_BUFFER_BIT);
2231 EXPECT_GL_NO_ERROR();
2232 }
Geoff Lang76e65652017-03-27 14:58:02 -04002233
2234 // Normalized uint buffer
2235 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
2236 ASSERT_GL_NO_ERROR();
2237
2238 glClearBufferfv(GL_COLOR, 0, clearFloat);
2239 EXPECT_GL_NO_ERROR();
2240
2241 glClearBufferiv(GL_COLOR, 0, clearInt);
2242 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2243
2244 glClearBufferuiv(GL_COLOR, 0, clearUint);
2245 EXPECT_GL_ERROR(GL_INVALID_OPERATION);
2246
2247 glClear(GL_COLOR_BUFFER_BIT);
2248 EXPECT_GL_NO_ERROR();
2249}
2250
Geoff Lange4915782017-04-12 15:19:07 -04002251// Verify that errors are generate when trying to blit from an image to itself
2252TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage)
2253{
2254 GLTexture textures[2];
2255 glBindTexture(GL_TEXTURE_2D, textures[0]);
2256 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2257 glBindTexture(GL_TEXTURE_2D, textures[1]);
2258 glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4);
2259
2260 GLRenderbuffer renderbuffers[2];
2261 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]);
2262 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2263 glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]);
2264 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4);
2265
2266 GLFramebuffer framebuffers[2];
2267 glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]);
2268 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]);
2269
2270 ASSERT_GL_NO_ERROR();
2271
2272 // Same texture
2273 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2274 0);
2275 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2276 0);
2277 ASSERT_GL_NO_ERROR();
2278 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2279 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2280
2281 // Same textures but different renderbuffers
2282 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2283 renderbuffers[0]);
2284 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2285 renderbuffers[1]);
2286 ASSERT_GL_NO_ERROR();
2287 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
2288 ASSERT_GL_NO_ERROR();
2289 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2290 GL_NEAREST);
2291 ASSERT_GL_NO_ERROR();
2292 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2293 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2294 GL_NEAREST);
2295 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2296
2297 // Same renderbuffers but different textures
2298 glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0],
2299 0);
2300 glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1],
2301 0);
2302 glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2303 renderbuffers[0]);
2304 glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2305 renderbuffers[0]);
2306 ASSERT_GL_NO_ERROR();
2307 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST);
2308 ASSERT_GL_NO_ERROR();
2309 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2310 GL_NEAREST);
2311 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2312 glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4,
2313 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT,
2314 GL_NEAREST);
2315 ASSERT_GL_ERROR(GL_INVALID_OPERATION);
2316}
2317
Geoff Langc287ea62016-09-16 14:46:51 -04002318// Use this to select which configurations (e.g. which renderer, which GLES major version) these
2319// tests should be run against.
2320ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest,
2321 ES2_D3D9(),
2322 ES2_D3D11(),
2323 ES3_D3D11(),
Geoff Langc287ea62016-09-16 14:46:51 -04002324 ES2_OPENGL(),
2325 ES3_OPENGL(),
2326 ES2_OPENGLES(),
2327 ES3_OPENGLES());
2328
Jamie Madill07be8bf2017-02-02 19:59:57 -05002329ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Geoff Langc287ea62016-09-16 14:46:51 -04002330} // namespace