summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/textures/misc/tex-new-formats.html
blob: 760bc6bd1947a4e141935dfe0d885a97ba3ba88a (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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
<!--
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>Conformance test for WebGL2 texture image formats specification</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>
<canvas id="canvas" width="64" height="64"> </canvas>
<div id="console"></div>


<script>
"use strict";
description("This test verifies that texture image specification entry points " +
            "accept new formats introduced in WebGL2, and accept sized internalformats.");

debug("");

var wtu = WebGLTestUtils;
var canvas = document.getElementById("canvas");
var gl = wtu.create3DContext(canvas, null, 2);
var vao = null;

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

    runTexFormatsTest();
    runDepthStencilFormatTest();

    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
}

function enumToString(value) {
  return wtu.glEnumToString(gl, value);
}

function runTexFormatsTest()
{
    // texFormats is Table 3.2 and Table 3.3 from the OpenGL ES 3.0.4 spec.
    var texFormats = [
        {
            sizedformat: "RGBA8",
            unsizedformat: "RGBA",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RGB5_A1",
            unsizedformat: "RGBA",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RGBA4",
            unsizedformat: "RGBA",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "SRGB8_ALPHA8",
            unsizedformat: "RGBA",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RGBA8_SNORM",
            unsizedformat: "RGBA",
            type: "BYTE",
        },
        {
            sizedformat: "RGBA4",
            unsizedformat: "RGBA",
            type: "UNSIGNED_SHORT_4_4_4_4",
        },
        {
            sizedformat: "RGB5_A1",
            unsizedformat: "RGBA",
            type: "UNSIGNED_SHORT_5_5_5_1",
        },
        {
            sizedformat: "RGB10_A2",
            unsizedformat: "RGBA",
            type: "UNSIGNED_INT_2_10_10_10_REV",
        },
        {
            sizedformat: "RGB5_A1",
            unsizedformat: "RGBA",
            type: "UNSIGNED_INT_2_10_10_10_REV",
        },
        {
            sizedformat: "RGBA16F",
            unsizedformat: "RGBA",
            type: "HALF_FLOAT",
        },
        {
            sizedformat: "RGBA32F",
            unsizedformat: "RGBA",
            type: "FLOAT",
        },
        {
            sizedformat: "RGBA16F",
            unsizedformat: "RGBA",
            type: "FLOAT",
        },
        {
            sizedformat: "RGBA8UI",
            unsizedformat: "RGBA_INTEGER",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RGBA8I",
            unsizedformat: "RGBA_INTEGER",
            type: "BYTE",
        },
        {
            sizedformat: "RGBA16UI",
            unsizedformat: "RGBA_INTEGER",
            type: "UNSIGNED_SHORT",
        },
        {
            sizedformat: "RGBA16I",
            unsizedformat: "RGBA_INTEGER",
            type: "SHORT",
        },
        {
            sizedformat: "RGBA32UI",
            unsizedformat: "RGBA_INTEGER",
            type: "UNSIGNED_INT",
        },
        {
            sizedformat: "RGBA32I",
            unsizedformat: "RGBA_INTEGER",
            type: "INT",
        },
        {
            sizedformat: "RGB10_A2UI",
            unsizedformat: "RGBA_INTEGER",
            type: "UNSIGNED_INT_2_10_10_10_REV",
        },
        {
            sizedformat: "RGB8",
            unsizedformat: "RGB",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RGB565",
            unsizedformat: "RGB",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "SRGB8",
            unsizedformat: "RGB",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RGB8_SNORM",
            unsizedformat: "RGB",
            type: "BYTE",
        },
        {
            sizedformat: "RGB565",
            unsizedformat: "RGB",
            type: "UNSIGNED_SHORT_5_6_5",
        },
        {
            sizedformat: "R11F_G11F_B10F",
            unsizedformat: "RGB",
            type: "UNSIGNED_INT_10F_11F_11F_REV",
        },
        {
            sizedformat: "RGB9_E5",
            unsizedformat: "RGB",
            type: "UNSIGNED_INT_5_9_9_9_REV",
        },
        {
            sizedformat: "RGB16F",
            unsizedformat: "RGB",
            type: "HALF_FLOAT",
        },
        {
            sizedformat: "R11F_G11F_B10F",
            unsizedformat: "RGB",
            type: "HALF_FLOAT",
        },
        {
            sizedformat: "RGB9_E5",
            unsizedformat: "RGB",
            type: "HALF_FLOAT",
        },
        {
            sizedformat: "RGB32F",
            unsizedformat: "RGB",
            type: "FLOAT",
        },
        {
            sizedformat: "RGB16F",
            unsizedformat: "RGB",
            type: "FLOAT",
        },
        {
            sizedformat: "R11F_G11F_B10F",
            unsizedformat: "RGB",
            type: "FLOAT",
        },
        {
            sizedformat: "RGB9_E5",
            unsizedformat: "RGB",
            type: "FLOAT",
        },
        {
            sizedformat: "RGB8UI",
            unsizedformat: "RGB_INTEGER",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RGB8I",
            unsizedformat: "RGB_INTEGER",
            type: "BYTE",
        },
        {
            sizedformat: "RGB16UI",
            unsizedformat: "RGB_INTEGER",
            type: "UNSIGNED_SHORT",
        },
        {
            sizedformat: "RGB16I",
            unsizedformat: "RGB_INTEGER",
            type: "SHORT",
        },
        {
            sizedformat: "RGB32UI",
            unsizedformat: "RGB_INTEGER",
            type: "UNSIGNED_INT",
        },
        {
            sizedformat: "RGB32I",
            unsizedformat: "RGB_INTEGER",
            type: "INT",
        },
        {
            sizedformat: "RG8",
            unsizedformat: "RG",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RG8_SNORM",
            unsizedformat: "RG",
            type: "BYTE",
        },
        {
            sizedformat: "RG16F",
            unsizedformat: "RG",
            type: "HALF_FLOAT",
        },
        {
            sizedformat: "RG32F",
            unsizedformat: "RG",
            type: "FLOAT",
        },
        {
            sizedformat: "RG16F",
            unsizedformat: "RG",
            type: "FLOAT",
        },
        {
            sizedformat: "RG8UI",
            unsizedformat: "RG_INTEGER",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "RG8I",
            unsizedformat: "RG_INTEGER",
            type: "BYTE",
        },
        {
            sizedformat: "RG16UI",
            unsizedformat: "RG_INTEGER",
            type: "UNSIGNED_SHORT",
        },
        {
            sizedformat: "RG16I",
            unsizedformat: "RG_INTEGER",
            type: "SHORT",
        },
        {
            sizedformat: "RG32UI",
            unsizedformat: "RG_INTEGER",
            type: "UNSIGNED_INT",
        },
        {
            sizedformat: "RG32I",
            unsizedformat: "RG_INTEGER",
            type: "INT",
        },
        {
            sizedformat: "R8",
            unsizedformat: "RED",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "R8_SNORM",
            unsizedformat: "RED",
            type: "BYTE",
        },
        {
            sizedformat: "R16F",
            unsizedformat: "RED",
            type: "HALF_FLOAT",
        },
        {
            sizedformat: "R32F",
            unsizedformat: "RED",
            type: "FLOAT",
        },
        {
            sizedformat: "R16F",
            unsizedformat: "RED",
            type: "FLOAT",
        },
        {
            sizedformat: "R8UI",
            unsizedformat: "RED_INTEGER",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: "R8I",
            unsizedformat: "RED_INTEGER",
            type: "BYTE",
        },
        {
            sizedformat: "R16UI",
            unsizedformat: "RED_INTEGER",
            type: "UNSIGNED_SHORT",
        },
        {
            sizedformat: "R16I",
            unsizedformat: "RED_INTEGER",
            type: "SHORT",
        },
        {
            sizedformat: "R32UI",
            unsizedformat: "RED_INTEGER",
            type: "UNSIGNED_INT",
        },
        {
            sizedformat: "R32I",
            unsizedformat: "RED_INTEGER",
            type: "INT",
        },
        {
            sizedformat: "DEPTH_COMPONENT16",
            unsizedformat: "DEPTH_COMPONENT",
            type: "UNSIGNED_SHORT",
        },
        {
            sizedformat: "DEPTH_COMPONENT24",
            unsizedformat: "DEPTH_COMPONENT",
            type: "UNSIGNED_INT",
        },
        {
            sizedformat: "DEPTH_COMPONENT16",
            unsizedformat: "DEPTH_COMPONENT",
            type: "UNSIGNED_INT",
        },
        {
            sizedformat: "DEPTH_COMPONENT32F",
            unsizedformat: "DEPTH_COMPONENT",
            type: "FLOAT",
        },
        {
            sizedformat: "DEPTH24_STENCIL8",
            unsizedformat: "DEPTH_STENCIL",
            type: "UNSIGNED_INT_24_8",
        },
        // No good typed array type for this format, just allow this format when  pixel is null.
        {
            sizedformat: "DEPTH32F_STENCIL8",
            unsizedformat: "DEPTH_STENCIL",
            type: "FLOAT_32_UNSIGNED_INT_24_8_REV",
        },
        // internalFormat of texImage2D may be unsized format according Table 3.3 in OpenGL ES 3.0.4 spec.
        {
            sizedformat: undefined,
            unsizedformat: "RGBA",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: undefined,
            unsizedformat: "RGBA",
            type: "UNSIGNED_SHORT_4_4_4_4",
        },
        {
            sizedformat: undefined,
            unsizedformat: "RGBA",
            type: "UNSIGNED_SHORT_5_5_5_1",
        },
        {
            sizedformat: undefined,
            unsizedformat: "RGB",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: undefined,
            unsizedformat: "RGB",
            type: "UNSIGNED_SHORT_5_6_5",
        },
        {
            sizedformat: undefined,
            unsizedformat: "LUMINANCE_ALPHA",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: undefined,
            unsizedformat: "LUMINANCE",
            type: "UNSIGNED_BYTE",
        },
        {
            sizedformat: undefined,
            unsizedformat: "ALPHA",
            type: "UNSIGNED_BYTE",
        },
    ];

    texFormats.forEach(function(texformat){
        debug("");
        debug("Testing sized format " + texformat.sizedformat
              + ", unsized format " + texformat.unsizedformat
              + ", type " + texformat.type);
        var tex = gl.createTexture();
        gl.bindTexture(gl.TEXTURE_2D, tex);

        var sizedformat = gl[texformat.sizedformat];
        var unsizedformat = gl[texformat.unsizedformat];
        var type = gl[texformat.type];

        // prepare some good data to feed texImage2D and friends for this type
        var data;
        switch(type) {
            case gl.UNSIGNED_BYTE:
                data = new Uint8Array(4);
                break;
            case gl.BYTE:
                data = new Int8Array(4);
                break;
            case gl.UNSIGNED_SHORT:
            case gl.UNSIGNED_SHORT_4_4_4_4:
            case gl.UNSIGNED_SHORT_5_5_5_1:
            case gl.UNSIGNED_SHORT_5_6_5:
            case gl.HALF_FLOAT:
                data = new Uint16Array(4);
                break;
            case gl.SHORT:
                data = new Int16Array(4);
                break;
            case gl.UNSIGNED_INT:
            case gl.UNSIGNED_INT_5_9_9_9_REV:
            case gl.UNSIGNED_INT_10F_11F_11F_REV:
            case gl.UNSIGNED_INT_2_10_10_10_REV:
            case gl.UNSIGNED_INT_24_8:
                data = new Uint32Array(4);
                break;
            case gl.INT:
                data = new Int32Array(4);
                break;
            case gl.FLOAT:
                data = new Float32Array(4);
                break;
            case gl.FLOAT_32_UNSIGNED_INT_24_8_REV:
                data = null;
        }

        // prepare some bad data that doesn't fit this type
        var baddata = (data instanceof Float32Array)
                      ? new Uint8Array(4)
                      : new Float32Array(4);

        // test texImage2D with unsized internalformat
        if (!sizedformat) {
            gl.texImage2D(gl.TEXTURE_2D, 0, unsizedformat, 1, 1, 0, unsizedformat, type, data);
            wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage2D should succeed with unsized internalformat");
            gl.texImage2D(gl.TEXTURE_2D, 0, unsizedformat, 1, 1, 0, unsizedformat, type, baddata);
            wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage2D should fail with unsized internalformat and data of wrong type");
        } else {
            // test texImage2D with sized internalformat
            gl.texImage2D(gl.TEXTURE_2D, 0, sizedformat, 1, 1, 0, unsizedformat, type, data);
            wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage2D should succeed with sized internalformat");
            gl.texImage2D(gl.TEXTURE_2D, 0, sizedformat, 1, 1, 0, unsizedformat, type, baddata);
            wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage2D should fail with sized internalformat and data of wrong type");
        }

        // test texSubImage2D
        if (gl.FLOAT_32_UNSIGNED_INT_24_8_REV != type) {
            gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, data);
            wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed");
            gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, baddata);
            wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage2D should fail with data of wrong type");
        }

        // test texStorage2D
        if (sizedformat) {
            gl.texStorage2D(gl.TEXTURE_2D, 1, sizedformat, 1, 1);
            wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texStorage2D should succeed");
            if (gl.FLOAT_32_UNSIGNED_INT_24_8_REV != type) {
                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, data);
                wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed on immutable-format texture");
                gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, baddata);
                wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage2D should fail on immutable-format texture with data of wrong type");
            }
        }

        // Test a 3D texture.
        // Formats containing a depth component can't be used for 3D textures.
        var isdepthformat =
            unsizedformat == gl.DEPTH_COMPONENT ||
            unsizedformat == gl.DEPTH_STENCIL;
        if (!isdepthformat) {
            var tex3d = gl.createTexture();
            gl.bindTexture(gl.TEXTURE_3D, tex3d);

            // test texImage3D with unsized internalformat
            if (!sizedformat) {
                gl.texImage3D(gl.TEXTURE_3D, 0, unsizedformat, 1, 1, 1, 0, unsizedformat, type, data);
                wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage3D should succeed with unsized internalformat");
                gl.texImage3D(gl.TEXTURE_3D, 0, unsizedformat, 1, 1, 1, 0, unsizedformat, type, baddata);
                wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage3D should fail with unsized internalformat and data of wrong type");
            } else {
                // test texImage3D with sized internalformat
                gl.texImage3D(gl.TEXTURE_3D, 0, sizedformat, 1, 1, 1, 0, unsizedformat, type, data);
                wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage3D should succeed with sized internalformat");
                gl.texImage3D(gl.TEXTURE_3D, 0, sizedformat, 1, 1, 1, 0, unsizedformat, type, baddata);
                wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage3D should fail with sized internalformat and data of wrong type");
            }

            // test texSubImage3D
            gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, data);
            wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage3D should succeed");
            gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, baddata);
            wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage3D should fail with data of wrong type");

            if (sizedformat) {
                gl.texStorage3D(gl.TEXTURE_3D, 1, sizedformat, 1, 1, 1);
                wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texStorage3D should succeed");
                gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, data);
                wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage3D should succeed on immutable-format texture");
                gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, baddata);
                wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage3D should fail on immutable-format texture with data of wrong type");
            }
        }
    });
}

function runDepthStencilFormatTest() {
    debug("");
    debug("Testing FLOAT_32_UNSIGNED_INT_24_8_REV with data");
    const fb = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);

    const tex2D = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D, tex2D);
    gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH32F_STENCIL8, 1, 1, 0, gl.DEPTH_STENCIL, gl.FLOAT_32_UNSIGNED_INT_24_8_REV, new Uint8Array(8));
    wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_2D, tex2D, 0);
    if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
        testFailed("2D texture with invalid type was created");
    } else {
        testPassed("2D texture with invalid type was not created")
    }

    const tex3D = gl.createTexture();
    gl.bindTexture(gl.TEXTURE_2D_ARRAY, tex3D);
    gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, gl.DEPTH32F_STENCIL8, 1, 1, 1, 0, gl.DEPTH_STENCIL, gl.FLOAT_32_UNSIGNED_INT_24_8_REV, new Uint8Array(8));
    wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
    gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, tex3D, 0, 0);
    if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
        testFailed("2D array texture with invalid type was created");
    } else {
        testPassed("2D array texture with invalid type was not created")
    }
}

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

</body>
</html>