summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/extensions/webgl-compressed-texture-etc.html
blob: 8a85239ff9d5a20687506b866cd1b21a3ba4f0dd (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
<!--
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 WEBGL_compressed_texture_etc 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 WEBGL_compressed_texture_etc extension, if it is available.");

debug("");

var validFormats = {
  COMPRESSED_R11_EAC                        : 0x9270,
  COMPRESSED_SIGNED_R11_EAC                 : 0x9271,
  COMPRESSED_RG11_EAC                       : 0x9272,
  COMPRESSED_SIGNED_RG11_EAC                : 0x9273,
  COMPRESSED_RGB8_ETC2                      : 0x9274,
  COMPRESSED_SRGB8_ETC2                     : 0x9275,
  COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2  : 0x9276,
  COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 : 0x9277,
  COMPRESSED_RGBA8_ETC2_EAC                 : 0x9278,
  COMPRESSED_SRGB8_ALPHA8_ETC2_EAC          : 0x9279
};

function expectedByteLength(width, height, format) {
  var blockSizeInBytes = 8;

  var largerBlockFormats = [
    validFormats.COMPRESSED_RG11_EAC,
    validFormats.COMPRESSED_SIGNED_RG11_EAC,
    validFormats.COMPRESSED_RGBA8_ETC2_EAC,
    validFormats.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC];

  if (largerBlockFormats.indexOf(format) >= 0) {
    blockSizeInBytes = 16;
  }

  return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * blockSizeInBytes;
}

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

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

var formats = null;

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

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

    WEBGL_compressed_texture_etc = gl.getExtension("WEBGL_compressed_texture_etc");

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

    var isPositive = WEBGL_compressed_texture_etc !== null;

    if (isPositive) {
      // Test that enum values are listed correctly in supported formats and in the extension object.
      ctu.testCompressedFormatsListed(gl, validFormats);
      ctu.testCorrectEnumValuesInExt(WEBGL_compressed_texture_etc, validFormats);
      // Test that texture upload buffer size is validated correctly.
      ctu.testFormatRestrictionsOnBufferSize(gl, validFormats, expectedByteLength, getBlockDimensions);

      var tex = gl.createTexture();
      gl.bindTexture(gl.TEXTURE_2D, tex);

      for (var name in validFormats) {
        if (validFormats.hasOwnProperty(name)) {
          var format = validFormats[name];
          wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.compressedTexImage2D(gl.TEXTURE_2D, 0, " + format + ", 4, 4, 0, new Uint8Array(" + expectedByteLength(4, 4, format) + "))");
          wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 4, 4, " + format + ", new Uint8Array(" + expectedByteLength(4, 4, format) + "))");
        }
      }
    }

    var tex2 = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex2);

    debug("");
    if (contextVersion >= 2) {
      var expectedError = isPositive ? gl.INVALID_OPERATION: [gl.INVALID_ENUM, gl.INVALID_OPERATION];
      // `null` coerces into `0` for the PBO entrypoint, yielding INVALID_OP due to no PBO bound.
      wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexImage2D(gl.TEXTURE_2D, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 0, 0, null)");
      wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, 0, null)");
      wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 4, 0, 0, null)");
      wtu.shouldGenerateGLError(gl, expectedError, "gl.compressedTexSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, 0, null)");
    } else {
      shouldThrow("gl.compressedTexImage2D(gl.TEXTURE_2D, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 0, null)");
      shouldThrow("gl.compressedTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, null)");
      shouldThrow("gl.compressedTexImage3D(gl.TEXTURE_2D_ARRAY, 0, validFormats.COMPRESSED_R11_EAC, 4, 4, 4, 0, null)");
      shouldThrow("gl.compressedTexSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, 0, 0, 0, validFormats.COMPRESSED_R11_EAC, null)");
    }
  }
}

runTest();

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