summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/extensions/ext-texture-compression-rgtc.html
blob: d9c34af25f3c3a32ab7b46cbfed0c4e8e91bef65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL EXT_texture_compression_rgtc Conformance Tests</title>
<LINK rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
<script src="../../js/tests/compressed-texture-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("This test verifies the functionality of the EXT_texture_compression_rgtc extension, if it is available.");

debug("");

var validFormats = {
  COMPRESSED_RED_RGTC1_EXT: 0x8DBB,
  COMPRESSED_SIGNED_RED_RGTC1_EXT: 0x8DBC,
  COMPRESSED_RED_GREEN_RGTC2_EXT: 0x8DBD,
  COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 0x8DBE
};

function expectedByteLength(width, height, format) {
  if (format == validFormats.COMPRESSED_RED_RGTC1_EXT || format == validFormats.COMPRESSED_SIGNED_RED_RGTC1_EXT) {
    return Math.ceil(width / 4) * Math.ceil(height / 4) * 8;
  }
  else {
    return Math.ceil(width / 4) * Math.ceil(height / 4) * 16;
  }
}

function getBlockDimensions(format) {
  return {width: 4, height: 4};
}

var wtu = WebGLTestUtils;
var ctu = CompressedTextureUtils;
var contextVersion = wtu.getDefault3DContextVersion();
var gl = wtu.create3DContext();
var ext;

var formats = null;

function runTestExtension() {
  // Test that enum values are listed correctly in supported formats and in the extension object.
  ctu.testCompressedFormatsListed(gl, validFormats);
  ctu.testCorrectEnumValuesInExt(ext, validFormats);
  // Test that texture upload buffer size is validated correctly.
  ctu.testFormatRestrictionsOnBufferSize(gl, validFormats, expectedByteLength, getBlockDimensions);
  // Test TexSubImage validation on dimensions
  // CompressedTexSubImage* will result in an
  // INVALID_OPERATION error only if one of the following conditions occurs:
  // * <width> is not a multiple of four, and <width> plus <xoffset> is not
  // equal to TEXTURE_WIDTH;
  // * <height> is not a multiple of four, and <height> plus <yoffset> is
  //           not equal to TEXTURE_HEIGHT; or
  // * <xoffset> or <yoffset> is not a multiple of four.
  ctu.testTexSubImageDimensions(gl, ext, validFormats, expectedByteLength, getBlockDimensions,
    16, 16, [
      { xoffset: 0, yoffset: 0, width: 4, height: 3,
        expectation: gl.INVALID_OPERATION, message: "height is not a multiple of 4" },
      { xoffset: 0, yoffset: 0, width: 3, height: 4,
        expectation: gl.INVALID_OPERATION, message: "width is not a multiple of 4" },
      { xoffset: 1, yoffset: 0, width: 4, height: 4,
        expectation: gl.INVALID_OPERATION, message: "xoffset is not a multiple of 4" },
      { xoffset: 0, yoffset: 1, width: 4, height: 4,
        expectation: gl.INVALID_OPERATION, message: "yoffset is not a multiple of 4" },
      { xoffset: 12, yoffset: 12, width: 4, height: 4,
        expectation: gl.NO_ERROR, message: "is valid" },
  ]);

  // Test TexImage validation on level dimensions combinations.
  // When level equals 0, width and height must be a multiple of 4.
  // When level is larger than 0, this constraint doesn't apply.

  let npotExpectation, npotMessage;
  if (contextVersion >= 2) {
    npotExpectation = gl.NO_ERROR;
    npotMessage = "valid";
  } else {
    npotExpectation = gl.INVALID_VALUE;
    npotMessage = "invalid";
  }

  ctu.testTexImageLevelDimensions(gl, ext, validFormats, expectedByteLength, getBlockDimensions,
    [
      { level: 0, width: 4, height: 3,
        expectation: gl.INVALID_OPERATION, message: "level is 0, height is not a multiple of 4" },
      { level: 0, width: 3, height: 4,
        expectation: gl.INVALID_OPERATION, message: "level is 0, width is not a multiple of 4" },
      { level: 0, width: 2, height: 2,
        expectation: gl.INVALID_OPERATION, message: "level is 0, width is not a multiple of 4" },
      { level: 0, width: 4, height: 4,
        expectation: gl.NO_ERROR, message: "is valid" },
      { level: 1, width: 1, height: 1,
        expectation: gl.INVALID_OPERATION, message: "implied base mip 2x2 is invalid" },
      { level: 1, width: 1, height: 2,
        expectation: gl.INVALID_OPERATION, message: "implied base mip 2x4 is invalid" },
      { level: 1, width: 2, height: 1,
        expectation: gl.INVALID_OPERATION, message: "implied base mip 4x2 is invalid" },
      { level: 1, width: 2, height: 2,
        expectation: gl.NO_ERROR, message: "implied base mip 4x4 is valid" },
      { level: 2, width: 1, height: 3,
        expectation: npotExpectation, message: "implied base mip 4x12 is " + npotMessage },
  ]);

  // Test that RGTC enums are not accepted by texImage2D
  if (contextVersion >= 2) {
    var tex = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex);

    gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_RED_RGTC1_EXT, 4, 4, 0, gl.RED, gl.UNSIGNED_BYTE, null);
    wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_RED_RGTC1_EXT fails with texImage2D");

    gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_SIGNED_RED_RGTC1_EXT, 4, 4, 0, gl.RED, gl.BYTE, null);
    wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_SIGNED_RED_RGTC1_EXT fails with texImage2D");

    gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_RED_GREEN_RGTC2_EXT, 4, 4, 0, gl.RG, gl.UNSIGNED_BYTE, null);
    wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_RED_GREEN_RGTC2_EXT fails with texImage2D");

    gl.texImage2D(gl.TEXTURE_2D, 0, ext.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, 4, 4, 0, gl.RG, gl.BYTE, null);
    wtu.glErrorShouldBe(gl, [gl.INVALID_VALUE, gl.INVALID_OPERATION], "COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT fails with texImage2D");

    gl.deleteTexture(tex);
  }
};

function runTest() {
  if (!gl) {
    testFailed("context does not exist");
  } else {
    testPassed("context exists");

    ctu.testCompressedFormatsUnavailableWhenExtensionDisabled(gl, validFormats, expectedByteLength, 4);

    ext = gl.getExtension("EXT_texture_compression_rgtc");

    wtu.runExtensionSupportedTest(gl, "EXT_texture_compression_rgtc", ext !== null);

    if (ext !== null) {
      runTestExtension();
    }
  }
}

runTest();

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>