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