summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/misc/uninitialized-test-2.html
blob: 39c439aec2fda9992ec52b6dfc5fb8231f5abfd2 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<!--

/*
** Copyright (c) 2016 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 2 Uninitialized GL Resources 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>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="canvas" width="2" height="2"> </canvas>
<script>
"use strict";
description("Tests to check user code cannot access uninitialized data from GL resources.");

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas", undefined, 2);
if (!gl)
  testFailed("Context created.");
else
  testPassed("Context created.");

function setupTexture(target, texWidth, texHeight, texDepth) {
    var is3d = (target == gl.TEXTURE_3D || target == gl.TEXTURE_2D_ARRAY);
    var texture = gl.createTexture();
    gl.bindTexture(target, texture);
    if (is3d) {
        gl.texImage3D(target, 0, gl.RGBA8, texWidth, texHeight, texDepth, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    } else if (target == gl.TEXTURE_2D) {
        gl.texImage2D(target, 0, gl.RGBA8, texWidth, texHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    } else {
        gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, gl.RGBA8, texWidth, texHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
        gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, gl.RGBA8, texWidth, texHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
        gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, gl.RGBA8, texWidth, texHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
        gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, gl.RGBA8, texWidth, texHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
        gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, gl.RGBA8, texWidth, texHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
        gl.texImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, gl.RGBA8, texWidth, texHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    }

    // this can be quite undeterministic so to improve odds of seeing uninitialized data write bits
    // into tex then delete texture then re-create one with same characteristics (driver will likely reuse mem)
    // with this trick on r59046 WebKit/OSX I get FAIL 100% of the time instead of ~15% of the time.

    var badData = new Uint8Array(texWidth * texHeight * texDepth * 4);
    for (var i = 0; i < badData.length; ++i)
        badData[i] = i % 255;

    if (is3d) {
        gl.texSubImage3D(target, 0, 0, 0, 0, texWidth, texHeight, texDepth, gl.RGBA, gl.UNSIGNED_BYTE, badData);
    } else if (target == gl.TEXTURE_2D) {
        gl.texSubImage2D(target, 0, 0, 0, texWidth, texHeight, gl.RGBA, gl.UNSIGNED_BYTE, badData);
    } else {
        gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X, 0, 0, 0, texWidth, texHeight, gl.RGBA, gl.UNSIGNED_BYTE, badData);
        gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 0, 0, 0, texWidth, texHeight, gl.RGBA, gl.UNSIGNED_BYTE, badData);
        gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 0, 0, 0, texWidth, texHeight, gl.RGBA, gl.UNSIGNED_BYTE, badData);
        gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, 0, 0, texWidth, texHeight, gl.RGBA, gl.UNSIGNED_BYTE, badData);
        gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 0, 0, 0, texWidth, texHeight, gl.RGBA, gl.UNSIGNED_BYTE, badData);
        gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, 0, 0, texWidth, texHeight, gl.RGBA, gl.UNSIGNED_BYTE, badData);
    }
    gl.finish(); // make sure it has been uploaded

    gl.deleteTexture(texture);
    gl.finish(); // make sure it has been deleted

    var texture = gl.createTexture();
    gl.bindTexture(target, texture);
    return texture;
}

function checkNonZeroPixels(texture, target, format, type, texWidth, texHeight, level, layer, exceptions) {
    var tol = 2;
    var is3d = (target == gl.TEXTURE_3D || target == gl.TEXTURE_2D_ARRAY);
    switch (target) {
      case gl.TEXTURE_CUBE_MAP_POSITIVE_X:
      case gl.TEXTURE_CUBE_MAP_NEGATIVE_X:
      case gl.TEXTURE_CUBE_MAP_POSITIVE_Y:
      case gl.TEXTURE_CUBE_MAP_NEGATIVE_Y:
      case gl.TEXTURE_CUBE_MAP_POSITIVE_Z:
      case gl.TEXTURE_CUBE_MAP_NEGATIVE_Z:
        gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
        break;
      default:
        gl.bindTexture(target, null);
        break;
    }
    var fb = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    if (is3d) {
        gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, texture, level, layer);
    } else {
        gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, target, texture, level);
    }
    shouldBe("gl.checkFramebufferStatus(gl.FRAMEBUFFER)", "gl.FRAMEBUFFER_COMPLETE");

    var data;
    switch (type) {
      case gl.UNSIGNED_INT:
        data = new Uint32Array(texWidth * texHeight * 4);
        break;
      case gl.INT:
        data = new Int32Array(texWidth * texHeight * 4);
        break;
      case gl.UNSIGNED_BYTE:
      default:
        data = new Uint8Array(texWidth * texHeight * 4);
        break;
    }
    gl.readPixels(0, 0, texWidth, texHeight, format, type, data);

    var k = 0;
    var failed_exceptions = 0;
    for (var y = 0; y < texHeight; ++y) {
        for (var x = 0; x < texWidth; ++x) {
            var index = (y * texWidth + x) * 4;
            var is_exception = false;
            for (var ii = 0; ii < exceptions.length; ++ii) {
                if (exceptions[ii].x == x && exceptions[ii].y == y) {
                    is_exception = true;
                    if (Math.abs(data[index] - exceptions[ii].r) > tol ||
                        Math.abs(data[index + 1] - exceptions[ii].g) > tol ||
                        Math.abs(data[index + 2] - exceptions[ii].b) > tol ||
                        Math.abs(data[index + 3] - exceptions[ii].a) > tol) {
                        failed_exceptions++;
                    }
                }
            }
            if (is_exception)
                continue;
            for (var i = 0; i < 4; ++i) {
                if (data[index + i] != 0) {
                    k++;
                }
            }
        }
    }
    var info = "Level = " + level;
    if (is3d)
        info  += ", layer = " + layer;
    info += " : ";
    if (k) {
        testFailed(info + "found " + k + " non-zero elements");
    } else {
        testPassed(info + "all data initialized");
    }
    if (exceptions.length > 0) {
        if (failed_exceptions) {
            testFailed(info + "found " + failed_exceptions + " elements incorrectly overwritten");
        } else {
            testPassed(info + "all initialized elements stay untouched");
        }
    }
}

function testTexImage3D() {

    var max_3d_texture_size = Math.min(gl.getParameter(gl.MAX_3D_TEXTURE_SIZE), 1024);

    var test_cases = [
      // TEXTURE_3D + RGBA8
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: 256, // minimum MAX_3D_TEXTURE_SIZE is 256
        height: 256,
        depth: 8,
        exceptions: [ { x: 0, y: 0, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: 256, // minimum MAX_3D_TEXTURE_SIZE is 256
        height: 256,
        depth: 8,
        exceptions: [],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: max_3d_texture_size,
        height: max_3d_texture_size,
        depth: 4,
        exceptions: [ { x: 0, y: 128, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: max_3d_texture_size,
        height: max_3d_texture_size,
        depth: 4,
        exceptions: [],
      },

      // TEXTURE_3D + RGBA8UI
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: 256, // minimum MAX_3D_TEXTURE_SIZE is 256
        height: 256,
        depth: 8,
        exceptions: [ { x: 0, y: 255, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: 256, // minimum MAX_3D_TEXTURE_SIZE is 256
        height: 256,
        depth: 8,
        exceptions: [],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: max_3d_texture_size,
        height: max_3d_texture_size,
        depth: 4,
        exceptions: [ { x: 128, y: 0, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: max_3d_texture_size,
        height: max_3d_texture_size,
        depth: 4,
        exceptions: [],
      },

      // TEXTURE_3D + RGBA8I
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: 256, // minimum MAX_3D_TEXTURE_SIZE is 256
        height: 256,
        depth: 8,
        exceptions: [ { x: 128, y: 255, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: 256, // minimum MAX_3D_TEXTURE_SIZE is 256
        height: 256,
        depth: 8,
        exceptions: [],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: max_3d_texture_size,
        height: max_3d_texture_size,
        depth: 4,
        exceptions: [ { x: 128, y: 128, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_3D",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: max_3d_texture_size,
        height: max_3d_texture_size,
        depth: 4,
        exceptions: [],
      },

      // TEXTURE_2D_ARRAY + RGBA8
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: 1024,
        height: 1024,
        depth: 8,
        exceptions: [ { x: 1023, y: 0, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: 1024,
        height: 1024,
        depth: 8,
        exceptions: [],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: 64,
        height: 64,
        depth: 256,  // minimum MAX_ARRAY_TEXTURE_LAYERS is 256
        exceptions: [ { x: 63, y: 32, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8",
        format: gl.RGBA,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_BYTE,
        width: 64,
        height: 64,
        depth: 256,  // minimum MAX_ARRAY_TEXTURE_LAYERS is 256
        exceptions: [],
      },

      // TEXTURE_2D_ARRAY + RGBA8UI
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: 1024,
        height: 1024,
        depth: 8,
        exceptions: [ { x: 1023, y: 1023, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: 1024,
        height: 1024,
        depth: 8,
        exceptions: [],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: 64,
        height: 64,
        depth: 256,  // minimum MAX_ARRAY_TEXTURE_LAYERS is 256
        exceptions: [ { x: 0, y: 0, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8UI",
        format: gl.RGBA_INTEGER,
        type: gl.UNSIGNED_BYTE,
        read_type: gl.UNSIGNED_INT,
        width: 64,
        height: 64,
        depth: 256,  // minimum MAX_ARRAY_TEXTURE_LAYERS is 256
        exceptions: [],
      },

      // TEXTURE_2D_ARRAY + RGBA8I
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: 1024,
        height: 1024,
        depth: 8,
        exceptions: [ { x: 512, y: 1023, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: 1024,
        height: 1024,
        depth: 8,
        exceptions: [],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: 64,
        height: 64,
        depth: 256,  // minimum MAX_ARRAY_TEXTURE_LAYERS is 256
        exceptions: [ { x: 63, y: 32, r: 108, g: 72, b: 36, a: 9 } ],
      },
      {
        target: "TEXTURE_2D_ARRAY",
        internal_format: "RGBA8I",
        format: gl.RGBA_INTEGER,
        type: gl.BYTE,
        read_type: gl.INT,
        width: 64,
        height: 64,
        depth: 256,  // minimum MAX_ARRAY_TEXTURE_LAYERS is 256
        exceptions: [],
      },
    ];

    for (var ii = 0; ii < test_cases.length; ++ii) {
        debug("");
        var test = test_cases[ii];
        debug("TexImage3D with target = " + test.target + ", internal_format = " + test.internal_format +
              ", width = " + test.width + ", height = " + test.height + ", depth = " + test.depth);
        var tex = setupTexture(gl[test.target], test.width, test.height, test.depth);
        gl.texImage3D(gl[test.target], 0, gl[test.internal_format], test.width, test.height, test.depth, 0, test.format, test.type, null);
        for (var jj = 0; jj < test.exceptions.length; ++jj) {
            var exception = test.exceptions[jj];
            var data;
            switch (test.type) {
              case gl.BYTE:
                data = new Int8Array(4 * test.depth);
                break;
              case gl.UNSIGNED_BYTE:
                data = new Uint8Array(4 * test.depth);
                break;
              default:
                assert(false);
            }
            for (var pixel = 0; pixel < test.depth; ++pixel) {
                data[pixel * 4] = exception.r;
                data[pixel * 4 + 1] = exception.g;
                data[pixel * 4 + 2] = exception.b;
                data[pixel * 4 + 3] = exception.a;
            }
            gl.texSubImage3D(gl[test.target], 0, exception.x, exception.y, 0, 1, 1, test.depth, test.format, test.type, data);
        }
        for (var layer = 0; layer < test.depth; ++layer)
            checkNonZeroPixels(tex, gl[test.target], test.format, test.read_type, test.width, test.height, 0, layer, test.exceptions);
        gl.deleteTexture(tex);
        gl.finish();
        wtu.glErrorShouldBe(gl, gl.NO_ERROR);
    }
}

function testTexStorage2D() {
    var targets = [ "TEXTURE_2D", "TEXTURE_CUBE_MAP" ];
    var width = 512;
    var height = 512;
    var levels = 5;

    for (var ii = 0; ii < targets.length; ++ii) {
        debug("");
        debug("Reading an uninitialized texture (texStorage2D) should succeed with all bytes set to 0 : target = " + targets[ii]);
        var tex = setupTexture(gl[targets[ii]], width, height, 1);
        gl.texStorage2D(gl[targets[ii]], levels, gl.RGBA8, width, height);
        for (var level = 0; level < levels; ++level) {
            if (gl[targets[ii]] == gl.TEXTURE_2D) {
                checkNonZeroPixels(tex, gl[targets[ii]], gl.RGBA, gl.UNSIGNED_BYTE, width, height, level, 0, []);
            } else {
                checkNonZeroPixels(tex, gl.TEXTURE_CUBE_MAP_POSITIVE_X, gl.RGBA, gl.UNSIGNED_BYTE, width, height, level, 0, []);
                checkNonZeroPixels(tex, gl.TEXTURE_CUBE_MAP_NEGATIVE_X, gl.RGBA, gl.UNSIGNED_BYTE, width, height, level, 0, []);
                checkNonZeroPixels(tex, gl.TEXTURE_CUBE_MAP_POSITIVE_Y, gl.RGBA, gl.UNSIGNED_BYTE, width, height, level, 0, []);
                checkNonZeroPixels(tex, gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, gl.RGBA, gl.UNSIGNED_BYTE, width, height, level, 0, []);
                checkNonZeroPixels(tex, gl.TEXTURE_CUBE_MAP_POSITIVE_Z, gl.RGBA, gl.UNSIGNED_BYTE, width, height, level, 0, []);
                checkNonZeroPixels(tex, gl.TEXTURE_CUBE_MAP_NEGATIVE_Z, gl.RGBA, gl.UNSIGNED_BYTE, width, height, level, 0, []);
            }
        }
        gl.deleteTexture(tex);
        gl.finish();
        wtu.glErrorShouldBe(gl, gl.NO_ERROR);
    }
}

function testTexStorage3D() {
    var targets = [ "TEXTURE_3D", "TEXTURE_2D_ARRAY" ];
    var internal_formats = [ "RGBA8", "RGBA8UI", "RGBA8I" ];
    var formats = [ gl.RGBA, gl.RGBA_INTEGER, gl.RGBA_INTEGER ];
    var read_types = [ gl.UNSIGNED_BYTE, gl.UNSIGNED_INT, gl.INT ];
    var width = 256;  // minimum MAX_3D_TEXTURE_SIZE is 256
    var height = 256;  // minimum MAX_3D_TEXTURE_SIZE is 256
    var depth = 8;
    var levels = 5;

    for (var ii = 0; ii < targets.length; ++ii) {
        debug("");
        debug("Reading an uninitialized texture (texStorage3D) should succeed with all bytes set to 0 : target = " + targets[ii]);
        for (var jj = 0; jj < internal_formats.length; ++jj) {
            debug("");
            debug("Internal format : " + internal_formats[jj]);
            var tex = setupTexture(gl[targets[ii]], width, height, depth);
            gl.texStorage3D(gl[targets[ii]], levels, gl[internal_formats[jj]], width, height, depth);
            var level_depth = depth;
            for (var level = 0; level < levels; ++level) {
                for (var layer = 0; layer < level_depth; ++layer) {
                    checkNonZeroPixels(tex, gl[targets[ii]], formats[jj], read_types[jj], width, height, level, layer, []);
                }
                if (gl[targets[ii]] == gl.TEXTURE_3D)
                    level_depth = Math.max(1, level_depth >> 1);
            }
            gl.deleteTexture(tex);
            gl.finish();
            wtu.glErrorShouldBe(gl, gl.NO_ERROR);
        }
    }
}

testTexImage3D();
testTexStorage2D();
testTexStorage3D();

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