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