ext-texture-compression-bptc.html (6380B)
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>WebGL EXT_texture_compression_bptc Conformance Tests</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 <script src="../../js/tests/compressed-texture-utils.js"></script> 16 </head> 17 <body> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script> 21 "use strict"; 22 description("This test verifies the functionality of the EXT_texture_compression_bptc extension, if it is available."); 23 24 debug(""); 25 26 var validFormats = { 27 COMPRESSED_RGBA_BPTC_UNORM_EXT: 0x8E8C, 28 COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: 0x8E8D, 29 COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: 0x8E8E, 30 COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: 0x8E8F 31 }; 32 33 function expectedByteLength(width, height, format) { 34 return Math.ceil(width / 4) * Math.ceil(height / 4) * 16; 35 } 36 37 function getBlockDimensions(format) { 38 return {width: 4, height: 4}; 39 } 40 41 var wtu = WebGLTestUtils; 42 var ctu = CompressedTextureUtils; 43 var contextVersion = wtu.getDefault3DContextVersion(); 44 var gl = wtu.create3DContext(); 45 var ext; 46 47 var formats = null; 48 49 function runTestExtension() { 50 // Test that enum values are listed correctly in supported formats and in the extension object. 51 ctu.testCompressedFormatsListed(gl, validFormats); 52 ctu.testCorrectEnumValuesInExt(ext, validFormats); 53 // Test that texture upload buffer size is validated correctly. 54 ctu.testFormatRestrictionsOnBufferSize(gl, validFormats, expectedByteLength, getBlockDimensions); 55 // Test TexSubImage validation on dimensions 56 // CompressedTexSubImage* will result in an 57 // INVALID_OPERATION error only if one of the following conditions occurs: 58 // * <width> is not a multiple of four, and <width> plus <xoffset> is not 59 // equal to TEXTURE_WIDTH; 60 // * <height> is not a multiple of four, and <height> plus <yoffset> is 61 // not equal to TEXTURE_HEIGHT; or 62 // * <xoffset> or <yoffset> is not a multiple of four. 63 ctu.testTexSubImageDimensions(gl, ext, validFormats, expectedByteLength, getBlockDimensions, 64 16, 16, [ 65 { xoffset: 0, yoffset: 0, width: 4, height: 3, 66 expectation: gl.INVALID_OPERATION, message: "height is not a multiple of 4" }, 67 { xoffset: 0, yoffset: 0, width: 3, height: 4, 68 expectation: gl.INVALID_OPERATION, message: "width is not a multiple of 4" }, 69 { xoffset: 1, yoffset: 0, width: 4, height: 4, 70 expectation: gl.INVALID_OPERATION, message: "xoffset is not a multiple of 4" }, 71 { xoffset: 0, yoffset: 1, width: 4, height: 4, 72 expectation: gl.INVALID_OPERATION, message: "yoffset is not a multiple of 4" }, 73 { xoffset: 12, yoffset: 12, width: 4, height: 4, 74 expectation: gl.NO_ERROR, message: "is valid" }, 75 ]); 76 77 // Test TexImage validation on level dimensions combinations. 78 // When level equals 0, width and height must be a multiple of 4. 79 // When level is larger than 0, this constraint doesn't apply. 80 81 let npotExpectation, npotMessage; 82 if (contextVersion >= 2) { 83 npotExpectation = gl.NO_ERROR; 84 npotMessage = "valid"; 85 } else { 86 npotExpectation = gl.INVALID_VALUE; 87 npotMessage = "invalid"; 88 } 89 90 ctu.testTexImageLevelDimensions(gl, ext, validFormats, expectedByteLength, getBlockDimensions, 91 [ 92 { level: 0, width: 4, height: 3, 93 expectation: gl.INVALID_OPERATION, message: "level is 0, height is not a multiple of 4" }, 94 { level: 0, width: 3, height: 4, 95 expectation: gl.INVALID_OPERATION, message: "level is 0, width is not a multiple of 4" }, 96 { level: 0, width: 2, height: 2, 97 expectation: gl.INVALID_OPERATION, message: "level is 0, width is not a multiple of 4" }, 98 { level: 0, width: 4, height: 4, 99 expectation: gl.NO_ERROR, message: "is valid" }, 100 { level: 1, width: 1, height: 1, 101 expectation: gl.INVALID_OPERATION, message: "implied base mip 2x2 is invalid" }, 102 { level: 1, width: 1, height: 2, 103 expectation: gl.INVALID_OPERATION, message: "implied base mip 2x4 is invalid" }, 104 { level: 1, width: 2, height: 1, 105 expectation: gl.INVALID_OPERATION, message: "implied base mip 4x2 is invalid" }, 106 { level: 1, width: 2, height: 2, 107 expectation: gl.NO_ERROR, message: "implied base mip 4x4 is valid" }, 108 { level: 2, width: 1, height: 3, 109 expectation: npotExpectation, message: "implied base mip 4x12 is " + npotMessage }, 110 ]); 111 112 // Test that BPTC enums are not accepted by texImage2D 113 { 114 var tex = gl.createTexture(); 115 gl.bindTexture(gl.TEXTURE_2D, tex); 116 117 gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_RGBA_BPTC_UNORM_EXT, 4, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 118 wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_RGBA_BPTC_UNORM_EXT fails with texImage2D"); 119 120 gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, 4, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 121 wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT fails with texImage2D"); 122 123 if (contextVersion >= 2) { 124 gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, 4, 4, 0, gl.RGB, gl.FLOAT, null); 125 wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT fails with texImage2D"); 126 127 gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4, 4, 0, gl.RGB, gl.FLOAT, null); 128 wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT fails with texImage2D"); 129 } 130 131 gl.deleteTexture(tex); 132 } 133 }; 134 135 function runTest() { 136 if (!gl) { 137 testFailed("context does not exist"); 138 } else { 139 testPassed("context exists"); 140 141 ctu.testCompressedFormatsUnavailableWhenExtensionDisabled(gl, validFormats, expectedByteLength, 4); 142 143 ext = gl.getExtension("EXT_texture_compression_bptc"); 144 145 wtu.runExtensionSupportedTest(gl, "EXT_texture_compression_bptc", ext !== null); 146 147 if (ext !== null) { 148 runTestExtension(); 149 } 150 } 151 } 152 153 runTest(); 154 155 var successfullyParsed = true; 156 </script> 157 <script src="../../js/js-test-post.js"></script> 158 </body> 159 </html>