tex-new-formats.html (19488B)
1 <!-- 2 Copyright (c) 2019 The Khronos Group Inc. 3 Use of this source code is governed by an MIT-style license that can be 4 found in the LICENSE.txt file. 5 --> 6 7 <!DOCTYPE html> 8 <html> 9 <head> 10 <meta charset="utf-8"> 11 <title>Conformance test for WebGL2 texture image formats specification</title> 12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> 13 <script src="../../../js/js-test-pre.js"></script> 14 <script src="../../../js/webgl-test-utils.js"></script> 15 </head> 16 <body> 17 <div id="description"></div> 18 <canvas id="canvas" width="64" height="64"> </canvas> 19 <div id="console"></div> 20 21 22 <script> 23 "use strict"; 24 description("This test verifies that texture image specification entry points " + 25 "accept new formats introduced in WebGL2, and accept sized internalformats."); 26 27 debug(""); 28 29 var wtu = WebGLTestUtils; 30 var canvas = document.getElementById("canvas"); 31 var gl = wtu.create3DContext(canvas, null, 2); 32 var vao = null; 33 34 if (!gl) { 35 testFailed("WebGL context does not exist"); 36 } else { 37 testPassed("WebGL context exists"); 38 39 runTexFormatsTest(); 40 runDepthStencilFormatTest(); 41 42 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors"); 43 } 44 45 function enumToString(value) { 46 return wtu.glEnumToString(gl, value); 47 } 48 49 function runTexFormatsTest() 50 { 51 // texFormats is Table 3.2 and Table 3.3 from the OpenGL ES 3.0.4 spec. 52 var texFormats = [ 53 { 54 sizedformat: "RGBA8", 55 unsizedformat: "RGBA", 56 type: "UNSIGNED_BYTE", 57 }, 58 { 59 sizedformat: "RGB5_A1", 60 unsizedformat: "RGBA", 61 type: "UNSIGNED_BYTE", 62 }, 63 { 64 sizedformat: "RGBA4", 65 unsizedformat: "RGBA", 66 type: "UNSIGNED_BYTE", 67 }, 68 { 69 sizedformat: "SRGB8_ALPHA8", 70 unsizedformat: "RGBA", 71 type: "UNSIGNED_BYTE", 72 }, 73 { 74 sizedformat: "RGBA8_SNORM", 75 unsizedformat: "RGBA", 76 type: "BYTE", 77 }, 78 { 79 sizedformat: "RGBA4", 80 unsizedformat: "RGBA", 81 type: "UNSIGNED_SHORT_4_4_4_4", 82 }, 83 { 84 sizedformat: "RGB5_A1", 85 unsizedformat: "RGBA", 86 type: "UNSIGNED_SHORT_5_5_5_1", 87 }, 88 { 89 sizedformat: "RGB10_A2", 90 unsizedformat: "RGBA", 91 type: "UNSIGNED_INT_2_10_10_10_REV", 92 }, 93 { 94 sizedformat: "RGB5_A1", 95 unsizedformat: "RGBA", 96 type: "UNSIGNED_INT_2_10_10_10_REV", 97 }, 98 { 99 sizedformat: "RGBA16F", 100 unsizedformat: "RGBA", 101 type: "HALF_FLOAT", 102 }, 103 { 104 sizedformat: "RGBA32F", 105 unsizedformat: "RGBA", 106 type: "FLOAT", 107 }, 108 { 109 sizedformat: "RGBA16F", 110 unsizedformat: "RGBA", 111 type: "FLOAT", 112 }, 113 { 114 sizedformat: "RGBA8UI", 115 unsizedformat: "RGBA_INTEGER", 116 type: "UNSIGNED_BYTE", 117 }, 118 { 119 sizedformat: "RGBA8I", 120 unsizedformat: "RGBA_INTEGER", 121 type: "BYTE", 122 }, 123 { 124 sizedformat: "RGBA16UI", 125 unsizedformat: "RGBA_INTEGER", 126 type: "UNSIGNED_SHORT", 127 }, 128 { 129 sizedformat: "RGBA16I", 130 unsizedformat: "RGBA_INTEGER", 131 type: "SHORT", 132 }, 133 { 134 sizedformat: "RGBA32UI", 135 unsizedformat: "RGBA_INTEGER", 136 type: "UNSIGNED_INT", 137 }, 138 { 139 sizedformat: "RGBA32I", 140 unsizedformat: "RGBA_INTEGER", 141 type: "INT", 142 }, 143 { 144 sizedformat: "RGB10_A2UI", 145 unsizedformat: "RGBA_INTEGER", 146 type: "UNSIGNED_INT_2_10_10_10_REV", 147 }, 148 { 149 sizedformat: "RGB8", 150 unsizedformat: "RGB", 151 type: "UNSIGNED_BYTE", 152 }, 153 { 154 sizedformat: "RGB565", 155 unsizedformat: "RGB", 156 type: "UNSIGNED_BYTE", 157 }, 158 { 159 sizedformat: "SRGB8", 160 unsizedformat: "RGB", 161 type: "UNSIGNED_BYTE", 162 }, 163 { 164 sizedformat: "RGB8_SNORM", 165 unsizedformat: "RGB", 166 type: "BYTE", 167 }, 168 { 169 sizedformat: "RGB565", 170 unsizedformat: "RGB", 171 type: "UNSIGNED_SHORT_5_6_5", 172 }, 173 { 174 sizedformat: "R11F_G11F_B10F", 175 unsizedformat: "RGB", 176 type: "UNSIGNED_INT_10F_11F_11F_REV", 177 }, 178 { 179 sizedformat: "RGB9_E5", 180 unsizedformat: "RGB", 181 type: "UNSIGNED_INT_5_9_9_9_REV", 182 }, 183 { 184 sizedformat: "RGB16F", 185 unsizedformat: "RGB", 186 type: "HALF_FLOAT", 187 }, 188 { 189 sizedformat: "R11F_G11F_B10F", 190 unsizedformat: "RGB", 191 type: "HALF_FLOAT", 192 }, 193 { 194 sizedformat: "RGB9_E5", 195 unsizedformat: "RGB", 196 type: "HALF_FLOAT", 197 }, 198 { 199 sizedformat: "RGB32F", 200 unsizedformat: "RGB", 201 type: "FLOAT", 202 }, 203 { 204 sizedformat: "RGB16F", 205 unsizedformat: "RGB", 206 type: "FLOAT", 207 }, 208 { 209 sizedformat: "R11F_G11F_B10F", 210 unsizedformat: "RGB", 211 type: "FLOAT", 212 }, 213 { 214 sizedformat: "RGB9_E5", 215 unsizedformat: "RGB", 216 type: "FLOAT", 217 }, 218 { 219 sizedformat: "RGB8UI", 220 unsizedformat: "RGB_INTEGER", 221 type: "UNSIGNED_BYTE", 222 }, 223 { 224 sizedformat: "RGB8I", 225 unsizedformat: "RGB_INTEGER", 226 type: "BYTE", 227 }, 228 { 229 sizedformat: "RGB16UI", 230 unsizedformat: "RGB_INTEGER", 231 type: "UNSIGNED_SHORT", 232 }, 233 { 234 sizedformat: "RGB16I", 235 unsizedformat: "RGB_INTEGER", 236 type: "SHORT", 237 }, 238 { 239 sizedformat: "RGB32UI", 240 unsizedformat: "RGB_INTEGER", 241 type: "UNSIGNED_INT", 242 }, 243 { 244 sizedformat: "RGB32I", 245 unsizedformat: "RGB_INTEGER", 246 type: "INT", 247 }, 248 { 249 sizedformat: "RG8", 250 unsizedformat: "RG", 251 type: "UNSIGNED_BYTE", 252 }, 253 { 254 sizedformat: "RG8_SNORM", 255 unsizedformat: "RG", 256 type: "BYTE", 257 }, 258 { 259 sizedformat: "RG16F", 260 unsizedformat: "RG", 261 type: "HALF_FLOAT", 262 }, 263 { 264 sizedformat: "RG32F", 265 unsizedformat: "RG", 266 type: "FLOAT", 267 }, 268 { 269 sizedformat: "RG16F", 270 unsizedformat: "RG", 271 type: "FLOAT", 272 }, 273 { 274 sizedformat: "RG8UI", 275 unsizedformat: "RG_INTEGER", 276 type: "UNSIGNED_BYTE", 277 }, 278 { 279 sizedformat: "RG8I", 280 unsizedformat: "RG_INTEGER", 281 type: "BYTE", 282 }, 283 { 284 sizedformat: "RG16UI", 285 unsizedformat: "RG_INTEGER", 286 type: "UNSIGNED_SHORT", 287 }, 288 { 289 sizedformat: "RG16I", 290 unsizedformat: "RG_INTEGER", 291 type: "SHORT", 292 }, 293 { 294 sizedformat: "RG32UI", 295 unsizedformat: "RG_INTEGER", 296 type: "UNSIGNED_INT", 297 }, 298 { 299 sizedformat: "RG32I", 300 unsizedformat: "RG_INTEGER", 301 type: "INT", 302 }, 303 { 304 sizedformat: "R8", 305 unsizedformat: "RED", 306 type: "UNSIGNED_BYTE", 307 }, 308 { 309 sizedformat: "R8_SNORM", 310 unsizedformat: "RED", 311 type: "BYTE", 312 }, 313 { 314 sizedformat: "R16F", 315 unsizedformat: "RED", 316 type: "HALF_FLOAT", 317 }, 318 { 319 sizedformat: "R32F", 320 unsizedformat: "RED", 321 type: "FLOAT", 322 }, 323 { 324 sizedformat: "R16F", 325 unsizedformat: "RED", 326 type: "FLOAT", 327 }, 328 { 329 sizedformat: "R8UI", 330 unsizedformat: "RED_INTEGER", 331 type: "UNSIGNED_BYTE", 332 }, 333 { 334 sizedformat: "R8I", 335 unsizedformat: "RED_INTEGER", 336 type: "BYTE", 337 }, 338 { 339 sizedformat: "R16UI", 340 unsizedformat: "RED_INTEGER", 341 type: "UNSIGNED_SHORT", 342 }, 343 { 344 sizedformat: "R16I", 345 unsizedformat: "RED_INTEGER", 346 type: "SHORT", 347 }, 348 { 349 sizedformat: "R32UI", 350 unsizedformat: "RED_INTEGER", 351 type: "UNSIGNED_INT", 352 }, 353 { 354 sizedformat: "R32I", 355 unsizedformat: "RED_INTEGER", 356 type: "INT", 357 }, 358 { 359 sizedformat: "DEPTH_COMPONENT16", 360 unsizedformat: "DEPTH_COMPONENT", 361 type: "UNSIGNED_SHORT", 362 }, 363 { 364 sizedformat: "DEPTH_COMPONENT24", 365 unsizedformat: "DEPTH_COMPONENT", 366 type: "UNSIGNED_INT", 367 }, 368 { 369 sizedformat: "DEPTH_COMPONENT16", 370 unsizedformat: "DEPTH_COMPONENT", 371 type: "UNSIGNED_INT", 372 }, 373 { 374 sizedformat: "DEPTH_COMPONENT32F", 375 unsizedformat: "DEPTH_COMPONENT", 376 type: "FLOAT", 377 }, 378 { 379 sizedformat: "DEPTH24_STENCIL8", 380 unsizedformat: "DEPTH_STENCIL", 381 type: "UNSIGNED_INT_24_8", 382 }, 383 // No good typed array type for this format, just allow this format when pixel is null. 384 { 385 sizedformat: "DEPTH32F_STENCIL8", 386 unsizedformat: "DEPTH_STENCIL", 387 type: "FLOAT_32_UNSIGNED_INT_24_8_REV", 388 }, 389 // internalFormat of texImage2D may be unsized format according Table 3.3 in OpenGL ES 3.0.4 spec. 390 { 391 sizedformat: undefined, 392 unsizedformat: "RGBA", 393 type: "UNSIGNED_BYTE", 394 }, 395 { 396 sizedformat: undefined, 397 unsizedformat: "RGBA", 398 type: "UNSIGNED_SHORT_4_4_4_4", 399 }, 400 { 401 sizedformat: undefined, 402 unsizedformat: "RGBA", 403 type: "UNSIGNED_SHORT_5_5_5_1", 404 }, 405 { 406 sizedformat: undefined, 407 unsizedformat: "RGB", 408 type: "UNSIGNED_BYTE", 409 }, 410 { 411 sizedformat: undefined, 412 unsizedformat: "RGB", 413 type: "UNSIGNED_SHORT_5_6_5", 414 }, 415 { 416 sizedformat: undefined, 417 unsizedformat: "LUMINANCE_ALPHA", 418 type: "UNSIGNED_BYTE", 419 }, 420 { 421 sizedformat: undefined, 422 unsizedformat: "LUMINANCE", 423 type: "UNSIGNED_BYTE", 424 }, 425 { 426 sizedformat: undefined, 427 unsizedformat: "ALPHA", 428 type: "UNSIGNED_BYTE", 429 }, 430 ]; 431 432 texFormats.forEach(function(texformat){ 433 debug(""); 434 debug("Testing sized format " + texformat.sizedformat 435 + ", unsized format " + texformat.unsizedformat 436 + ", type " + texformat.type); 437 var tex = gl.createTexture(); 438 gl.bindTexture(gl.TEXTURE_2D, tex); 439 440 var sizedformat = gl[texformat.sizedformat]; 441 var unsizedformat = gl[texformat.unsizedformat]; 442 var type = gl[texformat.type]; 443 444 // prepare some good data to feed texImage2D and friends for this type 445 var data; 446 switch(type) { 447 case gl.UNSIGNED_BYTE: 448 data = new Uint8Array(4); 449 break; 450 case gl.BYTE: 451 data = new Int8Array(4); 452 break; 453 case gl.UNSIGNED_SHORT: 454 case gl.UNSIGNED_SHORT_4_4_4_4: 455 case gl.UNSIGNED_SHORT_5_5_5_1: 456 case gl.UNSIGNED_SHORT_5_6_5: 457 case gl.HALF_FLOAT: 458 data = new Uint16Array(4); 459 break; 460 case gl.SHORT: 461 data = new Int16Array(4); 462 break; 463 case gl.UNSIGNED_INT: 464 case gl.UNSIGNED_INT_5_9_9_9_REV: 465 case gl.UNSIGNED_INT_10F_11F_11F_REV: 466 case gl.UNSIGNED_INT_2_10_10_10_REV: 467 case gl.UNSIGNED_INT_24_8: 468 data = new Uint32Array(4); 469 break; 470 case gl.INT: 471 data = new Int32Array(4); 472 break; 473 case gl.FLOAT: 474 data = new Float32Array(4); 475 break; 476 case gl.FLOAT_32_UNSIGNED_INT_24_8_REV: 477 data = null; 478 } 479 480 // prepare some bad data that doesn't fit this type 481 var baddata = (data instanceof Float32Array) 482 ? new Uint8Array(4) 483 : new Float32Array(4); 484 485 // test texImage2D with unsized internalformat 486 if (!sizedformat) { 487 gl.texImage2D(gl.TEXTURE_2D, 0, unsizedformat, 1, 1, 0, unsizedformat, type, data); 488 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage2D should succeed with unsized internalformat"); 489 gl.texImage2D(gl.TEXTURE_2D, 0, unsizedformat, 1, 1, 0, unsizedformat, type, baddata); 490 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage2D should fail with unsized internalformat and data of wrong type"); 491 } else { 492 // test texImage2D with sized internalformat 493 gl.texImage2D(gl.TEXTURE_2D, 0, sizedformat, 1, 1, 0, unsizedformat, type, data); 494 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage2D should succeed with sized internalformat"); 495 gl.texImage2D(gl.TEXTURE_2D, 0, sizedformat, 1, 1, 0, unsizedformat, type, baddata); 496 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage2D should fail with sized internalformat and data of wrong type"); 497 } 498 499 // test texSubImage2D 500 if (gl.FLOAT_32_UNSIGNED_INT_24_8_REV != type) { 501 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, data); 502 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed"); 503 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, baddata); 504 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage2D should fail with data of wrong type"); 505 } 506 507 // test texStorage2D 508 if (sizedformat) { 509 gl.texStorage2D(gl.TEXTURE_2D, 1, sizedformat, 1, 1); 510 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texStorage2D should succeed"); 511 if (gl.FLOAT_32_UNSIGNED_INT_24_8_REV != type) { 512 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, data); 513 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed on immutable-format texture"); 514 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, baddata); 515 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage2D should fail on immutable-format texture with data of wrong type"); 516 } 517 } 518 519 // Test a 3D texture. 520 // Formats containing a depth component can't be used for 3D textures. 521 var isdepthformat = 522 unsizedformat == gl.DEPTH_COMPONENT || 523 unsizedformat == gl.DEPTH_STENCIL; 524 if (!isdepthformat) { 525 var tex3d = gl.createTexture(); 526 gl.bindTexture(gl.TEXTURE_3D, tex3d); 527 528 // test texImage3D with unsized internalformat 529 if (!sizedformat) { 530 gl.texImage3D(gl.TEXTURE_3D, 0, unsizedformat, 1, 1, 1, 0, unsizedformat, type, data); 531 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage3D should succeed with unsized internalformat"); 532 gl.texImage3D(gl.TEXTURE_3D, 0, unsizedformat, 1, 1, 1, 0, unsizedformat, type, baddata); 533 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage3D should fail with unsized internalformat and data of wrong type"); 534 } else { 535 // test texImage3D with sized internalformat 536 gl.texImage3D(gl.TEXTURE_3D, 0, sizedformat, 1, 1, 1, 0, unsizedformat, type, data); 537 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage3D should succeed with sized internalformat"); 538 gl.texImage3D(gl.TEXTURE_3D, 0, sizedformat, 1, 1, 1, 0, unsizedformat, type, baddata); 539 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage3D should fail with sized internalformat and data of wrong type"); 540 } 541 542 // test texSubImage3D 543 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, data); 544 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage3D should succeed"); 545 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, baddata); 546 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage3D should fail with data of wrong type"); 547 548 if (sizedformat) { 549 gl.texStorage3D(gl.TEXTURE_3D, 1, sizedformat, 1, 1, 1); 550 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texStorage3D should succeed"); 551 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, data); 552 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage3D should succeed on immutable-format texture"); 553 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, baddata); 554 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage3D should fail on immutable-format texture with data of wrong type"); 555 } 556 } 557 }); 558 } 559 560 function runDepthStencilFormatTest() { 561 debug(""); 562 debug("Testing FLOAT_32_UNSIGNED_INT_24_8_REV with data"); 563 const fb = gl.createFramebuffer(); 564 gl.bindFramebuffer(gl.FRAMEBUFFER, fb); 565 566 const tex2D = gl.createTexture(); 567 gl.bindTexture(gl.TEXTURE_2D, tex2D); 568 gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH32F_STENCIL8, 1, 1, 0, gl.DEPTH_STENCIL, gl.FLOAT_32_UNSIGNED_INT_24_8_REV, new Uint8Array(8)); 569 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION); 570 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_2D, tex2D, 0); 571 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) { 572 testFailed("2D texture with invalid type was created"); 573 } else { 574 testPassed("2D texture with invalid type was not created") 575 } 576 577 const tex3D = gl.createTexture(); 578 gl.bindTexture(gl.TEXTURE_2D_ARRAY, tex3D); 579 gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.DEPTH32F_STENCIL8, 1, 1, 1, 0, gl.DEPTH_STENCIL, gl.FLOAT_32_UNSIGNED_INT_24_8_REV, new Uint8Array(8)); 580 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION); 581 gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, tex3D, 0, 0); 582 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) { 583 testFailed("2D array texture with invalid type was created"); 584 } else { 585 testPassed("2D array texture with invalid type was not created") 586 } 587 } 588 589 debug(""); 590 var successfullyParsed = true; 591 </script> 592 <script src="../../../js/js-test-post.js"></script> 593 594 </body> 595 </html>