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