Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / textures / misc / tex-new-formats.html
blob760bc6bd1947a4e141935dfe0d885a97ba3ba88a
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>Conformance test for WebGL2 texture image formats specification</title>
12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
13 <script src="../../../js/js-test-pre.js"></script>
14 <script src="../../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <canvas id="canvas" width="64" height="64"> </canvas>
19 <div id="console"></div>
22 <script>
23 "use strict";
24 description("This test verifies that texture image specification entry points " +
25 "accept new formats introduced in WebGL2, and accept sized internalformats.");
27 debug("");
29 var wtu = WebGLTestUtils;
30 var canvas = document.getElementById("canvas");
31 var gl = wtu.create3DContext(canvas, null, 2);
32 var vao = null;
34 if (!gl) {
35 testFailed("WebGL context does not exist");
36 } else {
37 testPassed("WebGL context exists");
39 runTexFormatsTest();
40 runDepthStencilFormatTest();
42 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
45 function enumToString(value) {
46 return wtu.glEnumToString(gl, value);
49 function runTexFormatsTest()
51 // texFormats is Table 3.2 and Table 3.3 from the OpenGL ES 3.0.4 spec.
52 var texFormats = [
54 sizedformat: "RGBA8",
55 unsizedformat: "RGBA",
56 type: "UNSIGNED_BYTE",
59 sizedformat: "RGB5_A1",
60 unsizedformat: "RGBA",
61 type: "UNSIGNED_BYTE",
64 sizedformat: "RGBA4",
65 unsizedformat: "RGBA",
66 type: "UNSIGNED_BYTE",
69 sizedformat: "SRGB8_ALPHA8",
70 unsizedformat: "RGBA",
71 type: "UNSIGNED_BYTE",
74 sizedformat: "RGBA8_SNORM",
75 unsizedformat: "RGBA",
76 type: "BYTE",
79 sizedformat: "RGBA4",
80 unsizedformat: "RGBA",
81 type: "UNSIGNED_SHORT_4_4_4_4",
84 sizedformat: "RGB5_A1",
85 unsizedformat: "RGBA",
86 type: "UNSIGNED_SHORT_5_5_5_1",
89 sizedformat: "RGB10_A2",
90 unsizedformat: "RGBA",
91 type: "UNSIGNED_INT_2_10_10_10_REV",
94 sizedformat: "RGB5_A1",
95 unsizedformat: "RGBA",
96 type: "UNSIGNED_INT_2_10_10_10_REV",
99 sizedformat: "RGBA16F",
100 unsizedformat: "RGBA",
101 type: "HALF_FLOAT",
104 sizedformat: "RGBA32F",
105 unsizedformat: "RGBA",
106 type: "FLOAT",
109 sizedformat: "RGBA16F",
110 unsizedformat: "RGBA",
111 type: "FLOAT",
114 sizedformat: "RGBA8UI",
115 unsizedformat: "RGBA_INTEGER",
116 type: "UNSIGNED_BYTE",
119 sizedformat: "RGBA8I",
120 unsizedformat: "RGBA_INTEGER",
121 type: "BYTE",
124 sizedformat: "RGBA16UI",
125 unsizedformat: "RGBA_INTEGER",
126 type: "UNSIGNED_SHORT",
129 sizedformat: "RGBA16I",
130 unsizedformat: "RGBA_INTEGER",
131 type: "SHORT",
134 sizedformat: "RGBA32UI",
135 unsizedformat: "RGBA_INTEGER",
136 type: "UNSIGNED_INT",
139 sizedformat: "RGBA32I",
140 unsizedformat: "RGBA_INTEGER",
141 type: "INT",
144 sizedformat: "RGB10_A2UI",
145 unsizedformat: "RGBA_INTEGER",
146 type: "UNSIGNED_INT_2_10_10_10_REV",
149 sizedformat: "RGB8",
150 unsizedformat: "RGB",
151 type: "UNSIGNED_BYTE",
154 sizedformat: "RGB565",
155 unsizedformat: "RGB",
156 type: "UNSIGNED_BYTE",
159 sizedformat: "SRGB8",
160 unsizedformat: "RGB",
161 type: "UNSIGNED_BYTE",
164 sizedformat: "RGB8_SNORM",
165 unsizedformat: "RGB",
166 type: "BYTE",
169 sizedformat: "RGB565",
170 unsizedformat: "RGB",
171 type: "UNSIGNED_SHORT_5_6_5",
174 sizedformat: "R11F_G11F_B10F",
175 unsizedformat: "RGB",
176 type: "UNSIGNED_INT_10F_11F_11F_REV",
179 sizedformat: "RGB9_E5",
180 unsizedformat: "RGB",
181 type: "UNSIGNED_INT_5_9_9_9_REV",
184 sizedformat: "RGB16F",
185 unsizedformat: "RGB",
186 type: "HALF_FLOAT",
189 sizedformat: "R11F_G11F_B10F",
190 unsizedformat: "RGB",
191 type: "HALF_FLOAT",
194 sizedformat: "RGB9_E5",
195 unsizedformat: "RGB",
196 type: "HALF_FLOAT",
199 sizedformat: "RGB32F",
200 unsizedformat: "RGB",
201 type: "FLOAT",
204 sizedformat: "RGB16F",
205 unsizedformat: "RGB",
206 type: "FLOAT",
209 sizedformat: "R11F_G11F_B10F",
210 unsizedformat: "RGB",
211 type: "FLOAT",
214 sizedformat: "RGB9_E5",
215 unsizedformat: "RGB",
216 type: "FLOAT",
219 sizedformat: "RGB8UI",
220 unsizedformat: "RGB_INTEGER",
221 type: "UNSIGNED_BYTE",
224 sizedformat: "RGB8I",
225 unsizedformat: "RGB_INTEGER",
226 type: "BYTE",
229 sizedformat: "RGB16UI",
230 unsizedformat: "RGB_INTEGER",
231 type: "UNSIGNED_SHORT",
234 sizedformat: "RGB16I",
235 unsizedformat: "RGB_INTEGER",
236 type: "SHORT",
239 sizedformat: "RGB32UI",
240 unsizedformat: "RGB_INTEGER",
241 type: "UNSIGNED_INT",
244 sizedformat: "RGB32I",
245 unsizedformat: "RGB_INTEGER",
246 type: "INT",
249 sizedformat: "RG8",
250 unsizedformat: "RG",
251 type: "UNSIGNED_BYTE",
254 sizedformat: "RG8_SNORM",
255 unsizedformat: "RG",
256 type: "BYTE",
259 sizedformat: "RG16F",
260 unsizedformat: "RG",
261 type: "HALF_FLOAT",
264 sizedformat: "RG32F",
265 unsizedformat: "RG",
266 type: "FLOAT",
269 sizedformat: "RG16F",
270 unsizedformat: "RG",
271 type: "FLOAT",
274 sizedformat: "RG8UI",
275 unsizedformat: "RG_INTEGER",
276 type: "UNSIGNED_BYTE",
279 sizedformat: "RG8I",
280 unsizedformat: "RG_INTEGER",
281 type: "BYTE",
284 sizedformat: "RG16UI",
285 unsizedformat: "RG_INTEGER",
286 type: "UNSIGNED_SHORT",
289 sizedformat: "RG16I",
290 unsizedformat: "RG_INTEGER",
291 type: "SHORT",
294 sizedformat: "RG32UI",
295 unsizedformat: "RG_INTEGER",
296 type: "UNSIGNED_INT",
299 sizedformat: "RG32I",
300 unsizedformat: "RG_INTEGER",
301 type: "INT",
304 sizedformat: "R8",
305 unsizedformat: "RED",
306 type: "UNSIGNED_BYTE",
309 sizedformat: "R8_SNORM",
310 unsizedformat: "RED",
311 type: "BYTE",
314 sizedformat: "R16F",
315 unsizedformat: "RED",
316 type: "HALF_FLOAT",
319 sizedformat: "R32F",
320 unsizedformat: "RED",
321 type: "FLOAT",
324 sizedformat: "R16F",
325 unsizedformat: "RED",
326 type: "FLOAT",
329 sizedformat: "R8UI",
330 unsizedformat: "RED_INTEGER",
331 type: "UNSIGNED_BYTE",
334 sizedformat: "R8I",
335 unsizedformat: "RED_INTEGER",
336 type: "BYTE",
339 sizedformat: "R16UI",
340 unsizedformat: "RED_INTEGER",
341 type: "UNSIGNED_SHORT",
344 sizedformat: "R16I",
345 unsizedformat: "RED_INTEGER",
346 type: "SHORT",
349 sizedformat: "R32UI",
350 unsizedformat: "RED_INTEGER",
351 type: "UNSIGNED_INT",
354 sizedformat: "R32I",
355 unsizedformat: "RED_INTEGER",
356 type: "INT",
359 sizedformat: "DEPTH_COMPONENT16",
360 unsizedformat: "DEPTH_COMPONENT",
361 type: "UNSIGNED_SHORT",
364 sizedformat: "DEPTH_COMPONENT24",
365 unsizedformat: "DEPTH_COMPONENT",
366 type: "UNSIGNED_INT",
369 sizedformat: "DEPTH_COMPONENT16",
370 unsizedformat: "DEPTH_COMPONENT",
371 type: "UNSIGNED_INT",
374 sizedformat: "DEPTH_COMPONENT32F",
375 unsizedformat: "DEPTH_COMPONENT",
376 type: "FLOAT",
379 sizedformat: "DEPTH24_STENCIL8",
380 unsizedformat: "DEPTH_STENCIL",
381 type: "UNSIGNED_INT_24_8",
383 // No good typed array type for this format, just allow this format when pixel is null.
385 sizedformat: "DEPTH32F_STENCIL8",
386 unsizedformat: "DEPTH_STENCIL",
387 type: "FLOAT_32_UNSIGNED_INT_24_8_REV",
389 // internalFormat of texImage2D may be unsized format according Table 3.3 in OpenGL ES 3.0.4 spec.
391 sizedformat: undefined,
392 unsizedformat: "RGBA",
393 type: "UNSIGNED_BYTE",
396 sizedformat: undefined,
397 unsizedformat: "RGBA",
398 type: "UNSIGNED_SHORT_4_4_4_4",
401 sizedformat: undefined,
402 unsizedformat: "RGBA",
403 type: "UNSIGNED_SHORT_5_5_5_1",
406 sizedformat: undefined,
407 unsizedformat: "RGB",
408 type: "UNSIGNED_BYTE",
411 sizedformat: undefined,
412 unsizedformat: "RGB",
413 type: "UNSIGNED_SHORT_5_6_5",
416 sizedformat: undefined,
417 unsizedformat: "LUMINANCE_ALPHA",
418 type: "UNSIGNED_BYTE",
421 sizedformat: undefined,
422 unsizedformat: "LUMINANCE",
423 type: "UNSIGNED_BYTE",
426 sizedformat: undefined,
427 unsizedformat: "ALPHA",
428 type: "UNSIGNED_BYTE",
432 texFormats.forEach(function(texformat){
433 debug("");
434 debug("Testing sized format " + texformat.sizedformat
435 + ", unsized format " + texformat.unsizedformat
436 + ", type " + texformat.type);
437 var tex = gl.createTexture();
438 gl.bindTexture(gl.TEXTURE_2D, tex);
440 var sizedformat = gl[texformat.sizedformat];
441 var unsizedformat = gl[texformat.unsizedformat];
442 var type = gl[texformat.type];
444 // prepare some good data to feed texImage2D and friends for this type
445 var data;
446 switch(type) {
447 case gl.UNSIGNED_BYTE:
448 data = new Uint8Array(4);
449 break;
450 case gl.BYTE:
451 data = new Int8Array(4);
452 break;
453 case gl.UNSIGNED_SHORT:
454 case gl.UNSIGNED_SHORT_4_4_4_4:
455 case gl.UNSIGNED_SHORT_5_5_5_1:
456 case gl.UNSIGNED_SHORT_5_6_5:
457 case gl.HALF_FLOAT:
458 data = new Uint16Array(4);
459 break;
460 case gl.SHORT:
461 data = new Int16Array(4);
462 break;
463 case gl.UNSIGNED_INT:
464 case gl.UNSIGNED_INT_5_9_9_9_REV:
465 case gl.UNSIGNED_INT_10F_11F_11F_REV:
466 case gl.UNSIGNED_INT_2_10_10_10_REV:
467 case gl.UNSIGNED_INT_24_8:
468 data = new Uint32Array(4);
469 break;
470 case gl.INT:
471 data = new Int32Array(4);
472 break;
473 case gl.FLOAT:
474 data = new Float32Array(4);
475 break;
476 case gl.FLOAT_32_UNSIGNED_INT_24_8_REV:
477 data = null;
480 // prepare some bad data that doesn't fit this type
481 var baddata = (data instanceof Float32Array)
482 ? new Uint8Array(4)
483 : new Float32Array(4);
485 // test texImage2D with unsized internalformat
486 if (!sizedformat) {
487 gl.texImage2D(gl.TEXTURE_2D, 0, unsizedformat, 1, 1, 0, unsizedformat, type, data);
488 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage2D should succeed with unsized internalformat");
489 gl.texImage2D(gl.TEXTURE_2D, 0, unsizedformat, 1, 1, 0, unsizedformat, type, baddata);
490 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage2D should fail with unsized internalformat and data of wrong type");
491 } else {
492 // test texImage2D with sized internalformat
493 gl.texImage2D(gl.TEXTURE_2D, 0, sizedformat, 1, 1, 0, unsizedformat, type, data);
494 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage2D should succeed with sized internalformat");
495 gl.texImage2D(gl.TEXTURE_2D, 0, sizedformat, 1, 1, 0, unsizedformat, type, baddata);
496 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage2D should fail with sized internalformat and data of wrong type");
499 // test texSubImage2D
500 if (gl.FLOAT_32_UNSIGNED_INT_24_8_REV != type) {
501 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, data);
502 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed");
503 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, baddata);
504 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage2D should fail with data of wrong type");
507 // test texStorage2D
508 if (sizedformat) {
509 gl.texStorage2D(gl.TEXTURE_2D, 1, sizedformat, 1, 1);
510 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texStorage2D should succeed");
511 if (gl.FLOAT_32_UNSIGNED_INT_24_8_REV != type) {
512 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, data);
513 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage2D should succeed on immutable-format texture");
514 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 1, 1, unsizedformat, type, baddata);
515 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage2D should fail on immutable-format texture with data of wrong type");
519 // Test a 3D texture.
520 // Formats containing a depth component can't be used for 3D textures.
521 var isdepthformat =
522 unsizedformat == gl.DEPTH_COMPONENT ||
523 unsizedformat == gl.DEPTH_STENCIL;
524 if (!isdepthformat) {
525 var tex3d = gl.createTexture();
526 gl.bindTexture(gl.TEXTURE_3D, tex3d);
528 // test texImage3D with unsized internalformat
529 if (!sizedformat) {
530 gl.texImage3D(gl.TEXTURE_3D, 0, unsizedformat, 1, 1, 1, 0, unsizedformat, type, data);
531 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage3D should succeed with unsized internalformat");
532 gl.texImage3D(gl.TEXTURE_3D, 0, unsizedformat, 1, 1, 1, 0, unsizedformat, type, baddata);
533 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage3D should fail with unsized internalformat and data of wrong type");
534 } else {
535 // test texImage3D with sized internalformat
536 gl.texImage3D(gl.TEXTURE_3D, 0, sizedformat, 1, 1, 1, 0, unsizedformat, type, data);
537 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texImage3D should succeed with sized internalformat");
538 gl.texImage3D(gl.TEXTURE_3D, 0, sizedformat, 1, 1, 1, 0, unsizedformat, type, baddata);
539 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texImage3D should fail with sized internalformat and data of wrong type");
542 // test texSubImage3D
543 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, data);
544 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage3D should succeed");
545 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, baddata);
546 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage3D should fail with data of wrong type");
548 if (sizedformat) {
549 gl.texStorage3D(gl.TEXTURE_3D, 1, sizedformat, 1, 1, 1);
550 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texStorage3D should succeed");
551 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, data);
552 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "texSubImage3D should succeed on immutable-format texture");
553 gl.texSubImage3D(gl.TEXTURE_3D, 0, 0, 0, 0, 1, 1, 1, unsizedformat, type, baddata);
554 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "texSubImage3D should fail on immutable-format texture with data of wrong type");
560 function runDepthStencilFormatTest() {
561 debug("");
562 debug("Testing FLOAT_32_UNSIGNED_INT_24_8_REV with data");
563 const fb = gl.createFramebuffer();
564 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
566 const tex2D = gl.createTexture();
567 gl.bindTexture(gl.TEXTURE_2D, tex2D);
568 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));
569 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
570 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.TEXTURE_2D, tex2D, 0);
571 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
572 testFailed("2D texture with invalid type was created");
573 } else {
574 testPassed("2D texture with invalid type was not created")
577 const tex3D = gl.createTexture();
578 gl.bindTexture(gl.TEXTURE_2D_ARRAY, tex3D);
579 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));
580 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION);
581 gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, tex3D, 0, 0);
582 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
583 testFailed("2D array texture with invalid type was created");
584 } else {
585 testPassed("2D array texture with invalid type was not created")
589 debug("");
590 var successfullyParsed = true;
591 </script>
592 <script src="../../../js/js-test-post.js"></script>
594 </body>
595 </html>