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.
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>
18 <div id=
"description"></div>
19 <div id=
"console"></div>
22 description("This test verifies the functionality of the EXT_texture_compression_rgtc extension, if it is available.");
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
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;
38 return Math
.ceil(width
/ 4) * Math
.ceil(height
/ 4) * 16;
42 function getBlockDimensions(format
) {
43 return {width
: 4, height
: 4};
46 var wtu
= WebGLTestUtils
;
47 var ctu
= CompressedTextureUtils
;
48 var contextVersion
= wtu
.getDefault3DContextVersion();
49 var gl
= wtu
.create3DContext();
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
,
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" },
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.
86 let npotExpectation
, npotMessage
;
87 if (contextVersion
>= 2) {
88 npotExpectation
= gl
.NO_ERROR
;
89 npotMessage
= "valid";
91 npotExpectation
= gl
.INVALID_VALUE
;
92 npotMessage
= "invalid";
95 ctu
.testTexImageLevelDimensions(gl
, ext
, validFormats
, expectedByteLength
, getBlockDimensions
,
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
},
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
);
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");
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");
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");
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");
134 gl
.deleteTexture(tex
);
140 testFailed("context does not exist");
142 testPassed("context exists");
144 ctu
.testCompressedFormatsUnavailableWhenExtensionDisabled(gl
, validFormats
, expectedByteLength
, 4);
146 ext
= gl
.getExtension("EXT_texture_compression_rgtc");
148 wtu
.runExtensionSupportedTest(gl
, "EXT_texture_compression_rgtc", ext
!== null);
158 var successfullyParsed
= true;
160 <script src=
"../../js/js-test-post.js"></script>