Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / extensions / webgl-compressed-texture-etc.html
blob8a85239ff9d5a20687506b866cd1b21a3ba4f0dd
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 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL WEBGL_compressed_texture_etc 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 WEBGL_compressed_texture_etc extension, if it is available.");
24 debug("");
26 var validFormats = {
27 COMPRESSED_R11_EAC : 0x9270,
28 COMPRESSED_SIGNED_R11_EAC : 0x9271,
29 COMPRESSED_RG11_EAC : 0x9272,
30 COMPRESSED_SIGNED_RG11_EAC : 0x9273,
31 COMPRESSED_RGB8_ETC2 : 0x9274,
32 COMPRESSED_SRGB8_ETC2 : 0x9275,
33 COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9276,
34 COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9277,
35 COMPRESSED_RGBA8_ETC2_EAC : 0x9278,
36 COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : 0x9279
39 function expectedByteLength(width, height, format) {
40 var blockSizeInBytes = 8;
42 var largerBlockFormats = [
43 validFormats.COMPRESSED_RG11_EAC,
44 validFormats.COMPRESSED_SIGNED_RG11_EAC,
45 validFormats.COMPRESSED_RGBA8_ETC2_EAC,
46 validFormats.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC];
48 if (largerBlockFormats.indexOf(format) >= 0) {
49 blockSizeInBytes = 16;
52 return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * blockSizeInBytes;
55 function getBlockDimensions(format) {
56 return {width: 4, height: 4};
59 var wtu = WebGLTestUtils;
60 var ctu = CompressedTextureUtils;
61 var contextVersion = wtu.getDefault3DContextVersion();
62 var gl = wtu.create3DContext();
63 var WEBGL_compressed_texture_etc;
65 var formats = null;
67 function runTest() {
68 if (!gl) {
69 testFailed("context does not exist");
70 } else {
71 testPassed("context exists");
73 ctu.testCompressedFormatsUnavailableWhenExtensionDisabled(gl, validFormats, expectedByteLength, 4);
75 WEBGL_compressed_texture_etc = gl.getExtension("WEBGL_compressed_texture_etc");
77 wtu.runExtensionSupportedTest(gl, "WEBGL_compressed_texture_etc", WEBGL_compressed_texture_etc !== null);
79 var isPositive = WEBGL_compressed_texture_etc !== null;
81 if (isPositive) {
82 // Test that enum values are listed correctly in supported formats and in the extension object.
83 ctu.testCompressedFormatsListed(gl, validFormats);
84 ctu.testCorrectEnumValuesInExt(WEBGL_compressed_texture_etc, validFormats);
85 // Test that texture upload buffer size is validated correctly.
86 ctu.testFormatRestrictionsOnBufferSize(gl, validFormats, expectedByteLength, getBlockDimensions);
88 var tex = gl.createTexture();
89 gl.bindTexture(gl.TEXTURE_2D, tex);
91 for (var name in validFormats) {
92 if (validFormats.hasOwnProperty(name)) {
93 var format = validFormats[name];
94 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.compressedTexImage2D(gl.TEXTURE_2D, 0, " + format + ", 4, 4, 0, new Uint8Array(" + expectedByteLength(4, 4, format) + "))");
95 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 4, 4, " + format + ", new Uint8Array(" + expectedByteLength(4, 4, format) + "))");
100 var tex2 = gl.createTexture();
101 gl.bindTexture(gl.TEXTURE_2D, tex2);
103 debug("");
104 if (contextVersion >= 2) {
105 var expectedError = isPositive ? gl.INVALID_OPERATION: [gl.INVALID_ENUM, gl.INVALID_OPERATION];
106 // `null` coerces into `0` for the PBO entrypoint, yielding INVALID_OP due to no PBO bound.
107 wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexImage2D(gl.TEXTURE_2D, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 0, 0, null)");
108 wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, 0, null)");
109 wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 4, 0, 0, null)");
110 wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, 0, null)");
111 } else {
112 shouldThrow("gl.compressedTexImage2D(gl.TEXTURE_2D, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 0, null)");
113 shouldThrow("gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, null)");
114 shouldThrow("gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 4, 0, null)");
115 shouldThrow("gl.compressedTexSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, null)");
120 runTest();
122 var successfullyParsed = true;
123 </script>
124 <script src="../../js/js-test-post.js"></script>
125 </body>
126 </html>