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