summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webgl/conformance-1.0.3/conformance/textures/texture-size-limit.html
blob: 176e1ce96a16ced1d542bfa2c6d7dfedd49a550f (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
163
164
165
166
167
168
169
170
171
172
173
174
175
<!--

/*
** Copyright (c) 2012 The Khronos Group Inc.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and/or associated documentation files (the
** "Materials"), to deal in the Materials without restriction, including
** without limitation the rights to use, copy, modify, merge, publish,
** distribute, sublicense, and/or sell copies of the Materials, and to
** permit persons to whom the Materials are furnished to do so, subject to
** the following conditions:
**
** The above copyright notice and this permission notice shall be included
** in all copies or substantial portions of the Materials.
**
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/

-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL texture size limit conformance test.</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="../../resources/js-test-pre.js"></script>
<script src="../resources/webgl-test-utils.js"></script>
</head>
<body>
<canvas id="example" width="32" height="32" style="width: 40px; height: 40px;"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description("Checks various size limits of textures")
var canvas;

function numLevelsFromSize(size) {
  var levels = 0;
  while ((size >> levels) > 0) {
    ++levels;
  }
  return levels;
}

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var tests = [
  { format: gl.ALPHA,           type: gl.UNSIGNED_BYTE,          size: 1, dataType: Uint8Array  },
  { format: gl.LUMINANCE,       type: gl.UNSIGNED_BYTE,          size: 1, dataType: Uint8Array  },
  { format: gl.LUMINANCE_ALPHA, type: gl.UNSIGNED_BYTE,          size: 2, dataType: Uint8Array  },
  { format: gl.RGB,             type: gl.UNSIGNED_BYTE,          size: 3, dataType: Uint8Array  },
  { format: gl.RGB,             type: gl.UNSIGNED_SHORT_5_6_5,   size: 1, dataType: Uint16Array },
  { format: gl.RGBA,            type: gl.UNSIGNED_BYTE,          size: 4, dataType: Uint8Array  },
  { format: gl.RGBA,            type: gl.UNSIGNED_SHORT_4_4_4_4, size: 1, dataType: Uint16Array },
  { format: gl.RGBA,            type: gl.UNSIGNED_SHORT_5_5_5_1, size: 1, dataType: Uint16Array }
];

// Note: We expressly only use 2 textures because first a texture will be defined
// using all mip levels of 1 format, then for a moment it will have mixed formats which
// may uncover bugs.
var targets = [
  { target: gl.TEXTURE_2D,
    maxSize: gl.getParameter(gl.MAX_TEXTURE_SIZE),
    maxLevel: 1000,
    tex: gl.createTexture(),
    targets: [gl.TEXTURE_2D]
  },
  { target: gl.TEXTURE_CUBE_MAP,
    maxSize: gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE),
    maxLevel: 5,
    tex: gl.createTexture(),
    targets: [
      gl.TEXTURE_CUBE_MAP_POSITIVE_X,
      gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
      gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
      gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
      gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
      gl.TEXTURE_CUBE_MAP_NEGATIVE_Z
    ]
  }
];

gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);

var trg = 0;
var tt = 0;
runNextTest();

function runNextTest() {
  var t = targets[trg];

  if (tt == 0) {
    var tex = t.tex;
    gl.bindTexture(t.target, tex);

    debug("");
    debug("max size for " + wtu.glEnumToString(gl, t.target) + ": " + t.maxSize);
    var numLevels = numLevelsFromSize(t.maxSize);
    debug("num levels " + numLevels);
  }

  var test = tests[tt];
  testFormatType(t, test);
  ++tt;
  if (tt == tests.length) {
    tt = 0;
    ++trg;
    if (trg == targets.length) {
      finishTest();
      return;
    }
  }
  wtu.waitForComposite(runNextTest)
}

function testFormatType(t, test) {
  debug("");
  debug("testing: " + wtu.glEnumToString(gl, test.format) + ", " + wtu.glEnumToString(gl, test.type));
  for (var j = 0; j < t.targets.length; ++j) {
    var target = t.targets[j];
    debug("");
    debug(wtu.glEnumToString(gl, target));
    var numLevels = numLevelsFromSize(t.maxSize);
    var numTestLevels = Math.min(numLevels, t.maxLevel);

    // out of bounds tests
    // level out of bounds
    gl.texImage2D(target, numLevels, test.format, 1, 1, 0, test.format, test.type, null);
    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "level out of bounds: should generate INVALID_VALUE: level is: "
        + numLevels + ", size is 1x1.");
    // width and height out of bounds
    gl.texImage2D(target, 0, test.format, t.maxSize + 1, t.maxSize + 1, 0, test.format, test.type, null);
    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "width or height out of bounds: should generate INVALID_VALUE: level is 0, size is "
        + (t.maxSize + 1) + "x" + (t.maxSize + 1));
    // width and height out of bounds for specified level
    gl.texImage2D(target, (numLevels - 1), test.format, 4, 4, 0, test.format, test.type, null);
    wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "width or height out of bounds for specified level: should generate INVALID_VALUE: level is "
        + (numLevels - 1) + ", size is 4x4.");

    for (var l = 0; l < numTestLevels; ++l) {
      // Do bottom levels first;
      var size = 1 << l;
      var level = numLevels - l - 1;
      var otherDimension = t.target == gl.TEXTURE_2D ? 1 : size;
      var badSize = size * 2;
      var badOtherDimension = t.target == gl.TEXTURE_2D ? 1 : badSize;
      var pixels = new test.dataType(badSize * badOtherDimension * test.size);
      gl.texImage2D(target, level, test.format, size, otherDimension, 0, test.format, test.type, pixels);
      wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no error for level: " + level + " " + size + "x" + otherDimension);
      gl.texImage2D(target, level, test.format, otherDimension, size, 0, test.format, test.type, pixels);
      wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no error for level: " + level + " " + otherDimension + "x" + size);
      gl.texImage2D(target, level, test.format, badSize, badOtherDimension, 0, test.format, test.type, pixels);
      wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "should generate INVALID_VALUE for level: " + level + " " + badSize + "x" + badOtherDimension);
      gl.texImage2D(target, level, test.format, badOtherDimension, badSize, 0, test.format, test.type, pixels);
      wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "should generate INVALID_VALUE for level: " + level + " " + badOtherDimension + "x" + badSize);
    }
  }
}

var successfullyParsed = true;
</script>
</body>
</html>