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 | |
| 11 | #include "test_utils/gl_raii.h" |
| 12 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 13 | namespace |
| 14 | { |
| 15 | |
| 16 | bool ConstantColorAndAlphaBlendFunctions(GLenum first, GLenum second) |
| 17 | { |
| 18 | return (first == GL_CONSTANT_COLOR || first == GL_ONE_MINUS_CONSTANT_COLOR) && |
| 19 | (second == GL_CONSTANT_ALPHA || second == GL_ONE_MINUS_CONSTANT_ALPHA); |
| 20 | } |
| 21 | |
| 22 | void CheckBlendFunctions(GLenum src, GLenum dst) |
| 23 | { |
| 24 | if (ConstantColorAndAlphaBlendFunctions(src, dst) || |
| 25 | ConstantColorAndAlphaBlendFunctions(dst, src)) |
| 26 | { |
| 27 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 28 | } |
| 29 | else |
| 30 | { |
| 31 | ASSERT_GL_NO_ERROR(); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | } // namespace |
| 36 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 37 | namespace angle |
| 38 | { |
| 39 | |
| 40 | class WebGLCompatibilityTest : public ANGLETest |
| 41 | { |
| 42 | protected: |
| 43 | WebGLCompatibilityTest() |
| 44 | { |
| 45 | setWindowWidth(128); |
| 46 | setWindowHeight(128); |
| 47 | setConfigRedBits(8); |
| 48 | setConfigGreenBits(8); |
| 49 | setConfigBlueBits(8); |
| 50 | setConfigAlphaBits(8); |
| 51 | setWebGLCompatibilityEnabled(true); |
| 52 | } |
| 53 | |
| 54 | void SetUp() override |
| 55 | { |
| 56 | ANGLETest::SetUp(); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 57 | glRequestExtensionANGLE = reinterpret_cast<PFNGLREQUESTEXTENSIONANGLEPROC>( |
| 58 | eglGetProcAddress("glRequestExtensionANGLE")); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void TearDown() override { ANGLETest::TearDown(); } |
| 62 | |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 63 | // Called from RenderingFeedbackLoopWithDrawBuffersEXT. |
| 64 | void drawBuffersEXTFeedbackLoop(GLuint program, |
| 65 | const std::array<GLenum, 2> &drawBuffers, |
| 66 | GLenum expectedError); |
| 67 | |
Jamie Madill | 07be8bf | 2017-02-02 19:59:57 -0500 | [diff] [blame] | 68 | // Called from RenderingFeedbackLoopWithDrawBuffers. |
| 69 | void drawBuffersFeedbackLoop(GLuint program, |
| 70 | const std::array<GLenum, 2> &drawBuffers, |
| 71 | GLenum expectedError); |
| 72 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 73 | PFNGLREQUESTEXTENSIONANGLEPROC glRequestExtensionANGLE = nullptr; |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 74 | }; |
| 75 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 76 | class WebGL2CompatibilityTest : public WebGLCompatibilityTest |
| 77 | { |
| 78 | }; |
| 79 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 80 | // Context creation would fail if EGL_ANGLE_create_context_webgl_compatibility was not available so |
| 81 | // the GL extension should always be present |
| 82 | TEST_P(WebGLCompatibilityTest, ExtensionStringExposed) |
| 83 | { |
| 84 | EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility")); |
| 85 | } |
| 86 | |
| 87 | // Verify that all extension entry points are available |
| 88 | TEST_P(WebGLCompatibilityTest, EntryPoints) |
| 89 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 90 | if (extensionEnabled("GL_ANGLE_request_extension")) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 91 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 92 | EXPECT_NE(nullptr, eglGetProcAddress("glRequestExtensionANGLE")); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
| 96 | // WebGL 1 allows GL_DEPTH_STENCIL_ATTACHMENT as a valid binding point. Make sure it is usable, |
| 97 | // even in ES2 contexts. |
| 98 | TEST_P(WebGLCompatibilityTest, DepthStencilBindingPoint) |
| 99 | { |
| 100 | GLRenderbuffer renderbuffer; |
| 101 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get()); |
| 102 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32); |
| 103 | |
| 104 | GLFramebuffer framebuffer; |
| 105 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 106 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 107 | renderbuffer.get()); |
| 108 | |
| 109 | EXPECT_GL_NO_ERROR(); |
| 110 | } |
| 111 | |
| 112 | // Test that attempting to enable an extension that doesn't exist generates GL_INVALID_OPERATION |
| 113 | TEST_P(WebGLCompatibilityTest, EnableExtensionValidation) |
| 114 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 115 | glRequestExtensionANGLE("invalid_extension_string"); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 116 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 117 | } |
| 118 | |
| 119 | // Test enabling the GL_OES_element_index_uint extension |
| 120 | TEST_P(WebGLCompatibilityTest, EnableExtensionUintIndices) |
| 121 | { |
| 122 | if (getClientMajorVersion() != 2) |
| 123 | { |
| 124 | // This test only works on ES2 where uint indices are not available by default |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | EXPECT_FALSE(extensionEnabled("GL_OES_element_index_uint")); |
| 129 | |
| 130 | GLBuffer indexBuffer; |
| 131 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get()); |
| 132 | |
| 133 | GLuint data[] = {0, 1, 2, 1, 3, 2}; |
| 134 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); |
| 135 | |
| 136 | ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }", |
| 137 | "void main() { gl_FragColor = vec4(0, 1, 0, 1); }") |
| 138 | glUseProgram(program.get()); |
| 139 | |
| 140 | glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr); |
| 141 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 142 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 143 | if (extensionRequestable("GL_OES_element_index_uint")) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 144 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 145 | glRequestExtensionANGLE("GL_OES_element_index_uint"); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 146 | EXPECT_GL_NO_ERROR(); |
| 147 | EXPECT_TRUE(extensionEnabled("GL_OES_element_index_uint")); |
| 148 | |
| 149 | glDrawElements(GL_TRIANGLES, 2, GL_UNSIGNED_INT, nullptr); |
| 150 | EXPECT_GL_NO_ERROR(); |
| 151 | } |
| 152 | } |
| 153 | |
Bryan Bernhart | 87c182e | 2016-11-02 11:23:22 -0700 | [diff] [blame] | 154 | // Verify that shaders are of a compatible spec when the extension is enabled. |
| 155 | TEST_P(WebGLCompatibilityTest, ExtensionCompilerSpec) |
| 156 | { |
| 157 | EXPECT_TRUE(extensionEnabled("GL_ANGLE_webgl_compatibility")); |
| 158 | |
| 159 | // Use of reserved _webgl prefix should fail when the shader specification is for WebGL. |
| 160 | const std::string &vert = |
| 161 | "struct Foo {\n" |
| 162 | " int _webgl_bar;\n" |
| 163 | "};\n" |
| 164 | "void main()\n" |
| 165 | "{\n" |
| 166 | " Foo foo = Foo(1);\n" |
| 167 | "}"; |
| 168 | |
| 169 | // Default fragement shader. |
| 170 | const std::string &frag = |
| 171 | "void main()\n" |
| 172 | "{\n" |
| 173 | " gl_FragColor = vec4(1.0,0.0,0.0,1.0);\n" |
| 174 | "}"; |
| 175 | |
| 176 | GLuint program = CompileProgram(vert, frag); |
| 177 | EXPECT_EQ(0u, program); |
| 178 | glDeleteProgram(program); |
| 179 | } |
| 180 | |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 181 | // Test that client-side array buffers are forbidden in WebGL mode |
| 182 | TEST_P(WebGLCompatibilityTest, ForbidsClientSideArrayBuffer) |
| 183 | { |
| 184 | const std::string &vert = |
| 185 | "attribute vec3 a_pos;\n" |
| 186 | "void main()\n" |
| 187 | "{\n" |
| 188 | " gl_Position = vec4(a_pos, 1.0);\n" |
| 189 | "}\n"; |
| 190 | |
| 191 | const std::string &frag = |
| 192 | "precision highp float;\n" |
| 193 | "void main()\n" |
| 194 | "{\n" |
| 195 | " gl_FragColor = vec4(1.0);\n" |
| 196 | "}\n"; |
| 197 | |
| 198 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 199 | |
| 200 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 201 | ASSERT_NE(-1, posLocation); |
| 202 | glUseProgram(program.get()); |
| 203 | |
| 204 | const auto &vertices = GetQuadVertices(); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 205 | glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 4, vertices.data()); |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 206 | glEnableVertexAttribArray(posLocation); |
| 207 | |
| 208 | ASSERT_GL_NO_ERROR(); |
| 209 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 210 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 211 | } |
| 212 | |
| 213 | // Test that client-side element array buffers are forbidden in WebGL mode |
| 214 | TEST_P(WebGLCompatibilityTest, ForbidsClientSideElementBuffer) |
| 215 | { |
| 216 | const std::string &vert = |
| 217 | "attribute vec3 a_pos;\n" |
| 218 | "void main()\n" |
| 219 | "{\n" |
| 220 | " gl_Position = vec4(a_pos, 1.0);\n" |
| 221 | "}\n"; |
| 222 | |
| 223 | const std::string &frag = |
| 224 | "precision highp float;\n" |
| 225 | "void main()\n" |
| 226 | "{\n" |
| 227 | " gl_FragColor = vec4(1.0);\n" |
| 228 | "}\n"; |
| 229 | |
| 230 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 231 | |
| 232 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 233 | ASSERT_NE(-1, posLocation); |
| 234 | glUseProgram(program.get()); |
| 235 | |
| 236 | const auto &vertices = GetQuadVertices(); |
| 237 | |
| 238 | GLBuffer vertexBuffer; |
| 239 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get()); |
| 240 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(), |
| 241 | GL_STATIC_DRAW); |
| 242 | |
| 243 | glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); |
| 244 | glEnableVertexAttribArray(posLocation); |
| 245 | |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 246 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | ded1b5a | 2017-03-09 18:58:48 -0500 | [diff] [blame^] | 247 | |
| 248 | // Use the pointer with value of 1 for indices instead of an actual pointer because WebGL also |
| 249 | // enforces that the top bit of indices must be 0 (i.e. offset >= 0) and would generate |
| 250 | // GL_INVALID_VALUE in that case. Using a null pointer gets caught by another check. |
| 251 | 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] | 252 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 253 | } |
| 254 | |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 255 | // Tests the WebGL requirement of having the same stencil mask, writemask and ref for fron and back |
| 256 | TEST_P(WebGLCompatibilityTest, RequiresSameStencilMaskAndRef) |
| 257 | { |
| 258 | // Run the test in an FBO to make sure we have some stencil bits. |
| 259 | GLRenderbuffer renderbuffer; |
| 260 | glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer.get()); |
| 261 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 32, 32); |
| 262 | |
| 263 | GLFramebuffer framebuffer; |
| 264 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 265 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, |
| 266 | renderbuffer.get()); |
| 267 | |
| 268 | ANGLE_GL_PROGRAM(program, "void main() { gl_Position = vec4(0, 0, 0, 1); }", |
| 269 | "void main() { gl_FragColor = vec4(0, 1, 0, 1); }") |
| 270 | glUseProgram(program.get()); |
| 271 | ASSERT_GL_NO_ERROR(); |
| 272 | |
| 273 | // Having ref and mask the same for front and back is valid. |
| 274 | glStencilMask(255); |
| 275 | glStencilFunc(GL_ALWAYS, 0, 255); |
| 276 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 277 | ASSERT_GL_NO_ERROR(); |
| 278 | |
| 279 | // Having a different front - back write mask generates an error. |
| 280 | glStencilMaskSeparate(GL_FRONT, 1); |
| 281 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 282 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 283 | |
| 284 | // Setting both write masks separately to the same value is valid. |
| 285 | glStencilMaskSeparate(GL_BACK, 1); |
| 286 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 287 | ASSERT_GL_NO_ERROR(); |
| 288 | |
| 289 | // Having a different stencil front - back mask generates an error |
| 290 | glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 0, 1); |
| 291 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 292 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 293 | |
| 294 | // Setting both masks separately to the same value is valid. |
| 295 | glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 0, 1); |
| 296 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 297 | ASSERT_GL_NO_ERROR(); |
| 298 | |
| 299 | // Having a different stencil front - back reference generates an error |
| 300 | glStencilFuncSeparate(GL_FRONT, GL_ALWAYS, 255, 1); |
| 301 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 302 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 303 | |
| 304 | // Setting both references separately to the same value is valid. |
| 305 | glStencilFuncSeparate(GL_BACK, GL_ALWAYS, 255, 1); |
| 306 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 307 | ASSERT_GL_NO_ERROR(); |
| 308 | |
| 309 | // Using different stencil funcs, everything being equal is valid. |
| 310 | glStencilFuncSeparate(GL_BACK, GL_NEVER, 255, 1); |
| 311 | glDrawArrays(GL_TRIANGLES, 0, 6); |
| 312 | ASSERT_GL_NO_ERROR(); |
| 313 | } |
| 314 | |
Corentin Wallez | 506fc9c | 2016-12-21 16:53:33 -0500 | [diff] [blame] | 315 | // Test that GL_FIXED is forbidden |
| 316 | TEST_P(WebGLCompatibilityTest, ForbidsGLFixed) |
| 317 | { |
| 318 | GLBuffer buffer; |
| 319 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 320 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 321 | |
| 322 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, nullptr); |
| 323 | ASSERT_GL_NO_ERROR(); |
| 324 | |
| 325 | glVertexAttribPointer(0, 1, GL_FIXED, GL_FALSE, 0, nullptr); |
| 326 | EXPECT_GL_ERROR(GL_INVALID_ENUM); |
| 327 | } |
| 328 | |
| 329 | // Test the WebGL limit of 255 for the attribute stride |
| 330 | TEST_P(WebGLCompatibilityTest, MaxStride) |
| 331 | { |
| 332 | GLBuffer buffer; |
| 333 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 334 | glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW); |
| 335 | |
| 336 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 255, nullptr); |
| 337 | ASSERT_GL_NO_ERROR(); |
| 338 | |
| 339 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 256, nullptr); |
| 340 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
| 341 | } |
| 342 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 343 | // Test the checks for OOB reads in the vertex buffers, non-instanced version |
| 344 | TEST_P(WebGLCompatibilityTest, DrawArraysBufferOutOfBoundsNonInstanced) |
| 345 | { |
| 346 | const std::string &vert = |
| 347 | "attribute float a_pos;\n" |
| 348 | "void main()\n" |
| 349 | "{\n" |
| 350 | " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" |
| 351 | "}\n"; |
| 352 | |
| 353 | const std::string &frag = |
| 354 | "precision highp float;\n" |
| 355 | "void main()\n" |
| 356 | "{\n" |
| 357 | " gl_FragColor = vec4(1.0);\n" |
| 358 | "}\n"; |
| 359 | |
| 360 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 361 | |
| 362 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 363 | ASSERT_NE(-1, posLocation); |
| 364 | glUseProgram(program.get()); |
| 365 | |
| 366 | GLBuffer buffer; |
| 367 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 368 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 369 | |
| 370 | glEnableVertexAttribArray(posLocation); |
| 371 | |
| 372 | const uint8_t* zeroOffset = nullptr; |
| 373 | |
| 374 | // Test touching the last element is valid. |
| 375 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12); |
| 376 | glDrawArrays(GL_POINTS, 0, 4); |
| 377 | ASSERT_GL_NO_ERROR(); |
| 378 | |
| 379 | // Test touching the last element + 1 is invalid. |
| 380 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13); |
| 381 | glDrawArrays(GL_POINTS, 0, 4); |
| 382 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 383 | |
| 384 | // Test touching the last element is valid, using a stride. |
| 385 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9); |
| 386 | glDrawArrays(GL_POINTS, 0, 4); |
| 387 | ASSERT_GL_NO_ERROR(); |
| 388 | |
| 389 | // Test touching the last element + 1 is invalid, using a stride. |
| 390 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10); |
| 391 | glDrawArrays(GL_POINTS, 0, 4); |
| 392 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 393 | |
| 394 | // Test any offset is valid if no vertices are drawn. |
| 395 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32); |
| 396 | glDrawArrays(GL_POINTS, 0, 0); |
| 397 | ASSERT_GL_NO_ERROR(); |
| 398 | } |
| 399 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 400 | // Test the checks for OOB reads in the index buffer |
| 401 | TEST_P(WebGLCompatibilityTest, DrawElementsBufferOutOfBoundsInIndexBuffer) |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 402 | { |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 403 | const std::string &vert = |
| 404 | "attribute float a_pos;\n" |
| 405 | "void main()\n" |
| 406 | "{\n" |
| 407 | " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" |
| 408 | "}\n"; |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 409 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 410 | const std::string &frag = |
| 411 | "precision highp float;\n" |
| 412 | "void main()\n" |
| 413 | "{\n" |
| 414 | " gl_FragColor = vec4(1.0);\n" |
| 415 | "}\n"; |
| 416 | |
| 417 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 418 | |
| 419 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 420 | ASSERT_NE(-1, posLocation); |
| 421 | glUseProgram(program.get()); |
| 422 | |
| 423 | GLBuffer vertexBuffer; |
| 424 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get()); |
| 425 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 426 | |
| 427 | glEnableVertexAttribArray(posLocation); |
| 428 | |
| 429 | const uint8_t *zeroOffset = nullptr; |
| 430 | const uint8_t zeroIndices[] = {0, 0, 0, 0, 0, 0, 0, 0}; |
| 431 | |
| 432 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset); |
| 433 | |
| 434 | GLBuffer indexBuffer; |
| 435 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get()); |
| 436 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(zeroIndices), zeroIndices, GL_STATIC_DRAW); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 437 | ASSERT_GL_NO_ERROR(); |
| 438 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 439 | // Test touching the last index is valid |
| 440 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4); |
| 441 | ASSERT_GL_NO_ERROR(); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 442 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 443 | // Test touching the last + 1 element is invalid |
| 444 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 5); |
| 445 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 446 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 447 | // Test any offset if valid if count is zero |
| 448 | glDrawElements(GL_POINTS, 0, GL_UNSIGNED_BYTE, zeroOffset + 42); |
| 449 | ASSERT_GL_NO_ERROR(); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 450 | |
| 451 | // Test touching the first index is valid |
| 452 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset + 4); |
| 453 | ASSERT_GL_NO_ERROR(); |
| 454 | |
| 455 | // Test touching the first - 1 index is invalid |
| 456 | // The error ha been specified to be INVALID_VALUE instead of INVALID_OPERATION because it was |
| 457 | // the historic behavior of WebGL implementations |
| 458 | glDrawElements(GL_POINTS, 4, GL_UNSIGNED_BYTE, zeroOffset - 1); |
| 459 | EXPECT_GL_ERROR(GL_INVALID_VALUE); |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 460 | } |
| 461 | |
Frank Henigman | 6137ddc | 2017-02-10 18:55:07 -0500 | [diff] [blame] | 462 | // Test depth range with 'near' more or less than 'far.' |
| 463 | TEST_P(WebGLCompatibilityTest, DepthRange) |
| 464 | { |
| 465 | glDepthRangef(0, 1); |
| 466 | ASSERT_GL_NO_ERROR(); |
| 467 | |
| 468 | glDepthRangef(.5, .5); |
| 469 | ASSERT_GL_NO_ERROR(); |
| 470 | |
| 471 | glDepthRangef(1, 0); |
| 472 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 473 | } |
| 474 | |
Frank Henigman | 146e8a1 | 2017-03-02 23:22:37 -0500 | [diff] [blame] | 475 | // Test all blend function combinations. |
| 476 | // In WebGL it is invalid to combine constant color with constant alpha. |
| 477 | TEST_P(WebGLCompatibilityTest, BlendWithConstantColor) |
| 478 | { |
| 479 | constexpr GLenum srcFunc[] = { |
| 480 | GL_ZERO, |
| 481 | GL_ONE, |
| 482 | GL_SRC_COLOR, |
| 483 | GL_ONE_MINUS_SRC_COLOR, |
| 484 | GL_DST_COLOR, |
| 485 | GL_ONE_MINUS_DST_COLOR, |
| 486 | GL_SRC_ALPHA, |
| 487 | GL_ONE_MINUS_SRC_ALPHA, |
| 488 | GL_DST_ALPHA, |
| 489 | GL_ONE_MINUS_DST_ALPHA, |
| 490 | GL_CONSTANT_COLOR, |
| 491 | GL_ONE_MINUS_CONSTANT_COLOR, |
| 492 | GL_CONSTANT_ALPHA, |
| 493 | GL_ONE_MINUS_CONSTANT_ALPHA, |
| 494 | GL_SRC_ALPHA_SATURATE, |
| 495 | }; |
| 496 | |
| 497 | constexpr GLenum dstFunc[] = { |
| 498 | GL_ZERO, GL_ONE, |
| 499 | GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, |
| 500 | GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, |
| 501 | GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, |
| 502 | GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, |
| 503 | GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR, |
| 504 | GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, |
| 505 | }; |
| 506 | |
| 507 | for (GLenum src : srcFunc) |
| 508 | { |
| 509 | for (GLenum dst : dstFunc) |
| 510 | { |
| 511 | glBlendFunc(src, dst); |
| 512 | CheckBlendFunctions(src, dst); |
| 513 | glBlendFuncSeparate(src, dst, GL_ONE, GL_ONE); |
| 514 | CheckBlendFunctions(src, dst); |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 519 | // Test the checks for OOB reads in the vertex buffers, instanced version |
| 520 | TEST_P(WebGL2CompatibilityTest, DrawArraysBufferOutOfBoundsInstanced) |
| 521 | { |
| 522 | const std::string &vert = |
| 523 | "attribute float a_pos;\n" |
| 524 | "void main()\n" |
| 525 | "{\n" |
| 526 | " gl_Position = vec4(a_pos, a_pos, a_pos, 1.0);\n" |
| 527 | "}\n"; |
| 528 | |
| 529 | const std::string &frag = |
| 530 | "precision highp float;\n" |
| 531 | "void main()\n" |
| 532 | "{\n" |
| 533 | " gl_FragColor = vec4(1.0);\n" |
| 534 | "}\n"; |
| 535 | |
| 536 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 537 | |
| 538 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 539 | ASSERT_NE(-1, posLocation); |
| 540 | glUseProgram(program.get()); |
| 541 | |
| 542 | GLBuffer buffer; |
| 543 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
| 544 | glBufferData(GL_ARRAY_BUFFER, 16, nullptr, GL_STATIC_DRAW); |
| 545 | |
| 546 | glEnableVertexAttribArray(posLocation); |
| 547 | glVertexAttribDivisor(posLocation, 1); |
| 548 | |
| 549 | const uint8_t* zeroOffset = nullptr; |
| 550 | |
| 551 | // Test touching the last element is valid. |
| 552 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 12); |
| 553 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 554 | ASSERT_GL_NO_ERROR(); |
| 555 | |
| 556 | // Test touching the last element + 1 is invalid. |
| 557 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 13); |
| 558 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 559 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 560 | |
| 561 | // Test touching the last element is valid, using a stride. |
| 562 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 9); |
| 563 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 564 | ASSERT_GL_NO_ERROR(); |
| 565 | |
| 566 | // Test touching the last element + 1 is invalid, using a stride. |
| 567 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 2, zeroOffset + 10); |
| 568 | glDrawArraysInstanced(GL_POINTS, 0, 1, 4); |
| 569 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 570 | |
| 571 | // Test any offset is valid if no vertices are drawn. |
| 572 | glVertexAttribPointer(0, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, zeroOffset + 32); |
| 573 | glDrawArraysInstanced(GL_POINTS, 0, 1, 0); |
| 574 | ASSERT_GL_NO_ERROR(); |
| 575 | } |
| 576 | |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 577 | // Tests that NPOT is not enabled by default in WebGL 1 and that it can be enabled |
| 578 | TEST_P(WebGLCompatibilityTest, NPOT) |
| 579 | { |
| 580 | EXPECT_FALSE(extensionEnabled("GL_OES_texture_npot")); |
| 581 | |
| 582 | // Create a texture and set an NPOT mip 0, should always be acceptable. |
| 583 | GLTexture texture; |
| 584 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 585 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 10, 10, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 586 | ASSERT_GL_NO_ERROR(); |
| 587 | |
| 588 | // Try setting an NPOT mip 1 and verify the error if WebGL 1 |
| 589 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 590 | if (getClientMajorVersion() < 3) |
| 591 | { |
| 592 | ASSERT_GL_ERROR(GL_INVALID_VALUE); |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | ASSERT_GL_NO_ERROR(); |
| 597 | } |
| 598 | |
| 599 | if (extensionRequestable("GL_OES_texture_npot")) |
| 600 | { |
| 601 | glRequestExtensionANGLE("GL_OES_texture_npot"); |
| 602 | ASSERT_GL_NO_ERROR(); |
| 603 | |
| 604 | // Try again to set NPOT mip 1 |
| 605 | glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 5, 5, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 606 | ASSERT_GL_NO_ERROR(); |
| 607 | } |
| 608 | } |
| 609 | |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 610 | template <typename T> |
| 611 | void FillTexture2D(GLuint texture, |
| 612 | GLsizei width, |
| 613 | GLsizei height, |
| 614 | const T &onePixelData, |
| 615 | GLint level, |
| 616 | GLint internalFormat, |
| 617 | GLenum format, |
| 618 | GLenum type) |
| 619 | { |
| 620 | std::vector<T> allPixelsData(width * height, onePixelData); |
| 621 | |
| 622 | glBindTexture(GL_TEXTURE_2D, texture); |
| 623 | glTexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, |
| 624 | allPixelsData.data()); |
| 625 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 626 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 627 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 628 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 629 | } |
| 630 | |
Frank Henigman | 875bbba | 2017-02-08 16:38:17 -0500 | [diff] [blame] | 631 | // Test that unset gl_Position defaults to (0,0,0,0). |
| 632 | TEST_P(WebGLCompatibilityTest, DefaultPosition) |
| 633 | { |
| 634 | // Draw a quad where each vertex is red if gl_Position is (0,0,0,0) before it is set, |
| 635 | // and green otherwise. The center of each quadrant will be red if and only if all |
| 636 | // four corners are red. |
| 637 | const std::string vertexShader = |
| 638 | "attribute vec3 pos;\n" |
| 639 | "varying vec4 color;\n" |
| 640 | "void main() {\n" |
| 641 | " if (gl_Position == vec4(0,0,0,0)) {\n" |
| 642 | " color = vec4(1,0,0,1);\n" |
| 643 | " } else {\n" |
| 644 | " color = vec4(0,1,0,1);\n" |
| 645 | " }\n" |
| 646 | " gl_Position = vec4(pos,1);\n" |
| 647 | "}\n"; |
| 648 | |
| 649 | const std::string fragmentShader = |
| 650 | "precision mediump float;\n" |
| 651 | "varying vec4 color;\n" |
| 652 | "void main() {\n" |
| 653 | " gl_FragColor = color;\n" |
| 654 | "}\n"; |
| 655 | |
| 656 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 657 | drawQuad(program.get(), "pos", 0.0f, 1.0f, true); |
| 658 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 1 / 4, GLColor::red); |
| 659 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 1 / 4, getWindowHeight() * 3 / 4, GLColor::red); |
| 660 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 1 / 4, GLColor::red); |
| 661 | EXPECT_PIXEL_COLOR_EQ(getWindowWidth() * 3 / 4, getWindowHeight() * 3 / 4, GLColor::red); |
| 662 | } |
| 663 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 664 | // Tests that a rendering feedback loop triggers a GL error under WebGL. |
| 665 | // Based on WebGL test conformance/renderbuffers/feedback-loop.html. |
| 666 | TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoop) |
| 667 | { |
| 668 | const std::string vertexShader = |
| 669 | "attribute vec4 a_position;\n" |
| 670 | "varying vec2 v_texCoord;\n" |
| 671 | "void main() {\n" |
| 672 | " gl_Position = a_position;\n" |
| 673 | " v_texCoord = (a_position.xy * 0.5) + 0.5;\n" |
| 674 | "}\n"; |
| 675 | |
| 676 | const std::string fragmentShader = |
| 677 | "precision mediump float;\n" |
| 678 | "varying vec2 v_texCoord;\n" |
| 679 | "uniform sampler2D u_texture;\n" |
| 680 | "void main() {\n" |
| 681 | " // Shader swizzles color channels so we can tell if the draw succeeded.\n" |
| 682 | " gl_FragColor = texture2D(u_texture, v_texCoord).gbra;\n" |
| 683 | "}\n"; |
| 684 | |
| 685 | GLTexture texture; |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 686 | 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] | 687 | |
| 688 | ASSERT_GL_NO_ERROR(); |
| 689 | |
| 690 | GLFramebuffer framebuffer; |
| 691 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 692 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 693 | |
| 694 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 695 | |
| 696 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 697 | |
| 698 | GLint uniformLoc = glGetUniformLocation(program.get(), "u_texture"); |
| 699 | ASSERT_NE(-1, uniformLoc); |
| 700 | |
| 701 | glUseProgram(program.get()); |
| 702 | glUniform1i(uniformLoc, 0); |
| 703 | glDisable(GL_BLEND); |
| 704 | glDisable(GL_DEPTH_TEST); |
| 705 | ASSERT_GL_NO_ERROR(); |
| 706 | |
| 707 | // Drawing with a texture that is also bound to the current framebuffer should fail |
| 708 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 709 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 710 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 711 | |
| 712 | // Ensure that the texture contents did not change after the previous render |
| 713 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 714 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 715 | ASSERT_GL_NO_ERROR(); |
| 716 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue); |
| 717 | |
| 718 | // Drawing when texture is bound to an inactive uniform should succeed |
| 719 | GLTexture texture2; |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 720 | 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] | 721 | |
| 722 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 723 | glActiveTexture(GL_TEXTURE1); |
| 724 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 725 | drawQuad(program.get(), "a_position", 0.5f, 1.0f, true); |
| 726 | ASSERT_GL_NO_ERROR(); |
| 727 | EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red); |
| 728 | } |
| 729 | |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 730 | // Test for the max draw buffers and color attachments. |
| 731 | TEST_P(WebGLCompatibilityTest, MaxDrawBuffersAttachmentPoints) |
| 732 | { |
| 733 | // This test only applies to ES2. |
| 734 | if (getClientMajorVersion() != 2) |
| 735 | { |
| 736 | return; |
| 737 | } |
| 738 | |
| 739 | GLFramebuffer fbo[2]; |
| 740 | glBindFramebuffer(GL_FRAMEBUFFER, fbo[0].get()); |
| 741 | |
| 742 | // Test that is valid when we bind with a single attachment point. |
| 743 | GLTexture texture; |
| 744 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 745 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 746 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 747 | ASSERT_GL_NO_ERROR(); |
| 748 | |
| 749 | // Test that enabling the draw buffers extension will allow us to bind with a non-zero |
| 750 | // attachment point. |
| 751 | if (extensionRequestable("GL_EXT_draw_buffers")) |
| 752 | { |
| 753 | glRequestExtensionANGLE("GL_EXT_draw_buffers"); |
| 754 | EXPECT_GL_NO_ERROR(); |
| 755 | EXPECT_TRUE(extensionEnabled("GL_EXT_draw_buffers")); |
| 756 | |
| 757 | glBindFramebuffer(GL_FRAMEBUFFER, fbo[1].get()); |
| 758 | |
| 759 | GLTexture texture2; |
| 760 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 761 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 762 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, texture2.get(), |
| 763 | 0); |
| 764 | ASSERT_GL_NO_ERROR(); |
| 765 | } |
| 766 | } |
| 767 | |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 768 | // Test that the offset in the index buffer is forced to be a multiple of the element size |
| 769 | TEST_P(WebGLCompatibilityTest, DrawElementsOffsetRestriction) |
| 770 | { |
| 771 | const std::string &vert = |
| 772 | "attribute vec3 a_pos;\n" |
| 773 | "void main()\n" |
| 774 | "{\n" |
| 775 | " gl_Position = vec4(a_pos, 1.0);\n" |
| 776 | "}\n"; |
| 777 | |
| 778 | const std::string &frag = |
| 779 | "precision highp float;\n" |
| 780 | "void main()\n" |
| 781 | "{\n" |
| 782 | " gl_FragColor = vec4(1.0);\n" |
| 783 | "}\n"; |
| 784 | |
| 785 | ANGLE_GL_PROGRAM(program, vert, frag); |
| 786 | |
| 787 | GLint posLocation = glGetAttribLocation(program.get(), "a_pos"); |
| 788 | ASSERT_NE(-1, posLocation); |
| 789 | glUseProgram(program.get()); |
| 790 | |
| 791 | const auto &vertices = GetQuadVertices(); |
| 792 | |
| 793 | GLBuffer vertexBuffer; |
| 794 | glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get()); |
| 795 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(), |
| 796 | GL_STATIC_DRAW); |
| 797 | |
| 798 | glVertexAttribPointer(posLocation, 3, GL_FLOAT, GL_FALSE, 0, 0); |
| 799 | glEnableVertexAttribArray(posLocation); |
| 800 | |
| 801 | GLBuffer indexBuffer; |
| 802 | const GLubyte indices[] = {0, 0, 0, 0, 0, 0, 0}; |
| 803 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer.get()); |
| 804 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 805 | |
| 806 | ASSERT_GL_NO_ERROR(); |
| 807 | |
| 808 | const char *zeroIndices = nullptr; |
| 809 | |
| 810 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, zeroIndices); |
| 811 | ASSERT_GL_NO_ERROR(); |
| 812 | |
| 813 | glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices); |
| 814 | ASSERT_GL_NO_ERROR(); |
| 815 | |
| 816 | glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, zeroIndices + 1); |
| 817 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 818 | } |
| 819 | |
| 820 | // Test that the offset and stride in the vertex buffer is forced to be a multiple of the element |
| 821 | // size |
| 822 | TEST_P(WebGLCompatibilityTest, VertexAttribPointerOffsetRestriction) |
| 823 | { |
| 824 | const char *zeroOffset = nullptr; |
| 825 | |
| 826 | // Base case, vector of two floats |
| 827 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset); |
| 828 | ASSERT_GL_NO_ERROR(); |
| 829 | |
| 830 | // Test setting a non-multiple offset |
| 831 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 1); |
| 832 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 833 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 2); |
| 834 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 835 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, zeroOffset + 3); |
| 836 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 837 | |
| 838 | // Test setting a non-multiple stride |
| 839 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 1, zeroOffset); |
| 840 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 841 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2, zeroOffset); |
| 842 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 843 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 3, zeroOffset); |
| 844 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 845 | } |
| 846 | |
Jamie Madill | cad97ee | 2017-02-02 18:52:44 -0500 | [diff] [blame] | 847 | void WebGLCompatibilityTest::drawBuffersEXTFeedbackLoop(GLuint program, |
| 848 | const std::array<GLenum, 2> &drawBuffers, |
| 849 | GLenum expectedError) |
| 850 | { |
| 851 | glDrawBuffersEXT(2, drawBuffers.data()); |
| 852 | |
| 853 | // Make sure framebuffer is complete before feedback loop detection |
| 854 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 855 | |
| 856 | drawQuad(program, "aPosition", 0.5f, 1.0f, true); |
| 857 | |
| 858 | // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise, |
| 859 | // it should be NO_ERROR" |
| 860 | EXPECT_GL_ERROR(expectedError); |
| 861 | } |
| 862 | |
| 863 | // This tests that rendering feedback loops works as expected with GL_EXT_draw_buffers. |
| 864 | // Based on WebGL test conformance/extensions/webgl-draw-buffers-feedback-loop.html |
| 865 | TEST_P(WebGLCompatibilityTest, RenderingFeedbackLoopWithDrawBuffersEXT) |
| 866 | { |
| 867 | const std::string vertexShader = |
| 868 | "attribute vec4 aPosition;\n" |
| 869 | "varying vec2 texCoord;\n" |
| 870 | "void main() {\n" |
| 871 | " gl_Position = aPosition;\n" |
| 872 | " texCoord = (aPosition.xy * 0.5) + 0.5;\n" |
| 873 | "}\n"; |
| 874 | |
| 875 | const std::string fragmentShader = |
| 876 | "#extension GL_EXT_draw_buffers : require\n" |
| 877 | "precision mediump float;\n" |
| 878 | "uniform sampler2D tex;\n" |
| 879 | "varying vec2 texCoord;\n" |
| 880 | "void main() {\n" |
| 881 | " gl_FragData[0] = texture2D(tex, texCoord);\n" |
| 882 | " gl_FragData[1] = texture2D(tex, texCoord);\n" |
| 883 | "}\n"; |
| 884 | |
| 885 | GLsizei width = 8; |
| 886 | GLsizei height = 8; |
| 887 | |
| 888 | // This shader cannot be run in ES3, because WebGL 2 does not expose the draw buffers |
| 889 | // extension and gl_FragData semantics are changed to enforce indexing by zero always. |
| 890 | // TODO(jmadill): This extension should be disabled in WebGL 2 contexts. |
| 891 | if (/*!extensionEnabled("GL_EXT_draw_buffers")*/ getClientMajorVersion() != 2) |
| 892 | { |
| 893 | // No WEBGL_draw_buffers support -- this is legal. |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | GLint maxDrawBuffers = 0; |
| 898 | glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
| 899 | |
| 900 | if (maxDrawBuffers < 2) |
| 901 | { |
| 902 | std::cout << "Test skipped because MAX_DRAW_BUFFERS is too small." << std::endl; |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 907 | glUseProgram(program.get()); |
| 908 | glViewport(0, 0, width, height); |
| 909 | |
| 910 | GLTexture tex0; |
| 911 | GLTexture tex1; |
| 912 | GLFramebuffer fbo; |
| 913 | FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 914 | FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 915 | ASSERT_GL_NO_ERROR(); |
| 916 | |
| 917 | glBindTexture(GL_TEXTURE_2D, tex1.get()); |
| 918 | GLint texLoc = glGetUniformLocation(program.get(), "tex"); |
| 919 | ASSERT_NE(-1, texLoc); |
| 920 | glUniform1i(texLoc, 0); |
| 921 | ASSERT_GL_NO_ERROR(); |
| 922 | |
| 923 | // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation |
| 924 | glBindFramebuffer(GL_FRAMEBUFFER, fbo.get()); |
| 925 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0); |
| 926 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0); |
| 927 | |
| 928 | drawBuffersEXTFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, |
| 929 | GL_INVALID_OPERATION); |
| 930 | drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}}, |
| 931 | GL_INVALID_OPERATION); |
| 932 | drawBuffersEXTFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR); |
| 933 | } |
| 934 | |
Jamie Madill | 07be8bf | 2017-02-02 19:59:57 -0500 | [diff] [blame] | 935 | // Test tests that texture copying feedback loops are properly rejected in WebGL. |
| 936 | // Based on the WebGL test conformance/textures/misc/texture-copying-feedback-loops.html |
| 937 | TEST_P(WebGLCompatibilityTest, TextureCopyingFeedbackLoops) |
| 938 | { |
| 939 | GLTexture texture; |
| 940 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 941 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 942 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 943 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 944 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 945 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 946 | |
| 947 | GLTexture texture2; |
| 948 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 949 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 950 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 951 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 952 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 953 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 954 | |
| 955 | GLFramebuffer framebuffer; |
| 956 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 957 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.get(), 0); |
| 958 | |
| 959 | // framebuffer should be FRAMEBUFFER_COMPLETE. |
| 960 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 961 | ASSERT_GL_NO_ERROR(); |
| 962 | |
| 963 | // testing copyTexImage2D |
| 964 | |
| 965 | // copyTexImage2D to same texture but different level |
| 966 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 967 | glCopyTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 0, 0, 2, 2, 0); |
| 968 | EXPECT_GL_NO_ERROR(); |
| 969 | |
| 970 | // copyTexImage2D to same texture same level, invalid feedback loop |
| 971 | glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0); |
| 972 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 973 | |
| 974 | // copyTexImage2D to different texture |
| 975 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 976 | glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 2, 2, 0); |
| 977 | EXPECT_GL_NO_ERROR(); |
| 978 | |
| 979 | // testing copyTexSubImage2D |
| 980 | |
| 981 | // copyTexSubImage2D to same texture but different level |
| 982 | glBindTexture(GL_TEXTURE_2D, texture.get()); |
| 983 | glCopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1); |
| 984 | EXPECT_GL_NO_ERROR(); |
| 985 | |
| 986 | // copyTexSubImage2D to same texture same level, invalid feedback loop |
| 987 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); |
| 988 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 989 | |
| 990 | // copyTexSubImage2D to different texture |
| 991 | glBindTexture(GL_TEXTURE_2D, texture2.get()); |
| 992 | glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); |
| 993 | EXPECT_GL_NO_ERROR(); |
| 994 | } |
| 995 | |
| 996 | void WebGLCompatibilityTest::drawBuffersFeedbackLoop(GLuint program, |
| 997 | const std::array<GLenum, 2> &drawBuffers, |
| 998 | GLenum expectedError) |
| 999 | { |
| 1000 | glDrawBuffers(2, drawBuffers.data()); |
| 1001 | |
| 1002 | // Make sure framebuffer is complete before feedback loop detection |
| 1003 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1004 | |
| 1005 | drawQuad(program, "aPosition", 0.5f, 1.0f, true); |
| 1006 | |
| 1007 | // "Rendering to a texture where it samples from should geneates INVALID_OPERATION. Otherwise, |
| 1008 | // it should be NO_ERROR" |
| 1009 | EXPECT_GL_ERROR(expectedError); |
| 1010 | } |
| 1011 | |
Yuly Novikov | 817232e | 2017-02-22 18:36:10 -0500 | [diff] [blame] | 1012 | // Tests invariance matching rules between built in varyings. |
| 1013 | // Based on WebGL test conformance/glsl/misc/shaders-with-invariance.html. |
| 1014 | TEST_P(WebGLCompatibilityTest, BuiltInInvariant) |
| 1015 | { |
| 1016 | const std::string vertexShaderVariant = |
| 1017 | "varying vec4 v_varying;\n" |
| 1018 | "void main()\n" |
| 1019 | "{\n" |
| 1020 | " gl_PointSize = 1.0;\n" |
| 1021 | " gl_Position = v_varying;\n" |
| 1022 | "}"; |
| 1023 | const std::string fragmentShaderInvariantGlFragCoord = |
| 1024 | "invariant gl_FragCoord;\n" |
| 1025 | "void main()\n" |
| 1026 | "{\n" |
| 1027 | " gl_FragColor = gl_FragCoord;\n" |
| 1028 | "}"; |
| 1029 | const std::string fragmentShaderInvariantGlPointCoord = |
| 1030 | "invariant gl_PointCoord;\n" |
| 1031 | "void main()\n" |
| 1032 | "{\n" |
| 1033 | " gl_FragColor = vec4(gl_PointCoord, 0.0, 0.0);\n" |
| 1034 | "}"; |
| 1035 | |
| 1036 | GLuint program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlFragCoord); |
| 1037 | EXPECT_EQ(0u, program); |
| 1038 | |
| 1039 | program = CompileProgram(vertexShaderVariant, fragmentShaderInvariantGlPointCoord); |
| 1040 | EXPECT_EQ(0u, program); |
| 1041 | } |
| 1042 | |
Jamie Madill | 07be8bf | 2017-02-02 19:59:57 -0500 | [diff] [blame] | 1043 | // This tests that rendering feedback loops works as expected with WebGL 2. |
| 1044 | // Based on WebGL test conformance2/rendering/rendering-sampling-feedback-loop.html |
| 1045 | TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDrawBuffers) |
| 1046 | { |
| 1047 | const std::string vertexShader = |
| 1048 | "#version 300 es\n" |
| 1049 | "in vec4 aPosition;\n" |
| 1050 | "out vec2 texCoord;\n" |
| 1051 | "void main() {\n" |
| 1052 | " gl_Position = aPosition;\n" |
| 1053 | " texCoord = (aPosition.xy * 0.5) + 0.5;\n" |
| 1054 | "}\n"; |
| 1055 | |
| 1056 | const std::string fragmentShader = |
| 1057 | "#version 300 es\n" |
| 1058 | "precision mediump float;\n" |
| 1059 | "uniform sampler2D tex;\n" |
| 1060 | "in vec2 texCoord;\n" |
| 1061 | "out vec4 oColor;\n" |
| 1062 | "void main() {\n" |
| 1063 | " oColor = texture(tex, texCoord);\n" |
| 1064 | "}\n"; |
| 1065 | |
| 1066 | GLsizei width = 8; |
| 1067 | GLsizei height = 8; |
| 1068 | |
| 1069 | GLint maxDrawBuffers = 0; |
| 1070 | glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers); |
| 1071 | // ES3 requires a minimum value of 4 for MAX_DRAW_BUFFERS. |
| 1072 | ASSERT_GE(maxDrawBuffers, 2); |
| 1073 | |
| 1074 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 1075 | glUseProgram(program.get()); |
| 1076 | glViewport(0, 0, width, height); |
| 1077 | |
| 1078 | GLTexture tex0; |
| 1079 | GLTexture tex1; |
| 1080 | GLFramebuffer fbo; |
| 1081 | FillTexture2D(tex0.get(), width, height, GLColor::red, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 1082 | FillTexture2D(tex1.get(), width, height, GLColor::green, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 1083 | ASSERT_GL_NO_ERROR(); |
| 1084 | |
| 1085 | glBindTexture(GL_TEXTURE_2D, tex1.get()); |
| 1086 | GLint texLoc = glGetUniformLocation(program.get(), "tex"); |
| 1087 | ASSERT_NE(-1, texLoc); |
| 1088 | glUniform1i(texLoc, 0); |
| 1089 | |
| 1090 | // The sampling texture is bound to COLOR_ATTACHMENT1 during resource allocation |
| 1091 | glBindFramebuffer(GL_FRAMEBUFFER, fbo.get()); |
| 1092 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0); |
| 1093 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, tex1.get(), 0); |
| 1094 | ASSERT_GL_NO_ERROR(); |
| 1095 | |
| 1096 | drawBuffersFeedbackLoop(program.get(), {{GL_NONE, GL_COLOR_ATTACHMENT1}}, GL_INVALID_OPERATION); |
| 1097 | drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}}, |
| 1098 | GL_INVALID_OPERATION); |
| 1099 | drawBuffersFeedbackLoop(program.get(), {{GL_COLOR_ATTACHMENT0, GL_NONE}}, GL_NO_ERROR); |
| 1100 | } |
| 1101 | |
Jamie Madill | 1d37bc5 | 2017-02-02 19:59:58 -0500 | [diff] [blame] | 1102 | // This test covers detection of rendering feedback loops between the FBO and a depth Texture. |
| 1103 | // Based on WebGL test conformance2/rendering/depth-stencil-feedback-loop.html |
| 1104 | TEST_P(WebGL2CompatibilityTest, RenderingFeedbackLoopWithDepthStencil) |
| 1105 | { |
| 1106 | const std::string vertexShader = |
| 1107 | "#version 300 es\n" |
| 1108 | "in vec4 aPosition;\n" |
| 1109 | "out vec2 texCoord;\n" |
| 1110 | "void main() {\n" |
| 1111 | " gl_Position = aPosition;\n" |
| 1112 | " texCoord = (aPosition.xy * 0.5) + 0.5;\n" |
| 1113 | "}\n"; |
| 1114 | |
| 1115 | const std::string fragmentShader = |
| 1116 | "#version 300 es\n" |
| 1117 | "precision mediump float;\n" |
| 1118 | "uniform sampler2D tex;\n" |
| 1119 | "in vec2 texCoord;\n" |
| 1120 | "out vec4 oColor;\n" |
| 1121 | "void main() {\n" |
| 1122 | " oColor = texture(tex, texCoord);\n" |
| 1123 | "}\n"; |
| 1124 | |
| 1125 | GLsizei width = 8; |
| 1126 | GLsizei height = 8; |
| 1127 | |
| 1128 | ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader); |
| 1129 | glUseProgram(program.get()); |
| 1130 | |
| 1131 | glViewport(0, 0, width, height); |
| 1132 | |
| 1133 | GLint texLoc = glGetUniformLocation(program.get(), "tex"); |
| 1134 | glUniform1i(texLoc, 0); |
| 1135 | |
| 1136 | // Create textures and allocate storage |
| 1137 | GLTexture tex0; |
| 1138 | GLTexture tex1; |
| 1139 | GLRenderbuffer rb; |
| 1140 | FillTexture2D(tex0.get(), width, height, GLColor::black, 0, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); |
| 1141 | FillTexture2D(tex1.get(), width, height, 0x80, 0, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, |
| 1142 | GL_UNSIGNED_INT); |
| 1143 | glBindRenderbuffer(GL_RENDERBUFFER, rb.get()); |
| 1144 | glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, width, height); |
| 1145 | ASSERT_GL_NO_ERROR(); |
| 1146 | |
| 1147 | GLFramebuffer fbo; |
| 1148 | glBindFramebuffer(GL_FRAMEBUFFER, fbo.get()); |
| 1149 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex0.get(), 0); |
| 1150 | |
| 1151 | // Test rendering and sampling feedback loop for depth buffer |
| 1152 | glBindTexture(GL_TEXTURE_2D, tex1.get()); |
| 1153 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, tex1.get(), 0); |
| 1154 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1155 | |
| 1156 | // The same image is used as depth buffer during rendering. |
| 1157 | glEnable(GL_DEPTH_TEST); |
| 1158 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 1159 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1160 | |
| 1161 | // The same image is used as depth buffer. But depth mask is false. |
| 1162 | glDepthMask(GL_FALSE); |
| 1163 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 1164 | EXPECT_GL_NO_ERROR(); |
| 1165 | |
| 1166 | // The same image is used as depth buffer. But depth test is not enabled during rendering. |
| 1167 | glDepthMask(GL_TRUE); |
| 1168 | glDisable(GL_DEPTH_TEST); |
| 1169 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 1170 | EXPECT_GL_NO_ERROR(); |
| 1171 | |
| 1172 | // Test rendering and sampling feedback loop for stencil buffer |
| 1173 | glBindTexture(GL_RENDERBUFFER, rb.get()); |
| 1174 | glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0); |
| 1175 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb.get()); |
| 1176 | ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER)); |
| 1177 | constexpr GLint stencilClearValue = 0x40; |
| 1178 | glClearBufferiv(GL_STENCIL, 0, &stencilClearValue); |
| 1179 | |
| 1180 | // The same image is used as stencil buffer during rendering. |
| 1181 | glEnable(GL_STENCIL_TEST); |
| 1182 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 1183 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1184 | |
| 1185 | // The same image is used as stencil buffer. But stencil mask is zero. |
| 1186 | glStencilMask(0x0); |
| 1187 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 1188 | EXPECT_GL_NO_ERROR(); |
| 1189 | |
| 1190 | // The same image is used as stencil buffer. But stencil test is not enabled during rendering. |
| 1191 | glStencilMask(0xffff); |
| 1192 | glDisable(GL_STENCIL_TEST); |
| 1193 | drawQuad(program.get(), "aPosition", 0.5f, 1.0f, true); |
| 1194 | EXPECT_GL_NO_ERROR(); |
| 1195 | } |
| 1196 | |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 1197 | // The source and the target for CopyTexSubImage3D are the same 3D texture. |
| 1198 | // But the level of the 3D texture != the level of the read attachment. |
| 1199 | TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLevels) |
| 1200 | { |
| 1201 | GLTexture texture; |
| 1202 | GLFramebuffer framebuffer; |
| 1203 | |
| 1204 | glBindTexture(GL_TEXTURE_3D, texture.get()); |
| 1205 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1206 | |
| 1207 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1208 | glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1209 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 0); |
| 1210 | ASSERT_GL_NO_ERROR(); |
| 1211 | |
| 1212 | glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2); |
| 1213 | EXPECT_GL_NO_ERROR(); |
| 1214 | } |
| 1215 | |
| 1216 | // The source and the target for CopyTexSubImage3D are the same 3D texture. |
| 1217 | // But the zoffset of the 3D texture != the layer of the read attachment. |
| 1218 | TEST_P(WebGL2CompatibilityTest, NoTextureCopyingFeedbackLoopBetween3DLayers) |
| 1219 | { |
| 1220 | GLTexture texture; |
| 1221 | GLFramebuffer framebuffer; |
| 1222 | |
| 1223 | glBindTexture(GL_TEXTURE_3D, texture.get()); |
| 1224 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1225 | |
| 1226 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1227 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 0, 1); |
| 1228 | ASSERT_GL_NO_ERROR(); |
| 1229 | |
| 1230 | glCopyTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 0, 0, 0, 2, 2); |
| 1231 | EXPECT_GL_NO_ERROR(); |
| 1232 | } |
| 1233 | |
| 1234 | // The source and the target for CopyTexSubImage3D are the same 3D texture. |
| 1235 | // And the level / zoffset of the 3D texture is equal to the level / layer of the read attachment. |
| 1236 | TEST_P(WebGL2CompatibilityTest, TextureCopyingFeedbackLoop3D) |
| 1237 | { |
| 1238 | GLTexture texture; |
| 1239 | GLFramebuffer framebuffer; |
| 1240 | |
| 1241 | glBindTexture(GL_TEXTURE_3D, texture.get()); |
| 1242 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.get()); |
| 1243 | |
| 1244 | glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1245 | glTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA8, 2, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1246 | glTexImage3D(GL_TEXTURE_3D, 2, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 1247 | glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture.get(), 1, 0); |
| 1248 | ASSERT_GL_NO_ERROR(); |
| 1249 | |
| 1250 | glCopyTexSubImage3D(GL_TEXTURE_3D, 1, 0, 0, 0, 0, 0, 2, 2); |
| 1251 | EXPECT_GL_ERROR(GL_INVALID_OPERATION); |
| 1252 | } |
| 1253 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 1254 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 1255 | // tests should be run against. |
| 1256 | ANGLE_INSTANTIATE_TEST(WebGLCompatibilityTest, |
| 1257 | ES2_D3D9(), |
| 1258 | ES2_D3D11(), |
| 1259 | ES3_D3D11(), |
| 1260 | ES2_D3D11_FL9_3(), |
| 1261 | ES2_OPENGL(), |
| 1262 | ES3_OPENGL(), |
| 1263 | ES2_OPENGLES(), |
| 1264 | ES3_OPENGLES()); |
| 1265 | |
Jamie Madill | 07be8bf | 2017-02-02 19:59:57 -0500 | [diff] [blame] | 1266 | ANGLE_INSTANTIATE_TEST(WebGL2CompatibilityTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES()); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 1267 | } // namespace |