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", |
| 40 | "GL_OES_texture_float", |
| 41 | "GL_OES_texture_float_linear", |
| 42 | "GL_OES_texture_half_float", |
| 43 | "GL_OES_texture_half_float_linear", |
| 44 | "GL_EXT_color_buffer_half_float", |
| 45 | "GL_EXT_color_buffer_float", |
| 46 | "GL_CHROMIUM_color_buffer_float_rgba", |
| 47 | "GL_CHROMIUM_color_buffer_float_rgb", |
| 48 | }; |
| 49 | |
Frank 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 | |
| 297 | glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr); |
| 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 | |
| 306 | glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr); |
| 307 | EXPECT_GL_NO_ERROR(); |
| 308 | } |
| 309 | } |
| 310 | |
Geoff Lang | ff5c63e | 2017-04-12 15:26:54 -0400 | [diff] [blame] | 311 | // Test enabling the GL_OES_standard_derivatives extension |
| 312 | TEST_P(WebGLCompatibilityTest, EnableExtensionStandardDerivitives) |
| 313 | { |
| 314 | EXPECT_FALSE(extensionEnabled("GL_OES_standard_derivatives")); |
| 315 | |
| 316 | const std::string source = |
| 317 | "#extension GL_OES_standard_derivatives : require\n" |
| 318 | "void main() { gl_FragColor = vec4(dFdx(vec2(1.0, 1.0)).x, 1, 0, 1); }\n"; |
| 319 | ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source)); |
| 320 | |
| 321 | if (extensionRequestable("GL_OES_standard_derivatives")) |
| 322 | { |
| 323 | glRequestExtensionANGLE("GL_OES_standard_derivatives"); |
| 324 | EXPECT_GL_NO_ERROR(); |
| 325 | EXPECT_TRUE(extensionEnabled("GL_OES_standard_derivatives")); |
| 326 | |
| 327 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); |
| 328 | ASSERT_NE(0u, shader); |
| 329 | glDeleteShader(shader); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | // Test enabling the GL_EXT_shader_texture_lod extension |
| 334 | TEST_P(WebGLCompatibilityTest, EnableExtensionTextureLOD) |
| 335 | { |
| 336 | EXPECT_FALSE(extensionEnabled("GL_EXT_shader_texture_lod")); |
| 337 | |
| 338 | const std::string source = |
| 339 | "#extension GL_EXT_shader_texture_lod : require\n" |
| 340 | "uniform sampler2D u_texture;\n" |
| 341 | "void main() {\n" |
| 342 | " gl_FragColor = texture2DGradEXT(u_texture, vec2(0.0, 0.0), vec2(0.0, 0.0), vec2(0.0, " |
| 343 | "0.0));\n" |
| 344 | "}\n"; |
| 345 | ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source)); |
| 346 | |
| 347 | if (extensionRequestable("GL_EXT_shader_texture_lod")) |
| 348 | { |
| 349 | glRequestExtensionANGLE("GL_EXT_shader_texture_lod"); |
| 350 | EXPECT_GL_NO_ERROR(); |
| 351 | EXPECT_TRUE(extensionEnabled("GL_EXT_shader_texture_lod")); |
| 352 | |
| 353 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); |
| 354 | ASSERT_NE(0u, shader); |
| 355 | glDeleteShader(shader); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // Test enabling the GL_EXT_frag_depth extension |
| 360 | TEST_P(WebGLCompatibilityTest, EnableExtensionFragDepth) |
| 361 | { |
| 362 | EXPECT_FALSE(extensionEnabled("GL_EXT_frag_depth")); |
| 363 | |
| 364 | const std::string source = |
| 365 | "#extension GL_EXT_frag_depth : require\n" |
| 366 | "void main() {\n" |
| 367 | " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n" |
| 368 | " gl_FragDepthEXT = 1.0;\n" |
| 369 | "}\n"; |
| 370 | ASSERT_EQ(0u, CompileShader(GL_FRAGMENT_SHADER, source)); |
| 371 | |
| 372 | if (extensionRequestable("GL_EXT_frag_depth")) |
| 373 | { |
| 374 | glRequestExtensionANGLE("GL_EXT_frag_depth"); |
| 375 | EXPECT_GL_NO_ERROR(); |
| 376 | EXPECT_TRUE(extensionEnabled("GL_EXT_frag_depth")); |
| 377 | |
| 378 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); |
| 379 | ASSERT_NE(0u, shader); |
| 380 | glDeleteShader(shader); |
| 381 | } |
| 382 | } |
| 383 | |
Geoff Lang | d7d526a | 2017-02-21 16:48:43 -0500 | [diff] [blame] | 384 | // Test enabling the GL_EXT_texture_filter_anisotropic extension |
| 385 | TEST_P(WebGLCompatibilityTest, EnableExtensionTextureFilterAnisotropic) |
| 386 | { |
| 387 | EXPECT_FALSE(extensionEnabled("GL_EXT_texture_filter_anisotropic")); |
| 388 | |
| 389 | GLfloat maxAnisotropy = 0.0f; |
| 390 | glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); |
| 391 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 392 | |
| 393 | GLTexture texture; |
| 394 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 395 | ASSERT_GL_NO_ERROR(); |
| 396 | |
| 397 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f); |
| 398 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 399 | |
| 400 | GLfloat currentAnisotropy = 0.0f; |
| 401 | glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, ¤tAnisotropy); |
| 402 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 403 | |
| 404 | if (extensionRequestable("GL_EXT_texture_filter_anisotropic")) |
| 405 | { |
| 406 | glRequestExtensionANGLE("GL_EXT_texture_filter_anisotropic"); |
| 407 | EXPECT_GL_NO_ERROR(); |
| 408 | EXPECT_TRUE(extensionEnabled("GL_EXT_texture_filter_anisotropic")); |
| 409 | |
| 410 | glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy); |
| 411 | ASSERT_GL_NO_ERROR(); |
| 412 | EXPECT_GE(maxAnisotropy, 2.0f); |
| 413 | |
| 414 | glGetTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, ¤tAnisotropy); |
| 415 | ASSERT_GL_NO_ERROR(); |
| 416 | EXPECT_EQ(1.0f, currentAnisotropy); |
| 417 | |
| 418 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f); |
| 419 | ASSERT_GL_NO_ERROR(); |
| 420 | } |
| 421 | } |
| 422 | |
Bryan Bernhart | 87c182e | 2016-11-02 11:23:22 -0700 | [diff] [blame] | 423 | // Verify that shaders are of a compatible spec when the extension is enabled. |
| 424 | TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec) |
| 425 | { |
| 426 | EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility")); |
| 427 | |
| 428 | // Use of reserved _webgl prefix should fail when the shader specification is for WebGL. |
| 429 | const std::string &vert = |
| 430 | "struct Foo {\n" |
| 431 | " int _webgl_bar;\n" |
| 432 | "};\n" |
| 433 | "void main()\n" |
| 434 | "{\n" |
| 435 | " Foo foo = Foo(1);\n" |
| 436 | "}"; |
| 437 | |
| 438 | // Default fragement shader. |
| 439 | const std::string &frag = |
| 440 | "void main()\n" |
| 441 | "{\n" |
| 442 | " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n" |
| 443 | "}"; |
| 444 | |
| 445 | GLuint program = CompileProgram(vert, frag); |
| 446 | EXPECT_EQ(0u, program); |
| 447 | glDeleteProgram(program); |
| 448 | } |
| 449 | |
Geoff Lang | a0e0aeb | 2017-04-12 15:06:29 -0400 | [diff] [blame] | 450 | // Verify that the context generates the correct error when the framebuffer attachments are |
| 451 | // different sizes |
| 452 | TEST_P(WebGLCompatibilityTest, FramebufferAttachmentSizeMissmatch) |
| 453 | { |
| 454 | GLFramebuffer fbo; |
| 455 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 456 | |
| 457 | GLTexture textures[2]; |
| 458 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 459 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 460 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0); |
| 461 | |
| 462 | ASSERT_GL_NO_ERROR(); |
| 463 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 464 | |
| 465 | GLRenderbuffer renderbuffer; |
| 466 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer); |
| 467 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, 3, 3); |
| 468 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); |
| 469 | |
| 470 | ASSERT_GL_NO_ERROR(); |
| 471 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS, |
| 472 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 473 | |
| 474 | if (extensionRequestable("GL_EXT_draw_buffers")) |
| 475 | { |
| 476 | glRequestExtensionANGLE("GL_EXT_draw_buffers"); |
| 477 | EXPECT_GL_NO_ERROR(); |
| 478 | EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers")); |
| 479 | |
| 480 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 481 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 482 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textures[1], 0); |
| 483 | ASSERT_GL_NO_ERROR(); |
| 484 | |
| 485 | ASSERT_GL_NO_ERROR(); |
| 486 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS, |
| 487 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 488 | |
| 489 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0); |
| 490 | |
| 491 | ASSERT_GL_NO_ERROR(); |
| 492 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 493 | |
| 494 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 3, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 495 | |
| 496 | ASSERT_GL_NO_ERROR(); |
| 497 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS, |
| 498 | glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 499 | } |
| 500 | } |
| 501 | |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 502 | // Test that client-side array buffers are forbidden in WebGL mode |
| 503 | TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer) |
| 504 | { |
| 505 | const std::string &vert = |
| 506 | "attribute vec3 a_pos;\n" |
| 507 | "void main()\n" |
| 508 | "{\n" |
| 509 | " gl_Position = vec4(a_pos, 1.0);\n" |
| 510 | "}\n"; |
| 511 | |
| 512 | const std::string &frag = |
| 513 | "precision highp float;\n" |
| 514 | "void main()\n" |
| 515 | "{\n" |
| 516 | " gl_FragColor = vec4(1.0);\n" |
| 517 | "}\n"; |
| 518 | |
| 519 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 520 | |
| 521 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 522 | ASSERT_NE(-1, posLocation); |
| 523 | glUseProgram(program.get()); |
| 524 | |
| 525 | const auto &vertices = GetQuadVertices(); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 526 | glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data()); |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 527 | glEnableVertexAttribArray(posLocation); |
| 528 | |
| 529 | ASSERT_GL_NO_ERROR(); |
| 530 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 531 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 532 | } |
| 533 | |
| 534 | // Test that client-side element array buffers are forbidden in WebGL mode |
| 535 | TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer) |
| 536 | { |
| 537 | const std::string &vert = |
| 538 | "attribute vec3 a_pos;\n" |
| 539 | "void main()\n" |
| 540 | "{\n" |
| 541 | " gl_Position = vec4(a_pos, 1.0);\n" |
| 542 | "}\n"; |
| 543 | |
| 544 | const std::string &frag = |
| 545 | "precision highp float;\n" |
| 546 | "void main()\n" |
| 547 | "{\n" |
| 548 | " gl_FragColor = vec4(1.0);\n" |
| 549 | "}\n"; |
| 550 | |
| 551 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 552 | |
| 553 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 554 | ASSERT_NE(-1, posLocation); |
| 555 | glUseProgram(program.get()); |
| 556 | |
| 557 | const auto &vertices = GetQuadVertices(); |
| 558 | |
| 559 | GLBuffer vertexBuffer; |
| 560 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get()); |
| 561 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(), |
| 562 | GL_STATIC_DRAW); |
| 563 | |
| 564 | glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); |
| 565 | glEnableVertexAttribArray(posLocation); |
| 566 | |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 567 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | ded1b5a | 2017-03-09 18:58:48 -0500 | [diff] [blame] | 568 | |
| 569 | // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also |
| 570 | // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate |
| 571 | // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check. |
| 572 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, reinterpret_cast<const void*>(intptr_t(1))); |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 573 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 574 | } |
| 575 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 576 | // Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back |
| 577 | TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef) |
| 578 | { |
| 579 | // Run the test in an FBO to make sure we have some stencil bits. |
| 580 | GLRenderbuffer renderbuffer; |
| 581 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get()); |
| 582 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32); |
| 583 | |
| 584 | GLFramebuffer framebuffer; |
| 585 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 586 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 587 | renderbuffer.get()); |
| 588 | |
| 589 | ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }", |
| 590 | "void main() { gl_FragColor = vec4(0, 1, 0, 1); }") |
| 591 | glUseProgram(program.get()); |
| 592 | ASSERT_GL_NO_ERROR(); |
| 593 | |
| 594 | // Having ref and mask the same for front and back is valid. |
| 595 | glStencilMask(255); |
| 596 | glStencilFunc(GL_ALWAYS, 0, 255); |
| 597 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 598 | ASSERT_GL_NO_ERROR(); |
| 599 | |
| 600 | // Having a different front - back write mask generates an error. |
| 601 | glStencilMaskSeparate(GL_FRONT, 1); |
| 602 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 603 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 604 | |
| 605 | // Setting both write masks separately to the same value is valid. |
| 606 | glStencilMaskSeparate(GL_BACK, 1); |
| 607 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 608 | ASSERT_GL_NO_ERROR(); |
| 609 | |
| 610 | // Having a different stencil front - back mask generates an error |
| 611 | glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1); |
| 612 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 613 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 614 | |
| 615 | // Setting both masks separately to the same value is valid. |
| 616 | glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1); |
| 617 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 618 | ASSERT_GL_NO_ERROR(); |
| 619 | |
| 620 | // Having a different stencil front - back reference generates an error |
| 621 | glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1); |
| 622 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 623 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 624 | |
| 625 | // Setting both references separately to the same value is valid. |
| 626 | glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1); |
| 627 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 628 | ASSERT_GL_NO_ERROR(); |
| 629 | |
| 630 | // Using different stencil funcs, everything being equal is valid. |
| 631 | glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1); |
| 632 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 633 | ASSERT_GL_NO_ERROR(); |
| 634 | } |
| 635 | |
Corentin Wallez | 506fc9c | 2016-12-21 16:53:33 -0500 | [diff] [blame] | 636 | // Test that GL_FIXED is forbidden |
| 637 | TEST_P(WebGLCompatibilityTest, ForbidsGLFixed) |
| 638 | { |
| 639 | GLBuffer buffer; |
| 640 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 641 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 642 | |
| 643 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr); |
| 644 | ASSERT_GL_NO_ERROR(); |
| 645 | |
| 646 | glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr); |
| 647 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 648 | } |
| 649 | |
| 650 | // Test the WebGL limit of 255 for the attribute stride |
| 651 | TEST_P(WebGLCompatibilityTest, MaxStride) |
| 652 | { |
| 653 | GLBuffer buffer; |
| 654 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 655 | glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW); |
| 656 | |
| 657 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr); |
| 658 | ASSERT_GL_NO_ERROR(); |
| 659 | |
| 660 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr); |
| 661 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 662 | } |
| 663 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 664 | // Test the checks for OOB reads in the vertex buffers, non-instanced version |
| 665 | TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced) |
| 666 | { |
| 667 | const std::string &vert = |
| 668 | "attribute float a_pos;\n" |
| 669 | "void main()\n" |
| 670 | "{\n" |
| 671 | " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" |
| 672 | "}\n"; |
| 673 | |
| 674 | const std::string &frag = |
| 675 | "precision highp float;\n" |
| 676 | "void main()\n" |
| 677 | "{\n" |
| 678 | " gl_FragColor = vec4(1.0);\n" |
| 679 | "}\n"; |
| 680 | |
| 681 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 682 | |
| 683 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 684 | ASSERT_NE(-1, posLocation); |
| 685 | glUseProgram(program.get()); |
| 686 | |
| 687 | GLBuffer buffer; |
| 688 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 689 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 690 | |
| 691 | glEnableVertexAttribArray(posLocation); |
| 692 | |
| 693 | const uint8_t* zeroOffset = nullptr; |
| 694 | |
| 695 | // Test touching the last element is valid. |
| 696 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12); |
| 697 | glDrawArrays(GL_POINTS, 0, 4); |
| 698 | ASSERT_GL_NO_ERROR(); |
| 699 | |
| 700 | // Test touching the last element + 1 is invalid. |
| 701 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13); |
| 702 | glDrawArrays(GL_POINTS, 0, 4); |
| 703 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 704 | |
| 705 | // Test touching the last element is valid, using a stride. |
| 706 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9); |
| 707 | glDrawArrays(GL_POINTS, 0, 4); |
| 708 | ASSERT_GL_NO_ERROR(); |
| 709 | |
| 710 | // Test touching the last element + 1 is invalid, using a stride. |
| 711 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10); |
| 712 | glDrawArrays(GL_POINTS, 0, 4); |
| 713 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 714 | |
| 715 | // Test any offset is valid if no vertices are drawn. |
| 716 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32); |
| 717 | glDrawArrays(GL_POINTS, 0, 0); |
| 718 | ASSERT_GL_NO_ERROR(); |
| 719 | } |
| 720 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 721 | // Test the checks for OOB reads in the index buffer |
| 722 | TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer) |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 723 | { |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 724 | const std::string &vert = |
| 725 | "attribute float a_pos;\n" |
| 726 | "void main()\n" |
| 727 | "{\n" |
| 728 | " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" |
| 729 | "}\n"; |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 730 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 731 | const std::string &frag = |
| 732 | "precision highp float;\n" |
| 733 | "void main()\n" |
| 734 | "{\n" |
| 735 | " gl_FragColor = vec4(1.0);\n" |
| 736 | "}\n"; |
| 737 | |
| 738 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 739 | |
| 740 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 741 | ASSERT_NE(-1, posLocation); |
| 742 | glUseProgram(program.get()); |
| 743 | |
| 744 | GLBuffer vertexBuffer; |
| 745 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get()); |
| 746 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 747 | |
| 748 | glEnableVertexAttribArray(posLocation); |
| 749 | |
| 750 | const uint8_t *zeroOffset = nullptr; |
| 751 | const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 752 | |
| 753 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset); |
| 754 | |
| 755 | GLBuffer indexBuffer; |
| 756 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get()); |
| 757 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 758 | ASSERT_GL_NO_ERROR(); |
| 759 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 760 | // Test touching the last index is valid |
| 761 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4); |
| 762 | ASSERT_GL_NO_ERROR(); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 763 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 764 | // Test touching the last + 1 element is invalid |
| 765 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5); |
| 766 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 767 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 768 | // Test any offset if valid if count is zero |
| 769 | glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42); |
| 770 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 771 | |
| 772 | // Test touching the first index is valid |
| 773 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4); |
| 774 | ASSERT_GL_NO_ERROR(); |
| 775 | |
| 776 | // Test touching the first - 1 index is invalid |
| 777 | // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was |
| 778 | // the historic behavior of WebGL implementations |
| 779 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1); |
| 780 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 781 | } |
| 782 | |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 783 | // Test depth range with 'near' more or less than 'far.' |
| 784 | TEST_P(WebGLCompatibilityTest, DepthRange) |
| 785 | { |
| 786 | glDepthRangef(0, 1); |
| 787 | ASSERT_GL_NO_ERROR(); |
| 788 | |
| 789 | glDepthRangef(.5, .5); |
| 790 | ASSERT_GL_NO_ERROR(); |
| 791 | |
| 792 | glDepthRangef(1, 0); |
| 793 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 794 | } |
| 795 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 796 | // Test all blend function combinations. |
| 797 | // In WebGL it is invalid to combine constant color with constant alpha. |
| 798 | TEST_P(WebGLCompatibilityTest, BlendWithConstantColor) |
| 799 | { |
| 800 | constexpr GLenum srcFunc[] = { |
| 801 | GL_ZERO, |
| 802 | GL_ONE, |
| 803 | GL_SRC_COLOR, |
| 804 | GL_ONE_MINUS_SRC_COLOR, |
| 805 | GL_DST_COLOR, |
| 806 | GL_ONE_MINUS_DST_COLOR, |
| 807 | GL_SRC_ALPHA, |
| 808 | GL_ONE_MINUS_SRC_ALPHA, |
| 809 | GL_DST_ALPHA, |
| 810 | GL_ONE_MINUS_DST_ALPHA, |
| 811 | GL_CONSTANT_COLOR, |
| 812 | GL_ONE_MINUS_CONSTANT_COLOR, |
| 813 | GL_CONSTANT_ALPHA, |
| 814 | GL_ONE_MINUS_CONSTANT_ALPHA, |
| 815 | GL_SRC_ALPHA_SATURATE, |
| 816 | }; |
| 817 | |
| 818 | constexpr GLenum dstFunc[] = { |
| 819 | GL_ZERO, GL_ONE, |
| 820 | GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, |
| 821 | GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, |
| 822 | GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
| 823 | GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, |
| 824 | GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, |
| 825 | GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, |
| 826 | }; |
| 827 | |
| 828 | for (GLenum src : srcFunc) |
| 829 | { |
| 830 | for (GLenum dst : dstFunc) |
| 831 | { |
| 832 | glBlendFunc(src, dst); |
| 833 | CheckBlendFunctions(src, dst); |
| 834 | glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE); |
| 835 | CheckBlendFunctions(src, dst); |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 840 | // Test the checks for OOB reads in the vertex buffers, instanced version |
| 841 | TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced) |
| 842 | { |
| 843 | const std::string &vert = |
| 844 | "attribute float a_pos;\n" |
Geoff Lang | 407d4e7 | 2017-04-12 14:54:11 -0400 | [diff] [blame] | 845 | "attribute float a_w;\n" |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 846 | "void main()\n" |
| 847 | "{\n" |
Geoff Lang | 407d4e7 | 2017-04-12 14:54:11 -0400 | [diff] [blame] | 848 | " gl_Position = vec4(a_pos, a_pos, a_pos, a_w);\n" |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 849 | "}\n"; |
| 850 | |
| 851 | const std::string &frag = |
| 852 | "precision highp float;\n" |
| 853 | "void main()\n" |
| 854 | "{\n" |
| 855 | " gl_FragColor = vec4(1.0);\n" |
| 856 | "}\n"; |
| 857 | |
| 858 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 859 | |
| 860 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 861 | ASSERT_NE(-1, posLocation); |
Geoff Lang | 407d4e7 | 2017-04-12 14:54:11 -0400 | [diff] [blame] | 862 | |
| 863 | GLint wLocation = glGetAttribLocation(program.get(), "a_w"); |
| 864 | ASSERT_NE(-1, wLocation); |
| 865 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 866 | glUseProgram(program.get()); |
| 867 | |
| 868 | GLBuffer buffer; |
| 869 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 870 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 871 | |
| 872 | glEnableVertexAttribArray(posLocation); |
| 873 | glVertexAttribDivisor(posLocation, 1); |
| 874 | |
Geoff Lang | 407d4e7 | 2017-04-12 14:54:11 -0400 | [diff] [blame] | 875 | glEnableVertexAttribArray(wLocation); |
| 876 | glVertexAttribPointer(wLocation, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, 0); |
| 877 | glVertexAttribDivisor(wLocation, 0); |
| 878 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 879 | const uint8_t* zeroOffset = nullptr; |
| 880 | |
| 881 | // Test touching the last element is valid. |
| 882 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12); |
| 883 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 884 | ASSERT_GL_NO_ERROR(); |
| 885 | |
| 886 | // Test touching the last element + 1 is invalid. |
| 887 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13); |
| 888 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 889 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 890 | |
| 891 | // Test touching the last element is valid, using a stride. |
| 892 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9); |
| 893 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 894 | ASSERT_GL_NO_ERROR(); |
| 895 | |
| 896 | // Test touching the last element + 1 is invalid, using a stride. |
| 897 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10); |
| 898 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 899 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 900 | |
| 901 | // Test any offset is valid if no vertices are drawn. |
| 902 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32); |
| 903 | glDrawArraysInstanced(GL_POINTS, 0, 1, 0); |
| 904 | ASSERT_GL_NO_ERROR(); |
| 905 | } |
| 906 | |
Geoff Lang | 407d4e7 | 2017-04-12 14:54:11 -0400 | [diff] [blame] | 907 | // Test that at least one attribute has a zero divisor for WebGL |
| 908 | TEST_P(WebGL2CompatibilityTest, InstancedDrawZeroDivisor) |
| 909 | { |
| 910 | const std::string &vert = |
| 911 | "attribute float a_pos;\n" |
| 912 | "void main()\n" |
| 913 | "{\n" |
| 914 | " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" |
| 915 | "}\n"; |
| 916 | |
| 917 | const std::string &frag = |
| 918 | "precision highp float;\n" |
| 919 | "void main()\n" |
| 920 | "{\n" |
| 921 | " gl_FragColor = vec4(1.0);\n" |
| 922 | "}\n"; |
| 923 | |
| 924 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 925 | |
| 926 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 927 | ASSERT_NE(-1, posLocation); |
| 928 | |
| 929 | glUseProgram(program.get()); |
| 930 | |
| 931 | GLBuffer buffer; |
| 932 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 933 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 934 | |
| 935 | glEnableVertexAttribArray(posLocation); |
| 936 | glVertexAttribDivisor(posLocation, 1); |
| 937 | |
| 938 | // Test touching the last element is valid. |
| 939 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, nullptr); |
| 940 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 941 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 942 | |
| 943 | glVertexAttribDivisor(posLocation, 0); |
| 944 | ASSERT_GL_NO_ERROR(); |
| 945 | } |
| 946 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 947 | // Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled |
| 948 | TEST_P(WebGLCompatibilityTest, NPOT) |
| 949 | { |
| 950 | EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot")); |
| 951 | |
| 952 | // Create a texture and set an NPOT mip 0, should always be acceptable. |
| 953 | GLTexture texture; |
| 954 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 955 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 956 | ASSERT_GL_NO_ERROR(); |
| 957 | |
| 958 | // Try setting an NPOT mip 1 and verify the error if WebGL 1 |
| 959 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 960 | if (getClientMajorVersion() < 3) |
| 961 | { |
| 962 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 963 | } |
| 964 | else |
| 965 | { |
| 966 | ASSERT_GL_NO_ERROR(); |
| 967 | } |
| 968 | |
| 969 | if (extensionRequestable("GL_OES_texture_npot")) |
| 970 | { |
| 971 | glRequestExtensionANGLE("GL_OES_texture_npot"); |
| 972 | ASSERT_GL_NO_ERROR(); |
| 973 | |
| 974 | // Try again to set NPOT mip 1 |
| 975 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 976 | ASSERT_GL_NO_ERROR(); |
| 977 | } |
| 978 | } |
| 979 | |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 980 | template <typename T> |
| 981 | void FillTexture2D(GLuint texture, |
| 982 | GLsizei width, |
| 983 | GLsizei height, |
| 984 | const T &onePixelData, |
| 985 | GLint level, |
| 986 | GLint internalFormat, |
| 987 | GLenum format, |
| 988 | GLenum type) |
| 989 | { |
| 990 | std::vector<T> allPixelsData(width * height, onePixelData); |
| 991 | |
| 992 | glBindTexture(GL_TEXTURE_2D, texture); |
| 993 | glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, |
| 994 | allPixelsData.data()); |
| 995 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 996 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 997 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 998 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 999 | } |
| 1000 | |
Frank Henigman | 875bbba | 2017-02-08 16:38:17 -0500 | [diff] [blame] | 1001 | // Test that unset gl_Position defaults to (0,0,0,0). |
| 1002 | TEST_P(WebGLCompatibilityTest, DefaultPosition) |
| 1003 | { |
| 1004 | // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set, |
| 1005 | // and green otherwise. The center of each quadrant will be red if and only if all |
| 1006 | // four corners are red. |
| 1007 | const std::string vertexShader = |
| 1008 | "attribute vec3 pos;\n" |
| 1009 | "varying vec4 color;\n" |
| 1010 | "void main() {\n" |
| 1011 | " if (gl_Position == vec4(0,0,0,0)) {\n" |
| 1012 | " color = vec4(1,0,0,1);\n" |
| 1013 | " } else {\n" |
| 1014 | " color = vec4(0,1,0,1);\n" |
| 1015 | " }\n" |
| 1016 | " gl_Position = vec4(pos,1);\n" |
| 1017 | "}\n"; |
| 1018 | |
| 1019 | const std::string fragmentShader = |
| 1020 | "precision mediump float;\n" |
| 1021 | "varying vec4 color;\n" |
| 1022 | "void main() {\n" |
| 1023 | " gl_FragColor = color;\n" |
| 1024 | "}\n"; |
| 1025 | |
| 1026 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 1027 | drawQuad(program.get(), "pos", 0.0f, 1.0f, true); |
| 1028 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red); |
| 1029 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red); |
| 1030 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red); |
| 1031 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red); |
| 1032 | } |
| 1033 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 1034 | // Tests that a rendering feedback loop triggers a GL error under WebGL. |
| 1035 | // Based on WebGL test conformance/renderbuffers/feedback-loop.html. |
| 1036 | TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop) |
| 1037 | { |
| 1038 | const std::string vertexShader = |
| 1039 | "attribute vec4 a_position;\n" |
| 1040 | "varying vec2 v_texCoord;\n" |
| 1041 | "void main() {\n" |
| 1042 | " gl_Position = a_position;\n" |
| 1043 | " v_texCoord = (a_position.xy * 0.5) + 0.5;\n" |
| 1044 | "}\n"; |
| 1045 | |
| 1046 | const std::string fragmentShader = |
| 1047 | "precision mediump float;\n" |
| 1048 | "varying vec2 v_texCoord;\n" |
| 1049 | "uniform sampler2D u_texture;\n" |
| 1050 | "void main() {\n" |
| 1051 | " // Shader swizzles color channels so we can tell if the draw succeeded.\n" |
| 1052 | " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n" |
| 1053 | "}\n"; |
| 1054 | |
| 1055 | GLTexture texture; |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 1056 | 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] | 1057 | |
| 1058 | ASSERT_GL_NO_ERROR(); |
| 1059 | |
| 1060 | GLFramebuffer framebuffer; |
| 1061 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1062 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 1063 | |
| 1064 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1065 | |
| 1066 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 1067 | |
| 1068 | GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture"); |
| 1069 | ASSERT_NE(-1, uniformLoc); |
| 1070 | |
| 1071 | glUseProgram(program.get()); |
| 1072 | glUniform1i(uniformLoc, 0); |
| 1073 | glDisable(GL_BLEND); |
| 1074 | glDisable(GL_DEPTH_TEST); |
| 1075 | ASSERT_GL_NO_ERROR(); |
| 1076 | |
| 1077 | // Drawing with a texture that is also bound to the current framebuffer should fail |
| 1078 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1079 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 1080 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1081 | |
| 1082 | // Ensure that the texture contents did not change after the previous render |
| 1083 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 1084 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 1085 | ASSERT_GL_NO_ERROR(); |
| 1086 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 1087 | |
| 1088 | // Drawing when texture is bound to an inactive uniform should succeed |
| 1089 | GLTexture texture2; |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 1090 | 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] | 1091 | |
| 1092 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1093 | glActiveTexture(GL_TEXTURE1); |
| 1094 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1095 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 1096 | ASSERT_GL_NO_ERROR(); |
| 1097 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 1098 | } |
| 1099 | |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 1100 | // Test for the max draw buffers and color attachments. |
| 1101 | TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints) |
| 1102 | { |
| 1103 | // This test only applies to ES2. |
| 1104 | if (getClientMajorVersion() != 2) |
| 1105 | { |
| 1106 | return; |
| 1107 | } |
| 1108 | |
| 1109 | GLFramebuffer fbo[2]; |
| 1110 | glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get()); |
| 1111 | |
| 1112 | // Test that is valid when we bind with a single attachment point. |
| 1113 | GLTexture texture; |
| 1114 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1115 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1116 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 1117 | ASSERT_GL_NO_ERROR(); |
| 1118 | |
| 1119 | // Test that enabling the draw buffers extension will allow us to bind with a non-zero |
| 1120 | // attachment point. |
| 1121 | if (extensionRequestable("GL_EXT_draw_buffers")) |
| 1122 | { |
| 1123 | glRequestExtensionANGLE("GL_EXT_draw_buffers"); |
| 1124 | EXPECT_GL_NO_ERROR(); |
| 1125 | EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers")); |
| 1126 | |
| 1127 | glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get()); |
| 1128 | |
| 1129 | GLTexture texture2; |
| 1130 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 1131 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1132 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(), |
| 1133 | 0); |
| 1134 | ASSERT_GL_NO_ERROR(); |
| 1135 | } |
| 1136 | } |
| 1137 | |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 1138 | // Test that the offset in the index buffer is forced to be a multiple of the element size |
| 1139 | TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction) |
| 1140 | { |
| 1141 | const std::string &vert = |
| 1142 | "attribute vec3 a_pos;\n" |
| 1143 | "void main()\n" |
| 1144 | "{\n" |
| 1145 | " gl_Position = vec4(a_pos, 1.0);\n" |
| 1146 | "}\n"; |
| 1147 | |
| 1148 | const std::string &frag = |
| 1149 | "precision highp float;\n" |
| 1150 | "void main()\n" |
| 1151 | "{\n" |
| 1152 | " gl_FragColor = vec4(1.0);\n" |
| 1153 | "}\n"; |
| 1154 | |
| 1155 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 1156 | |
| 1157 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 1158 | ASSERT_NE(-1, posLocation); |
| 1159 | glUseProgram(program.get()); |
| 1160 | |
| 1161 | const auto &vertices = GetQuadVertices(); |
| 1162 | |
| 1163 | GLBuffer vertexBuffer; |
| 1164 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get()); |
| 1165 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(), |
| 1166 | GL_STATIC_DRAW); |
| 1167 | |
| 1168 | glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); |
| 1169 | glEnableVertexAttribArray(posLocation); |
| 1170 | |
| 1171 | GLBuffer indexBuffer; |
| 1172 | const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0}; |
| 1173 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get()); |
| 1174 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 1175 | |
| 1176 | ASSERT_GL_NO_ERROR(); |
| 1177 | |
| 1178 | const char *zeroIndices = nullptr; |
| 1179 | |
| 1180 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices); |
| 1181 | ASSERT_GL_NO_ERROR(); |
| 1182 | |
| 1183 | glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices); |
| 1184 | ASSERT_GL_NO_ERROR(); |
| 1185 | |
| 1186 | glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1); |
| 1187 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1188 | } |
| 1189 | |
| 1190 | // Test that the offset and stride in the vertex buffer is forced to be a multiple of the element |
| 1191 | // size |
| 1192 | TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction) |
| 1193 | { |
| 1194 | const char *zeroOffset = nullptr; |
| 1195 | |
| 1196 | // Base case, vector of two floats |
| 1197 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset); |
| 1198 | ASSERT_GL_NO_ERROR(); |
| 1199 | |
| 1200 | // Test setting a non-multiple offset |
| 1201 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1); |
| 1202 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1203 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2); |
| 1204 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1205 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3); |
| 1206 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1207 | |
| 1208 | // Test setting a non-multiple stride |
| 1209 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset); |
| 1210 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1211 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset); |
| 1212 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1213 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset); |
| 1214 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1215 | } |
| 1216 | |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 1217 | void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program, |
| 1218 | const std::array<GLenum, 2> &drawBuffers, |
| 1219 | GLenum expectedError) |
| 1220 | { |
| 1221 | glDrawBuffersEXT(2, drawBuffers.data()); |
| 1222 | |
| 1223 | // Make sure framebuffer is complete before feedback loop detection |
| 1224 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1225 | |
| 1226 | drawQuad(program, "aPosition", 0.5f, 1.0f, true); |
| 1227 | |
| 1228 | // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise, |
| 1229 | // it should be NO_ERROR" |
| 1230 | EXPECT_GL_ERROR(expectedError); |
| 1231 | } |
| 1232 | |
| 1233 | // This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers. |
| 1234 | // Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html |
| 1235 | TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT) |
| 1236 | { |
| 1237 | const std::string vertexShader = |
| 1238 | "attribute vec4 aPosition;\n" |
| 1239 | "varying vec2 texCoord;\n" |
| 1240 | "void main() {\n" |
| 1241 | " gl_Position = aPosition;\n" |
| 1242 | " texCoord = (aPosition.xy * 0.5) + 0.5;\n" |
| 1243 | "}\n"; |
| 1244 | |
| 1245 | const std::string fragmentShader = |
| 1246 | "#extension GL_EXT_draw_buffers : require\n" |
| 1247 | "precision mediump float;\n" |
| 1248 | "uniform sampler2D tex;\n" |
| 1249 | "varying vec2 texCoord;\n" |
| 1250 | "void main() {\n" |
| 1251 | " gl_FragData[0] = texture2D(tex, texCoord);\n" |
| 1252 | " gl_FragData[1] = texture2D(tex, texCoord);\n" |
| 1253 | "}\n"; |
| 1254 | |
| 1255 | GLsizei width = 8; |
| 1256 | GLsizei height = 8; |
| 1257 | |
| 1258 | // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers |
| 1259 | // extension and gl_FragData semantics are changed to enforce indexing by zero always. |
| 1260 | // TODO(jmadill): This extension should be disabled in WebGL 2 contexts. |
| 1261 | if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2) |
| 1262 | { |
| 1263 | // No WEBGL_draw_buffers support -- this is legal. |
| 1264 | return; |
| 1265 | } |
| 1266 | |
| 1267 | GLint maxDrawBuffers = 0; |
| 1268 | glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
| 1269 | |
| 1270 | if (maxDrawBuffers < 2) |
| 1271 | { |
| 1272 | std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl; |
| 1273 | return; |
| 1274 | } |
| 1275 | |
| 1276 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 1277 | glUseProgram(program.get()); |
| 1278 | glViewport(0, 0, width, height); |
| 1279 | |
| 1280 | GLTexture tex0; |
| 1281 | GLTexture tex1; |
| 1282 | GLFramebuffer fbo; |
| 1283 | FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 1284 | FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 1285 | ASSERT_GL_NO_ERROR(); |
| 1286 | |
| 1287 | glBindTexture(GL_TEXTURE_2D, tex1.get()); |
| 1288 | GLint texLoc = glGetUniformLocation(program.get(), "tex"); |
| 1289 | ASSERT_NE(-1, texLoc); |
| 1290 | glUniform1i(texLoc, 0); |
| 1291 | ASSERT_GL_NO_ERROR(); |
| 1292 | |
| 1293 | // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation |
| 1294 | glBindFramebuffer(GL_FRAMEBUFFER, fbo.get()); |
| 1295 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0); |
| 1296 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0); |
| 1297 | |
| 1298 | drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, |
| 1299 | GL_INVALID_OPERATION); |
| 1300 | drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}}, |
| 1301 | GL_INVALID_OPERATION); |
| 1302 | drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR); |
| 1303 | } |
| 1304 | |
Jamie Madill | 07be8bf | 2017-02-02 19:59:57 -0500 | [diff] [blame] | 1305 | // Test tests that texture copying feedback loops are properly rejected in WebGL. |
| 1306 | // Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html |
| 1307 | TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops) |
| 1308 | { |
| 1309 | GLTexture texture; |
| 1310 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1311 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1312 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1313 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1314 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1315 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1316 | |
| 1317 | GLTexture texture2; |
| 1318 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 1319 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1320 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1321 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1322 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1323 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1324 | |
| 1325 | GLFramebuffer framebuffer; |
| 1326 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1327 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 1328 | |
| 1329 | // framebuffer should be FRAMEBUFFER_COMPLETE. |
| 1330 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1331 | ASSERT_GL_NO_ERROR(); |
| 1332 | |
| 1333 | // testing copyTexImage2D |
| 1334 | |
| 1335 | // copyTexImage2D to same texture but different level |
| 1336 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1337 | glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0); |
| 1338 | EXPECT_GL_NO_ERROR(); |
| 1339 | |
| 1340 | // copyTexImage2D to same texture same level, invalid feedback loop |
| 1341 | glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0); |
| 1342 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1343 | |
| 1344 | // copyTexImage2D to different texture |
| 1345 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 1346 | glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0); |
| 1347 | EXPECT_GL_NO_ERROR(); |
| 1348 | |
| 1349 | // testing copyTexSubImage2D |
| 1350 | |
| 1351 | // copyTexSubImage2D to same texture but different level |
| 1352 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 1353 | glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1); |
| 1354 | EXPECT_GL_NO_ERROR(); |
| 1355 | |
| 1356 | // copyTexSubImage2D to same texture same level, invalid feedback loop |
| 1357 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); |
| 1358 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1359 | |
| 1360 | // copyTexSubImage2D to different texture |
| 1361 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 1362 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); |
| 1363 | EXPECT_GL_NO_ERROR(); |
| 1364 | } |
| 1365 | |
| 1366 | void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program, |
| 1367 | const std::array<GLenum, 2> &drawBuffers, |
| 1368 | GLenum expectedError) |
| 1369 | { |
| 1370 | glDrawBuffers(2, drawBuffers.data()); |
| 1371 | |
| 1372 | // Make sure framebuffer is complete before feedback loop detection |
| 1373 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1374 | |
| 1375 | drawQuad(program, "aPosition", 0.5f, 1.0f, true); |
| 1376 | |
| 1377 | // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise, |
| 1378 | // it should be NO_ERROR" |
| 1379 | EXPECT_GL_ERROR(expectedError); |
| 1380 | } |
| 1381 | |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 1382 | // Tests invariance matching rules between built in varyings. |
| 1383 | // Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html. |
| 1384 | TEST_P(WebGLCompatibilityTest, BuiltInInvariant) |
| 1385 | { |
| 1386 | const std::string vertexShaderVariant = |
| 1387 | "varying vec4 v_varying;\n" |
| 1388 | "void main()\n" |
| 1389 | "{\n" |
| 1390 | " gl_PointSize = 1.0;\n" |
| 1391 | " gl_Position = v_varying;\n" |
| 1392 | "}"; |
| 1393 | const std::string fragmentShaderInvariantGlFragCoord = |
| 1394 | "invariant gl_FragCoord;\n" |
| 1395 | "void main()\n" |
| 1396 | "{\n" |
| 1397 | " gl_FragColor = gl_FragCoord;\n" |
| 1398 | "}"; |
| 1399 | const std::string fragmentShaderInvariantGlPointCoord = |
| 1400 | "invariant gl_PointCoord;\n" |
| 1401 | "void main()\n" |
| 1402 | "{\n" |
| 1403 | " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n" |
| 1404 | "}"; |
| 1405 | |
| 1406 | GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord); |
| 1407 | EXPECT_EQ(0u, program); |
| 1408 | |
| 1409 | program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord); |
| 1410 | EXPECT_EQ(0u, program); |
| 1411 | } |
| 1412 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1413 | // Test dimension and image size validation of compressed textures |
| 1414 | TEST_P(WebGLCompatibilityTest, CompressedTextureS3TC) |
| 1415 | { |
| 1416 | if (extensionRequestable("GL_EXT_texture_compression_dxt1")) |
| 1417 | { |
| 1418 | glRequestExtensionANGLE("GL_EXT_texture_compression_dxt1"); |
| 1419 | } |
| 1420 | |
| 1421 | if (!extensionEnabled("GL_EXT_texture_compression_dxt1")) |
| 1422 | { |
| 1423 | std::cout << "Test skipped because GL_EXT_texture_compression_dxt1 is not available." |
| 1424 | << std::endl; |
| 1425 | return; |
| 1426 | } |
| 1427 | |
| 1428 | constexpr uint8_t CompressedImageDXT1[] = {0x00, 0xf8, 0x00, 0xf8, 0xaa, 0xaa, 0xaa, 0xaa}; |
| 1429 | |
| 1430 | GLTexture texture; |
| 1431 | glBindTexture(GL_TEXTURE_2D, texture); |
| 1432 | |
| 1433 | // Regular case, verify that it works |
| 1434 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, |
| 1435 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1436 | ASSERT_GL_NO_ERROR(); |
| 1437 | |
| 1438 | // Test various dimensions that are not valid |
| 1439 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 3, 4, 0, |
| 1440 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1441 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 1442 | |
| 1443 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 3, 0, |
| 1444 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1445 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 1446 | |
| 1447 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0, |
| 1448 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1449 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 1450 | |
| 1451 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0, |
| 1452 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1453 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 1454 | |
| 1455 | // Test various image sizes that are not valid |
| 1456 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, |
| 1457 | sizeof(CompressedImageDXT1) - 1, CompressedImageDXT1); |
| 1458 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 1459 | |
| 1460 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, |
| 1461 | sizeof(CompressedImageDXT1) + 1, CompressedImageDXT1); |
| 1462 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 1463 | |
| 1464 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 0, |
| 1465 | CompressedImageDXT1); |
| 1466 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 1467 | |
| 1468 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0, 0, 0, |
| 1469 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1470 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 1471 | |
| 1472 | // Fill a full mip chain and verify that it works |
| 1473 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, |
| 1474 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1475 | glCompressedTexImage2D(GL_TEXTURE_2D, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 2, 2, 0, |
| 1476 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1477 | glCompressedTexImage2D(GL_TEXTURE_2D, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 1, 1, 0, |
| 1478 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1479 | ASSERT_GL_NO_ERROR(); |
| 1480 | |
| 1481 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 1482 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1483 | ASSERT_GL_NO_ERROR(); |
| 1484 | |
| 1485 | // Test that non-block size sub-uploads are not valid for the 0 mip |
| 1486 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 1487 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1488 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 1489 | |
| 1490 | // Test that non-block size sub-uploads are valid for if they fill the whole mip |
| 1491 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 2, 2, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 1492 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1493 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 2, 0, 0, 1, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
| 1494 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1495 | ASSERT_GL_NO_ERROR(); |
| 1496 | |
| 1497 | // Test that if the format miss-matches the texture, an error is generated |
| 1498 | glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 2, 2, 2, 2, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, |
| 1499 | sizeof(CompressedImageDXT1), CompressedImageDXT1); |
| 1500 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 1501 | } |
| 1502 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1503 | TEST_P(WebGLCompatibilityTest, L32FTextures) |
| 1504 | { |
| 1505 | constexpr float textureData[] = {15.1f, 0.0f, 0.0f, 0.0f}; |
| 1506 | constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], 1.0f}; |
| 1507 | |
| 1508 | for (auto extension : FloatingPointTextureExtensions) |
| 1509 | { |
| 1510 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1511 | { |
| 1512 | glRequestExtensionANGLE(extension); |
| 1513 | ASSERT_GL_NO_ERROR(); |
| 1514 | } |
| 1515 | |
| 1516 | // Unsized L 32F |
| 1517 | { |
| 1518 | bool texture = extensionEnabled("GL_OES_texture_float"); |
| 1519 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1520 | bool render = false; |
| 1521 | TestFloatTextureFormat(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT, texture, filter, render, |
| 1522 | textureData, readPixelData); |
| 1523 | } |
| 1524 | |
| 1525 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1526 | { |
| 1527 | // Sized L 32F |
| 1528 | bool texture = extensionEnabled("GL_OES_texture_float") && |
| 1529 | extensionEnabled("GL_EXT_texture_storage"); |
| 1530 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1531 | bool render = false; |
| 1532 | TestFloatTextureFormat(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT, texture, filter, |
| 1533 | render, textureData, readPixelData); |
| 1534 | } |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | TEST_P(WebGLCompatibilityTest, A32FTextures) |
| 1539 | { |
| 1540 | constexpr float textureData[] = {33.33f, 0.0f, 0.0f, 0.0f}; |
| 1541 | constexpr float readPixelData[] = {0.0f, 0.0f, 0.0f, textureData[0]}; |
| 1542 | |
| 1543 | for (auto extension : FloatingPointTextureExtensions) |
| 1544 | { |
| 1545 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1546 | { |
| 1547 | glRequestExtensionANGLE(extension); |
| 1548 | ASSERT_GL_NO_ERROR(); |
| 1549 | } |
| 1550 | |
| 1551 | // Unsized A 32F |
| 1552 | { |
| 1553 | bool texture = extensionEnabled("GL_OES_texture_float"); |
| 1554 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1555 | bool render = false; |
| 1556 | TestFloatTextureFormat(GL_ALPHA, GL_ALPHA, GL_FLOAT, texture, filter, render, |
| 1557 | textureData, readPixelData); |
| 1558 | } |
| 1559 | |
| 1560 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1561 | { |
| 1562 | // Sized A 32F |
| 1563 | bool texture = extensionEnabled("GL_OES_texture_float") && |
| 1564 | extensionEnabled("GL_EXT_texture_storage"); |
| 1565 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1566 | bool render = false; |
| 1567 | TestFloatTextureFormat(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT, texture, filter, render, |
| 1568 | textureData, readPixelData); |
| 1569 | } |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | TEST_P(WebGLCompatibilityTest, LA32FTextures) |
| 1574 | { |
| 1575 | constexpr float textureData[] = {-0.21f, 15.1f, 0.0f, 0.0f}; |
| 1576 | constexpr float readPixelData[] = {textureData[0], textureData[0], textureData[0], |
| 1577 | textureData[1]}; |
| 1578 | |
| 1579 | for (auto extension : FloatingPointTextureExtensions) |
| 1580 | { |
| 1581 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1582 | { |
| 1583 | glRequestExtensionANGLE(extension); |
| 1584 | ASSERT_GL_NO_ERROR(); |
| 1585 | } |
| 1586 | |
| 1587 | // Unsized LA 32F |
| 1588 | { |
| 1589 | bool texture = extensionEnabled("GL_OES_texture_float"); |
| 1590 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1591 | bool render = false; |
| 1592 | TestFloatTextureFormat(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT, texture, |
| 1593 | filter, render, textureData, readPixelData); |
| 1594 | } |
| 1595 | |
| 1596 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1597 | { |
| 1598 | // Sized LA 32F |
| 1599 | bool texture = extensionEnabled("GL_OES_texture_float") && |
| 1600 | extensionEnabled("GL_EXT_texture_storage"); |
| 1601 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1602 | bool render = false; |
| 1603 | TestFloatTextureFormat(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT, texture, |
| 1604 | filter, render, textureData, readPixelData); |
| 1605 | } |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | TEST_P(WebGLCompatibilityTest, R32FTextures) |
| 1610 | { |
| 1611 | constexpr float data[] = {1000.0f, 0.0f, 0.0f, 1.0f}; |
| 1612 | |
| 1613 | for (auto extension : FloatingPointTextureExtensions) |
| 1614 | { |
| 1615 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1616 | { |
| 1617 | glRequestExtensionANGLE(extension); |
| 1618 | ASSERT_GL_NO_ERROR(); |
| 1619 | } |
| 1620 | |
| 1621 | // Unsized R 32F |
| 1622 | { |
| 1623 | bool texture = |
| 1624 | extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg"); |
| 1625 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1626 | bool render = extensionEnabled("GL_EXT_color_buffer_float"); |
| 1627 | TestFloatTextureFormat(GL_RED, GL_RED, GL_FLOAT, texture, filter, render, data, data); |
| 1628 | } |
| 1629 | |
| 1630 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1631 | { |
| 1632 | // Sized R 32F |
| 1633 | bool texture = |
| 1634 | (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") && |
| 1635 | extensionEnabled("GL_EXT_texture_rg") && |
| 1636 | extensionEnabled("GL_EXT_texture_storage")); |
| 1637 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1638 | bool render = extensionEnabled("GL_EXT_color_buffer_float"); |
| 1639 | TestFloatTextureFormat(GL_R32F, GL_RED, GL_FLOAT, texture, filter, render, data, data); |
| 1640 | } |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | TEST_P(WebGLCompatibilityTest, RG32FTextures) |
| 1645 | { |
| 1646 | constexpr float data[] = {1000.0f, -0.001f, 0.0f, 1.0f}; |
| 1647 | |
| 1648 | for (auto extension : FloatingPointTextureExtensions) |
| 1649 | { |
| 1650 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1651 | { |
| 1652 | glRequestExtensionANGLE(extension); |
| 1653 | ASSERT_GL_NO_ERROR(); |
| 1654 | } |
| 1655 | |
| 1656 | // Unsized RG 32F |
| 1657 | { |
| 1658 | bool texture = |
| 1659 | (extensionEnabled("GL_OES_texture_float") && extensionEnabled("GL_EXT_texture_rg")); |
| 1660 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1661 | bool render = extensionEnabled("GL_EXT_color_buffer_float"); |
| 1662 | TestFloatTextureFormat(GL_RG, GL_RG, GL_FLOAT, texture, filter, render, data, data); |
| 1663 | } |
| 1664 | |
| 1665 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1666 | { |
| 1667 | // Sized RG 32F |
| 1668 | bool texture = |
| 1669 | (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") && |
| 1670 | extensionEnabled("GL_EXT_texture_rg") && |
| 1671 | extensionEnabled("GL_EXT_texture_storage")); |
| 1672 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1673 | bool render = extensionEnabled("GL_EXT_color_buffer_float"); |
| 1674 | TestFloatTextureFormat(GL_RG32F, GL_RG, GL_FLOAT, texture, filter, render, data, data); |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | TEST_P(WebGLCompatibilityTest, RGB32FTextures) |
| 1680 | { |
Geoff Lang | 40762ef | 2017-05-08 13:47:03 -0400 | [diff] [blame] | 1681 | if (IsLinux() && IsIntel()) |
| 1682 | { |
| 1683 | std::cout << "Test skipped on Linux Intel." << std::endl; |
| 1684 | return; |
| 1685 | } |
| 1686 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1687 | constexpr float data[] = {1000.0f, -500.0f, 10.0f, 1.0f}; |
| 1688 | |
| 1689 | for (auto extension : FloatingPointTextureExtensions) |
| 1690 | { |
| 1691 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1692 | { |
| 1693 | glRequestExtensionANGLE(extension); |
| 1694 | ASSERT_GL_NO_ERROR(); |
| 1695 | } |
| 1696 | |
| 1697 | // Unsized RGB 32F |
| 1698 | { |
| 1699 | bool texture = extensionEnabled("GL_OES_texture_float"); |
| 1700 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1701 | bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"); |
| 1702 | TestFloatTextureFormat(GL_RGB, GL_RGB, GL_FLOAT, texture, filter, render, data, data); |
| 1703 | } |
| 1704 | |
| 1705 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1706 | { |
| 1707 | // Sized RGBA 32F |
| 1708 | bool texture = |
| 1709 | (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") && |
| 1710 | extensionEnabled("GL_EXT_texture_storage")); |
| 1711 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1712 | bool render = extensionEnabled("GL_CHROMIUM_color_buffer_float_rgb"); |
| 1713 | TestFloatTextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, texture, filter, render, data, |
| 1714 | data); |
| 1715 | } |
| 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | TEST_P(WebGLCompatibilityTest, RGBA32FTextures) |
| 1720 | { |
| 1721 | constexpr float data[] = {7000.0f, 100.0f, 33.0f, -1.0f}; |
| 1722 | |
| 1723 | for (auto extension : FloatingPointTextureExtensions) |
| 1724 | { |
| 1725 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1726 | { |
| 1727 | glRequestExtensionANGLE(extension); |
| 1728 | ASSERT_GL_NO_ERROR(); |
| 1729 | } |
| 1730 | |
| 1731 | // Unsized RGBA 32F |
| 1732 | { |
| 1733 | bool texture = extensionEnabled("GL_OES_texture_float"); |
| 1734 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1735 | bool render = extensionEnabled("GL_EXT_color_buffer_float") || |
| 1736 | extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"); |
| 1737 | TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_FLOAT, texture, filter, render, data, data); |
| 1738 | } |
| 1739 | |
| 1740 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1741 | { |
| 1742 | // Sized RGBA 32F |
| 1743 | bool texture = |
| 1744 | (getClientMajorVersion() >= 3) || (extensionEnabled("GL_OES_texture_float") && |
| 1745 | extensionEnabled("GL_EXT_texture_storage")); |
| 1746 | bool filter = extensionEnabled("GL_OES_texture_float_linear"); |
| 1747 | bool render = extensionEnabled("GL_EXT_color_buffer_float") || |
| 1748 | extensionEnabled("GL_CHROMIUM_color_buffer_float_rgba"); |
| 1749 | TestFloatTextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, texture, filter, render, data, |
| 1750 | data); |
| 1751 | } |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | TEST_P(WebGLCompatibilityTest, R16FTextures) |
| 1756 | { |
| 1757 | constexpr float readPixelsData[] = {-5000.0f, 0.0f, 0.0f, 1.0f}; |
| 1758 | const GLushort textureData[] = { |
| 1759 | gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]), |
| 1760 | gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])}; |
| 1761 | |
| 1762 | for (auto extension : FloatingPointTextureExtensions) |
| 1763 | { |
| 1764 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1765 | { |
| 1766 | glRequestExtensionANGLE(extension); |
| 1767 | ASSERT_GL_NO_ERROR(); |
| 1768 | } |
| 1769 | |
| 1770 | // Unsized R 16F (OES) |
| 1771 | { |
| 1772 | bool texture = extensionEnabled("GL_OES_texture_half_float") && |
| 1773 | extensionEnabled("GL_EXT_texture_rg"); |
| 1774 | bool filter = getClientMajorVersion() >= 3 || |
| 1775 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1776 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float"); |
| 1777 | TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT_OES, texture, filter, render, |
| 1778 | textureData, readPixelsData); |
| 1779 | } |
| 1780 | |
| 1781 | // Unsized R 16F |
| 1782 | { |
| 1783 | bool texture = false; |
| 1784 | bool filter = false; |
| 1785 | bool render = false; |
| 1786 | TestFloatTextureFormat(GL_RED, GL_RED, GL_HALF_FLOAT, texture, filter, render, |
| 1787 | textureData, readPixelsData); |
| 1788 | } |
| 1789 | |
| 1790 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1791 | { |
| 1792 | // Sized R 16F |
| 1793 | bool texture = getClientMajorVersion() >= 3; |
| 1794 | bool filter = getClientMajorVersion() >= 3 || |
| 1795 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1796 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float") || |
| 1797 | extensionEnabled("GL_EXT_color_buffer_float"); |
| 1798 | TestFloatTextureFormat(GL_R16F, GL_RED, GL_HALF_FLOAT, texture, filter, render, |
| 1799 | textureData, readPixelsData); |
| 1800 | } |
| 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | TEST_P(WebGLCompatibilityTest, RG16FTextures) |
| 1805 | { |
| 1806 | constexpr float readPixelsData[] = {7108.0f, -10.0f, 0.0f, 1.0f}; |
| 1807 | const GLushort textureData[] = { |
| 1808 | gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]), |
| 1809 | gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])}; |
| 1810 | |
| 1811 | for (auto extension : FloatingPointTextureExtensions) |
| 1812 | { |
| 1813 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1814 | { |
| 1815 | glRequestExtensionANGLE(extension); |
| 1816 | ASSERT_GL_NO_ERROR(); |
| 1817 | } |
| 1818 | |
| 1819 | // Unsized RG 16F (OES) |
| 1820 | { |
| 1821 | bool texture = extensionEnabled("GL_OES_texture_half_float") && |
| 1822 | extensionEnabled("GL_EXT_texture_rg"); |
| 1823 | bool filter = getClientMajorVersion() >= 3 || |
| 1824 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1825 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float") && |
| 1826 | extensionEnabled("GL_EXT_texture_rg"); |
| 1827 | TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT_OES, texture, filter, render, |
| 1828 | textureData, readPixelsData); |
| 1829 | } |
| 1830 | |
| 1831 | // Unsized RG 16F |
| 1832 | { |
| 1833 | bool texture = false; |
| 1834 | bool filter = false; |
| 1835 | bool render = false; |
| 1836 | TestFloatTextureFormat(GL_RG, GL_RG, GL_HALF_FLOAT, texture, filter, render, |
| 1837 | textureData, readPixelsData); |
| 1838 | } |
| 1839 | |
| 1840 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1841 | { |
| 1842 | // Sized RG 16F |
| 1843 | bool texture = getClientMajorVersion() >= 3; |
| 1844 | bool filter = getClientMajorVersion() >= 3 || |
| 1845 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1846 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float") || |
| 1847 | extensionEnabled("GL_EXT_color_buffer_float"); |
| 1848 | TestFloatTextureFormat(GL_RG16F, GL_RG, GL_HALF_FLOAT, texture, filter, render, |
| 1849 | textureData, readPixelsData); |
| 1850 | } |
| 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | TEST_P(WebGLCompatibilityTest, RGB16FTextures) |
| 1855 | { |
Geoff Lang | 40762ef | 2017-05-08 13:47:03 -0400 | [diff] [blame] | 1856 | if (IsOzone() && IsIntel()) |
| 1857 | { |
| 1858 | std::cout << "Test skipped on Intel Ozone." << std::endl; |
| 1859 | return; |
| 1860 | } |
| 1861 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1862 | constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, 1.0f}; |
| 1863 | const GLushort textureData[] = { |
| 1864 | gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]), |
| 1865 | gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])}; |
| 1866 | |
| 1867 | for (auto extension : FloatingPointTextureExtensions) |
| 1868 | { |
| 1869 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1870 | { |
| 1871 | glRequestExtensionANGLE(extension); |
| 1872 | ASSERT_GL_NO_ERROR(); |
| 1873 | } |
| 1874 | |
| 1875 | // Unsized RGB 16F (OES) |
| 1876 | { |
| 1877 | bool texture = extensionEnabled("GL_OES_texture_half_float"); |
| 1878 | bool filter = getClientMajorVersion() >= 3 || |
| 1879 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1880 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float"); |
| 1881 | TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT_OES, texture, filter, render, |
| 1882 | textureData, readPixelsData); |
| 1883 | } |
| 1884 | |
| 1885 | // Unsized RGB 16F |
| 1886 | { |
| 1887 | bool texture = false; |
| 1888 | bool filter = false; |
| 1889 | bool render = false; |
| 1890 | TestFloatTextureFormat(GL_RGB, GL_RGB, GL_HALF_FLOAT, texture, filter, render, |
| 1891 | textureData, readPixelsData); |
| 1892 | } |
| 1893 | |
| 1894 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1895 | { |
| 1896 | // Sized RGB 16F |
| 1897 | bool texture = getClientMajorVersion() >= 3; |
| 1898 | bool filter = getClientMajorVersion() >= 3 || |
| 1899 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1900 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float"); |
| 1901 | TestFloatTextureFormat(GL_RGB16F, GL_RGB, GL_HALF_FLOAT, texture, filter, render, |
| 1902 | textureData, readPixelsData); |
| 1903 | } |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | TEST_P(WebGLCompatibilityTest, RGBA16FTextures) |
| 1908 | { |
Geoff Lang | 40762ef | 2017-05-08 13:47:03 -0400 | [diff] [blame] | 1909 | if (IsOzone() && IsIntel()) |
| 1910 | { |
| 1911 | std::cout << "Test skipped on Intel Ozone." << std::endl; |
| 1912 | return; |
| 1913 | } |
| 1914 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 1915 | constexpr float readPixelsData[] = {7000.0f, 100.0f, 33.0f, -1.0f}; |
| 1916 | const GLushort textureData[] = { |
| 1917 | gl::float32ToFloat16(readPixelsData[0]), gl::float32ToFloat16(readPixelsData[1]), |
| 1918 | gl::float32ToFloat16(readPixelsData[2]), gl::float32ToFloat16(readPixelsData[3])}; |
| 1919 | |
| 1920 | for (auto extension : FloatingPointTextureExtensions) |
| 1921 | { |
| 1922 | if (strlen(extension) > 0 && extensionRequestable(extension)) |
| 1923 | { |
| 1924 | glRequestExtensionANGLE(extension); |
| 1925 | ASSERT_GL_NO_ERROR(); |
| 1926 | } |
| 1927 | |
| 1928 | // Unsized RGBA 16F (OES) |
| 1929 | { |
| 1930 | bool texture = extensionEnabled("GL_OES_texture_half_float"); |
| 1931 | bool filter = getClientMajorVersion() >= 3 || |
| 1932 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1933 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float") || |
| 1934 | extensionEnabled("GL_EXT_color_buffer_float"); |
| 1935 | TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT_OES, texture, filter, render, |
| 1936 | textureData, readPixelsData); |
| 1937 | } |
| 1938 | |
| 1939 | // Unsized RGBA 16F |
| 1940 | { |
| 1941 | bool texture = false; |
| 1942 | bool filter = false; |
| 1943 | bool render = false; |
| 1944 | TestFloatTextureFormat(GL_RGBA, GL_RGBA, GL_HALF_FLOAT, texture, filter, render, |
| 1945 | textureData, readPixelsData); |
| 1946 | } |
| 1947 | |
| 1948 | if (getClientMajorVersion() >= 3 || extensionEnabled("GL_EXT_texture_storage")) |
| 1949 | { |
| 1950 | // Sized RGBA 16F |
| 1951 | bool texture = getClientMajorVersion() >= 3; |
| 1952 | bool filter = getClientMajorVersion() >= 3 || |
| 1953 | extensionEnabled("GL_OES_texture_half_float_linear"); |
| 1954 | bool render = extensionEnabled("GL_EXT_color_buffer_half_float") || |
| 1955 | extensionEnabled("GL_EXT_color_buffer_float"); |
| 1956 | TestFloatTextureFormat(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, texture, filter, render, |
| 1957 | textureData, readPixelsData); |
| 1958 | } |
| 1959 | } |
| 1960 | } |
| 1961 | |
Jamie Madill | 07be8bf | 2017-02-02 19:59:57 -0500 | [diff] [blame] | 1962 | // This tests that rendering feedback loops works as expected with WebGL 2. |
| 1963 | // Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html |
| 1964 | TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers) |
| 1965 | { |
| 1966 | const std::string vertexShader = |
| 1967 | "#version 300 es\n" |
| 1968 | "in vec4 aPosition;\n" |
| 1969 | "out vec2 texCoord;\n" |
| 1970 | "void main() {\n" |
| 1971 | " gl_Position = aPosition;\n" |
| 1972 | " texCoord = (aPosition.xy * 0.5) + 0.5;\n" |
| 1973 | "}\n"; |
| 1974 | |
| 1975 | const std::string fragmentShader = |
| 1976 | "#version 300 es\n" |
| 1977 | "precision mediump float;\n" |
| 1978 | "uniform sampler2D tex;\n" |
| 1979 | "in vec2 texCoord;\n" |
| 1980 | "out vec4 oColor;\n" |
| 1981 | "void main() {\n" |
| 1982 | " oColor = texture(tex, texCoord);\n" |
| 1983 | "}\n"; |
| 1984 | |
| 1985 | GLsizei width = 8; |
| 1986 | GLsizei height = 8; |
| 1987 | |
| 1988 | GLint maxDrawBuffers = 0; |
| 1989 | glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
| 1990 | // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS. |
| 1991 | ASSERT_GE(maxDrawBuffers, 2); |
| 1992 | |
| 1993 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 1994 | glUseProgram(program.get()); |
| 1995 | glViewport(0, 0, width, height); |
| 1996 | |
| 1997 | GLTexture tex0; |
| 1998 | GLTexture tex1; |
| 1999 | GLFramebuffer fbo; |
| 2000 | FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 2001 | FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 2002 | ASSERT_GL_NO_ERROR(); |
| 2003 | |
| 2004 | glBindTexture(GL_TEXTURE_2D, tex1.get()); |
| 2005 | GLint texLoc = glGetUniformLocation(program.get(), "tex"); |
| 2006 | ASSERT_NE(-1, texLoc); |
| 2007 | glUniform1i(texLoc, 0); |
| 2008 | |
| 2009 | // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation |
| 2010 | glBindFramebuffer(GL_FRAMEBUFFER, fbo.get()); |
| 2011 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0); |
| 2012 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0); |
| 2013 | ASSERT_GL_NO_ERROR(); |
| 2014 | |
| 2015 | drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION); |
| 2016 | drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}}, |
| 2017 | GL_INVALID_OPERATION); |
| 2018 | drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR); |
| 2019 | } |
| 2020 | |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 2021 | // This test covers detection of rendering feedback loops between the FBO and a depth Texture. |
| 2022 | // Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html |
| 2023 | TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil) |
| 2024 | { |
| 2025 | const std::string vertexShader = |
| 2026 | "#version 300 es\n" |
| 2027 | "in vec4 aPosition;\n" |
| 2028 | "out vec2 texCoord;\n" |
| 2029 | "void main() {\n" |
| 2030 | " gl_Position = aPosition;\n" |
| 2031 | " texCoord = (aPosition.xy * 0.5) + 0.5;\n" |
| 2032 | "}\n"; |
| 2033 | |
| 2034 | const std::string fragmentShader = |
| 2035 | "#version 300 es\n" |
| 2036 | "precision mediump float;\n" |
| 2037 | "uniform sampler2D tex;\n" |
| 2038 | "in vec2 texCoord;\n" |
| 2039 | "out vec4 oColor;\n" |
| 2040 | "void main() {\n" |
| 2041 | " oColor = texture(tex, texCoord);\n" |
| 2042 | "}\n"; |
| 2043 | |
| 2044 | GLsizei width = 8; |
| 2045 | GLsizei height = 8; |
| 2046 | |
| 2047 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 2048 | glUseProgram(program.get()); |
| 2049 | |
| 2050 | glViewport(0, 0, width, height); |
| 2051 | |
| 2052 | GLint texLoc = glGetUniformLocation(program.get(), "tex"); |
| 2053 | glUniform1i(texLoc, 0); |
| 2054 | |
| 2055 | // Create textures and allocate storage |
| 2056 | GLTexture tex0; |
| 2057 | GLTexture tex1; |
| 2058 | GLRenderbuffer rb; |
| 2059 | FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 2060 | FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, |
| 2061 | GL_UNSIGNED_INT); |
| 2062 | glBindRenderbuffer(GL_RENDERBUFFER, rb.get()); |
| 2063 | glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height); |
| 2064 | ASSERT_GL_NO_ERROR(); |
| 2065 | |
| 2066 | GLFramebuffer fbo; |
| 2067 | glBindFramebuffer(GL_FRAMEBUFFER, fbo.get()); |
| 2068 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0); |
| 2069 | |
| 2070 | // Test rendering and sampling feedback loop for depth buffer |
| 2071 | glBindTexture(GL_TEXTURE_2D, tex1.get()); |
| 2072 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0); |
| 2073 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 2074 | |
| 2075 | // The same image is used as depth buffer during rendering. |
| 2076 | glEnable(GL_DEPTH_TEST); |
| 2077 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 2078 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2079 | |
| 2080 | // The same image is used as depth buffer. But depth mask is false. |
| 2081 | glDepthMask(GL_FALSE); |
| 2082 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 2083 | EXPECT_GL_NO_ERROR(); |
| 2084 | |
| 2085 | // The same image is used as depth buffer. But depth test is not enabled during rendering. |
| 2086 | glDepthMask(GL_TRUE); |
| 2087 | glDisable(GL_DEPTH_TEST); |
| 2088 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 2089 | EXPECT_GL_NO_ERROR(); |
| 2090 | |
| 2091 | // Test rendering and sampling feedback loop for stencil buffer |
| 2092 | glBindTexture(GL_RENDERBUFFER, rb.get()); |
| 2093 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); |
| 2094 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get()); |
| 2095 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 2096 | constexpr GLint stencilClearValue = 0x40; |
| 2097 | glClearBufferiv(GL_STENCIL, 0, &stencilClearValue); |
| 2098 | |
| 2099 | // The same image is used as stencil buffer during rendering. |
| 2100 | glEnable(GL_STENCIL_TEST); |
| 2101 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 2102 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2103 | |
| 2104 | // The same image is used as stencil buffer. But stencil mask is zero. |
| 2105 | glStencilMask(0x0); |
| 2106 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 2107 | EXPECT_GL_NO_ERROR(); |
| 2108 | |
| 2109 | // The same image is used as stencil buffer. But stencil test is not enabled during rendering. |
| 2110 | glStencilMask(0xffff); |
| 2111 | glDisable(GL_STENCIL_TEST); |
| 2112 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 2113 | EXPECT_GL_NO_ERROR(); |
| 2114 | } |
| 2115 | |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2116 | // The source and the target for CopyTexSubImage3D are the same 3D texture. |
| 2117 | // But the level of the 3D texture != the level of the read attachment. |
| 2118 | TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels) |
| 2119 | { |
| 2120 | GLTexture texture; |
| 2121 | GLFramebuffer framebuffer; |
| 2122 | |
| 2123 | glBindTexture(GL_TEXTURE_3D, texture.get()); |
| 2124 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 2125 | |
| 2126 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 2127 | glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 2128 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0); |
| 2129 | ASSERT_GL_NO_ERROR(); |
| 2130 | |
| 2131 | glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2); |
| 2132 | EXPECT_GL_NO_ERROR(); |
| 2133 | } |
| 2134 | |
| 2135 | // The source and the target for CopyTexSubImage3D are the same 3D texture. |
| 2136 | // But the zoffset of the 3D texture != the layer of the read attachment. |
| 2137 | TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers) |
| 2138 | { |
| 2139 | GLTexture texture; |
| 2140 | GLFramebuffer framebuffer; |
| 2141 | |
| 2142 | glBindTexture(GL_TEXTURE_3D, texture.get()); |
| 2143 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 2144 | |
| 2145 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 2146 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1); |
| 2147 | ASSERT_GL_NO_ERROR(); |
| 2148 | |
| 2149 | glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2); |
| 2150 | EXPECT_GL_NO_ERROR(); |
| 2151 | } |
| 2152 | |
| 2153 | // The source and the target for CopyTexSubImage3D are the same 3D texture. |
| 2154 | // And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment. |
| 2155 | TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D) |
| 2156 | { |
| 2157 | GLTexture texture; |
| 2158 | GLFramebuffer framebuffer; |
| 2159 | |
| 2160 | glBindTexture(GL_TEXTURE_3D, texture.get()); |
| 2161 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 2162 | |
| 2163 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 2164 | glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 2165 | glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 2166 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0); |
| 2167 | ASSERT_GL_NO_ERROR(); |
| 2168 | |
| 2169 | glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2); |
| 2170 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2171 | } |
| 2172 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2173 | // Verify that errors are generated when there isn not a defined conversion between the clear type |
| 2174 | // and the buffer type. |
| 2175 | TEST_P(WebGL2CompatibilityTest, ClearBufferTypeCompatibity) |
| 2176 | { |
| 2177 | if (IsD3D11()) |
| 2178 | { |
| 2179 | std::cout << "Test skipped because it generates D3D11 runtime warnings." << std::endl; |
| 2180 | return; |
| 2181 | } |
| 2182 | |
| 2183 | constexpr float clearFloat[] = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 2184 | constexpr int clearInt[] = {0, 0, 0, 0}; |
| 2185 | constexpr unsigned int clearUint[] = {0, 0, 0, 0}; |
| 2186 | |
| 2187 | GLTexture texture; |
| 2188 | GLFramebuffer framebuffer; |
| 2189 | |
| 2190 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 2191 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 2192 | |
| 2193 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 2194 | ASSERT_GL_NO_ERROR(); |
| 2195 | |
| 2196 | // Unsigned integer buffer |
| 2197 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, 1, 1, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, nullptr); |
| 2198 | ASSERT_GL_NO_ERROR(); |
| 2199 | |
| 2200 | glClearBufferfv(GL_COLOR, 0, clearFloat); |
| 2201 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2202 | |
| 2203 | glClearBufferiv(GL_COLOR, 0, clearInt); |
| 2204 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2205 | |
| 2206 | glClearBufferuiv(GL_COLOR, 0, clearUint); |
| 2207 | EXPECT_GL_NO_ERROR(); |
| 2208 | |
| 2209 | glClear(GL_COLOR_BUFFER_BIT); |
| 2210 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2211 | |
| 2212 | // Integer buffer |
| 2213 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32I, 1, 1, 0, GL_RGBA_INTEGER, GL_INT, nullptr); |
| 2214 | ASSERT_GL_NO_ERROR(); |
| 2215 | |
| 2216 | glClearBufferfv(GL_COLOR, 0, clearFloat); |
| 2217 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2218 | |
| 2219 | glClearBufferiv(GL_COLOR, 0, clearInt); |
| 2220 | EXPECT_GL_NO_ERROR(); |
| 2221 | |
| 2222 | glClearBufferuiv(GL_COLOR, 0, clearUint); |
| 2223 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2224 | |
| 2225 | glClear(GL_COLOR_BUFFER_BIT); |
| 2226 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2227 | |
| 2228 | // Float buffer |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2229 | if (extensionRequestable("GL_EXT_color_buffer_float")) |
| 2230 | { |
| 2231 | glRequestExtensionANGLE("GL_EXT_color_buffer_float"); |
| 2232 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2233 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2234 | if (extensionEnabled("GL_EXT_color_buffer_float")) |
| 2235 | { |
| 2236 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1, 1, 0, GL_RGBA, GL_FLOAT, nullptr); |
| 2237 | ASSERT_GL_NO_ERROR(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2238 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2239 | glClearBufferfv(GL_COLOR, 0, clearFloat); |
| 2240 | EXPECT_GL_NO_ERROR(); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2241 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2242 | glClearBufferiv(GL_COLOR, 0, clearInt); |
| 2243 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2244 | |
Geoff Lang | 677bb6f | 2017-04-05 12:40:40 -0400 | [diff] [blame] | 2245 | glClearBufferuiv(GL_COLOR, 0, clearUint); |
| 2246 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2247 | |
| 2248 | glClear(GL_COLOR_BUFFER_BIT); |
| 2249 | EXPECT_GL_NO_ERROR(); |
| 2250 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 2251 | |
| 2252 | // Normalized uint buffer |
| 2253 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 2254 | ASSERT_GL_NO_ERROR(); |
| 2255 | |
| 2256 | glClearBufferfv(GL_COLOR, 0, clearFloat); |
| 2257 | EXPECT_GL_NO_ERROR(); |
| 2258 | |
| 2259 | glClearBufferiv(GL_COLOR, 0, clearInt); |
| 2260 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2261 | |
| 2262 | glClearBufferuiv(GL_COLOR, 0, clearUint); |
| 2263 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2264 | |
| 2265 | glClear(GL_COLOR_BUFFER_BIT); |
| 2266 | EXPECT_GL_NO_ERROR(); |
| 2267 | } |
| 2268 | |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 2269 | // Verify that errors are generate when trying to blit from an image to itself |
| 2270 | TEST_P(WebGL2CompatibilityTest, BlitFramebufferSameImage) |
| 2271 | { |
| 2272 | GLTexture textures[2]; |
| 2273 | glBindTexture(GL_TEXTURE_2D, textures[0]); |
| 2274 | glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4); |
| 2275 | glBindTexture(GL_TEXTURE_2D, textures[1]); |
| 2276 | glTexStorage2D(GL_TEXTURE_2D, 3, GL_RGBA8, 4, 4); |
| 2277 | |
| 2278 | GLRenderbuffer renderbuffers[2]; |
| 2279 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[0]); |
| 2280 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4); |
| 2281 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffers[1]); |
| 2282 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 4, 4); |
| 2283 | |
| 2284 | GLFramebuffer framebuffers[2]; |
| 2285 | glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffers[0]); |
| 2286 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffers[1]); |
| 2287 | |
| 2288 | ASSERT_GL_NO_ERROR(); |
| 2289 | |
| 2290 | // Same texture |
| 2291 | glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], |
| 2292 | 0); |
| 2293 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], |
| 2294 | 0); |
| 2295 | ASSERT_GL_NO_ERROR(); |
| 2296 | glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 2297 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 2298 | |
| 2299 | // Same textures but different renderbuffers |
| 2300 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 2301 | renderbuffers[0]); |
| 2302 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 2303 | renderbuffers[1]); |
| 2304 | ASSERT_GL_NO_ERROR(); |
| 2305 | glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT, GL_NEAREST); |
| 2306 | ASSERT_GL_NO_ERROR(); |
| 2307 | glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, |
| 2308 | GL_NEAREST); |
| 2309 | ASSERT_GL_NO_ERROR(); |
| 2310 | glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, |
| 2311 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, |
| 2312 | GL_NEAREST); |
| 2313 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 2314 | |
| 2315 | // Same renderbuffers but different textures |
| 2316 | glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], |
| 2317 | 0); |
| 2318 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], |
| 2319 | 0); |
| 2320 | glFramebufferRenderbuffer(GL_READ_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 2321 | renderbuffers[0]); |
| 2322 | glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 2323 | renderbuffers[0]); |
| 2324 | ASSERT_GL_NO_ERROR(); |
| 2325 | glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 2326 | ASSERT_GL_NO_ERROR(); |
| 2327 | glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, |
| 2328 | GL_NEAREST); |
| 2329 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 2330 | glBlitFramebuffer(0, 0, 4, 4, 0, 0, 4, 4, |
| 2331 | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, |
| 2332 | GL_NEAREST); |
| 2333 | ASSERT_GL_ERROR(GL_INVALID_OPERATION); |
| 2334 | } |
| 2335 | |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame^] | 2336 | // Verify that errors are generated when the fragment shader output doesn't match the bound color |
| 2337 | // buffer types |
| 2338 | TEST_P(WebGL2CompatibilityTest, FragmentShaderColorBufferTypeMissmatch) |
| 2339 | { |
| 2340 | const std::string vertexShader = |
| 2341 | "#version 300 es\n" |
| 2342 | "void main() {\n" |
| 2343 | " gl_Position = vec4(0, 0, 0, 1);\n" |
| 2344 | "}\n"; |
| 2345 | |
| 2346 | const std::string fragmentShader = |
| 2347 | "#version 300 es\n" |
| 2348 | "precision mediump float;\n" |
| 2349 | "layout(location = 0) out vec4 floatOutput;\n" |
| 2350 | "layout(location = 1) out uvec4 uintOutput;\n" |
| 2351 | "layout(location = 2) out ivec4 intOutput;\n" |
| 2352 | "void main() {\n" |
| 2353 | " floatOutput = vec4(0, 0, 0, 1);\n" |
| 2354 | " uintOutput = uvec4(0, 0, 0, 1);\n" |
| 2355 | " intOutput = ivec4(0, 0, 0, 1);\n" |
| 2356 | "}\n"; |
| 2357 | |
| 2358 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 2359 | glUseProgram(program.get()); |
| 2360 | |
| 2361 | GLuint floatLocation = glGetFragDataLocation(program, "floatOutput"); |
| 2362 | GLuint uintLocation = glGetFragDataLocation(program, "uintOutput"); |
| 2363 | GLuint intLocation = glGetFragDataLocation(program, "intOutput"); |
| 2364 | |
| 2365 | GLFramebuffer fbo; |
| 2366 | glBindFramebuffer(GL_FRAMEBUFFER, fbo); |
| 2367 | |
| 2368 | GLRenderbuffer floatRenderbuffer; |
| 2369 | glBindRenderbuffer(GL_RENDERBUFFER, floatRenderbuffer); |
| 2370 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 1, 1); |
| 2371 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER, |
| 2372 | floatRenderbuffer); |
| 2373 | |
| 2374 | GLRenderbuffer uintRenderbuffer; |
| 2375 | glBindRenderbuffer(GL_RENDERBUFFER, uintRenderbuffer); |
| 2376 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8UI, 1, 1); |
| 2377 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER, |
| 2378 | uintRenderbuffer); |
| 2379 | |
| 2380 | GLRenderbuffer intRenderbuffer; |
| 2381 | glBindRenderbuffer(GL_RENDERBUFFER, intRenderbuffer); |
| 2382 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8I, 1, 1); |
| 2383 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER, |
| 2384 | intRenderbuffer); |
| 2385 | |
| 2386 | ASSERT_GL_NO_ERROR(); |
| 2387 | |
| 2388 | GLint maxDrawBuffers = 0; |
| 2389 | glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
| 2390 | std::vector<GLenum> drawBuffers(static_cast<size_t>(maxDrawBuffers), GL_NONE); |
| 2391 | drawBuffers[floatLocation] = GL_COLOR_ATTACHMENT0 + floatLocation; |
| 2392 | drawBuffers[uintLocation] = GL_COLOR_ATTACHMENT0 + uintLocation; |
| 2393 | drawBuffers[intLocation] = GL_COLOR_ATTACHMENT0 + intLocation; |
| 2394 | |
| 2395 | glDrawBuffers(maxDrawBuffers, drawBuffers.data()); |
| 2396 | |
| 2397 | // Check that the correct case generates no errors |
| 2398 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 2399 | EXPECT_GL_NO_ERROR(); |
| 2400 | |
| 2401 | // Unbind some buffers and verify that there are still no errors |
| 2402 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER, |
| 2403 | 0); |
| 2404 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER, |
| 2405 | 0); |
| 2406 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 2407 | EXPECT_GL_NO_ERROR(); |
| 2408 | |
| 2409 | // Swap the int and uint buffers to and verify that an error is generated |
| 2410 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER, |
| 2411 | intRenderbuffer); |
| 2412 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER, |
| 2413 | uintRenderbuffer); |
| 2414 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 2415 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2416 | |
| 2417 | // Swap the float and uint buffers to and verify that an error is generated |
| 2418 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + uintLocation, GL_RENDERBUFFER, |
| 2419 | floatRenderbuffer); |
| 2420 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + floatLocation, GL_RENDERBUFFER, |
| 2421 | uintRenderbuffer); |
| 2422 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + intLocation, GL_RENDERBUFFER, |
| 2423 | intRenderbuffer); |
| 2424 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 2425 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 2426 | } |
| 2427 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2428 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 2429 | // tests should be run against. |
| 2430 | ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest, |
| 2431 | ES2_D3D9(), |
| 2432 | ES2_D3D11(), |
| 2433 | ES3_D3D11(), |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2434 | ES2_OPENGL(), |
| 2435 | ES3_OPENGL(), |
| 2436 | ES2_OPENGLES(), |
| 2437 | ES3_OPENGLES()); |
| 2438 | |
Jamie Madill | 07be8bf | 2017-02-02 19:59:57 -0500 | [diff] [blame] | 2439 | ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2440 | } // namespace |