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.
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>
17 <div id=
"description"></div>
18 <canvas id=
"canvas" width=
"64" height=
"64"> </canvas>
19 <div id=
"console"></div>
24 description("This test verifies that texture image specification entry points " +
25 "accept new formats introduced in WebGL2, and accept sized internalformats.");
29 var wtu
= WebGLTestUtils
;
30 var canvas
= document
.getElementById("canvas");
31 var gl
= wtu
.create3DContext(canvas
, null, 2);
35 testFailed("WebGL context does not exist");
37 testPassed("WebGL context exists");
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.
55 unsizedformat
: "RGBA",
56 type
: "UNSIGNED_BYTE",
59 sizedformat
: "RGB5_A1",
60 unsizedformat
: "RGBA",
61 type
: "UNSIGNED_BYTE",
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",
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",
104 sizedformat
: "RGBA32F",
105 unsizedformat
: "RGBA",
109 sizedformat
: "RGBA16F",
110 unsizedformat
: "RGBA",
114 sizedformat
: "RGBA8UI",
115 unsizedformat
: "RGBA_INTEGER",
116 type
: "UNSIGNED_BYTE",
119 sizedformat
: "RGBA8I",
120 unsizedformat
: "RGBA_INTEGER",
124 sizedformat
: "RGBA16UI",
125 unsizedformat
: "RGBA_INTEGER",
126 type
: "UNSIGNED_SHORT",
129 sizedformat
: "RGBA16I",
130 unsizedformat
: "RGBA_INTEGER",
134 sizedformat
: "RGBA32UI",
135 unsizedformat
: "RGBA_INTEGER",
136 type
: "UNSIGNED_INT",
139 sizedformat
: "RGBA32I",
140 unsizedformat
: "RGBA_INTEGER",
144 sizedformat
: "RGB10_A2UI",
145 unsizedformat
: "RGBA_INTEGER",
146 type
: "UNSIGNED_INT_2_10_10_10_REV",
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",
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",
189 sizedformat
: "R11F_G11F_B10F",
190 unsizedformat
: "RGB",
194 sizedformat
: "RGB9_E5",
195 unsizedformat
: "RGB",
199 sizedformat
: "RGB32F",
200 unsizedformat
: "RGB",
204 sizedformat
: "RGB16F",
205 unsizedformat
: "RGB",
209 sizedformat
: "R11F_G11F_B10F",
210 unsizedformat
: "RGB",
214 sizedformat
: "RGB9_E5",
215 unsizedformat
: "RGB",
219 sizedformat
: "RGB8UI",
220 unsizedformat
: "RGB_INTEGER",
221 type
: "UNSIGNED_BYTE",
224 sizedformat
: "RGB8I",
225 unsizedformat
: "RGB_INTEGER",
229 sizedformat
: "RGB16UI",
230 unsizedformat
: "RGB_INTEGER",
231 type
: "UNSIGNED_SHORT",
234 sizedformat
: "RGB16I",
235 unsizedformat
: "RGB_INTEGER",
239 sizedformat
: "RGB32UI",
240 unsizedformat
: "RGB_INTEGER",
241 type
: "UNSIGNED_INT",
244 sizedformat
: "RGB32I",
245 unsizedformat
: "RGB_INTEGER",
251 type
: "UNSIGNED_BYTE",
254 sizedformat
: "RG8_SNORM",
259 sizedformat
: "RG16F",
264 sizedformat
: "RG32F",
269 sizedformat
: "RG16F",
274 sizedformat
: "RG8UI",
275 unsizedformat
: "RG_INTEGER",
276 type
: "UNSIGNED_BYTE",
280 unsizedformat
: "RG_INTEGER",
284 sizedformat
: "RG16UI",
285 unsizedformat
: "RG_INTEGER",
286 type
: "UNSIGNED_SHORT",
289 sizedformat
: "RG16I",
290 unsizedformat
: "RG_INTEGER",
294 sizedformat
: "RG32UI",
295 unsizedformat
: "RG_INTEGER",
296 type
: "UNSIGNED_INT",
299 sizedformat
: "RG32I",
300 unsizedformat
: "RG_INTEGER",
305 unsizedformat
: "RED",
306 type
: "UNSIGNED_BYTE",
309 sizedformat
: "R8_SNORM",
310 unsizedformat
: "RED",
315 unsizedformat
: "RED",
320 unsizedformat
: "RED",
325 unsizedformat
: "RED",
330 unsizedformat
: "RED_INTEGER",
331 type
: "UNSIGNED_BYTE",
335 unsizedformat
: "RED_INTEGER",
339 sizedformat
: "R16UI",
340 unsizedformat
: "RED_INTEGER",
341 type
: "UNSIGNED_SHORT",
345 unsizedformat
: "RED_INTEGER",
349 sizedformat
: "R32UI",
350 unsizedformat
: "RED_INTEGER",
351 type
: "UNSIGNED_INT",
355 unsizedformat
: "RED_INTEGER",
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",
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
){
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
447 case gl
.UNSIGNED_BYTE
:
448 data
= new Uint8Array(4);
451 data
= new Int8Array(4);
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
:
458 data
= new Uint16Array(4);
461 data
= new Int16Array(4);
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);
471 data
= new Int32Array(4);
474 data
= new Float32Array(4);
476 case gl
.FLOAT_32_UNSIGNED_INT_24_8_REV
:
480 // prepare some bad data that doesn't fit this type
481 var baddata
= (data
instanceof Float32Array
)
483 : new Float32Array(4);
485 // test texImage2D with unsized internalformat
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");
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");
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.
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
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");
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");
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() {
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");
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");
585 testPassed("2D array texture with invalid type was not created")
590 var successfullyParsed
= true;
592 <script src=
"../../../js/js-test-post.js"></script>