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 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
11 <script src=
"../../../js/js-test-pre.js"></script>
12 <script src=
"../../../js/webgl-test-utils.js"></script>
15 <canvas id=
"c" width=
"16" height=
"16"></canvas>
16 <div id=
"description"></div>
17 <div id=
"console"></div>
20 description('Tests texImage2D with invalid internalformat/format/type combinations from various dom elements');
22 debug("<a href='https://www.khronos.org/registry/webgl/specs/latest/2.0/#TEXTURE_TYPES_FORMATS_FROM_DOM_ELEMENTS_TABLE'>Valid internalformat/format/type combinations</a>");
25 var wtu
= WebGLTestUtils
;
26 var gl
= wtu
.create3DContext("c", undefined, 2);
28 var doTexImage = function(domElement
) {
29 var tex
= gl
.createTexture();
30 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
31 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGB10_A2UI
, gl
.RGBA_INTEGER
, gl
.UNSIGNED_INT_2_10_10_10_REV
, domElement
);
32 wtu
.glErrorShouldBe(gl
, [gl
.INVALID_VALUE
, gl
.INVALID_ENUM
, gl
.INVALID_OPERATION
], "TexImage2D taking RGB10_A2UI/RGBA_INTEGER/UNSIGNED_INT_2_10_10_10_REV should fail");
33 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RG8
, gl
.RG
, gl
.FLOAT
, domElement
);
34 wtu
.glErrorShouldBe(gl
, gl
.INVALID_OPERATION
, "TexImage2D taking RG8/RG/FLOAT should fail");
35 gl
.deleteTexture(tex
);
38 var createCanvas2DContext = function(width
, height
) {
39 var canvas
= document
.createElement("canvas");
41 canvas
.height
= height
;
42 var ctx
= canvas
.getContext("2d");
43 ctx
.fillRect(0, 0, width
, height
);
47 var testImage = function(test
) {
48 debug("HTMLImageElement");
49 var img
= wtu
.makeImage(test
.src
, function() {
51 setTimeout(runNextTest
, 0);
55 var testVideo = function(test
) {
56 debug("HTMLVideoElement (" + test
.videoType
+ ")");
57 var video
= wtu
.makeVideo(test
.src
);
58 if(!video
.canPlayType(test
.videoType
).replace(/no/, '')) {
59 debug(test
.videoType
+ " unsupported");
60 setTimeout(runNextTest
, 0);
63 wtu
.startPlayingAndWaitForVideo(video
, function() {
65 setTimeout(runNextTest
, 0);
69 var testCanvas = function(test
) {
70 var ctx
= createCanvas2DContext(test
.width
, test
.height
);
71 debug("HTMLCanvasElement");
72 doTexImage(ctx
.canvas
);
73 setTimeout(runNextTest
, 0);
76 var testImageData = function(test
) {
77 var ctx
= createCanvas2DContext(test
.width
, test
.height
);
78 var imageData
= ctx
.getImageData(0, 0, test
.width
, test
.height
);
80 doTexImage(imageData
);
81 setTimeout(runNextTest
, 0);
84 var testImageBitmap = function(test
) {
86 if(!window
.createImageBitmap
|| !window
.ImageBitmap
) {
87 debug("ImageBitmap isn't supported");
88 setTimeout(runNextTest
, 0);
91 var ctx
= createCanvas2DContext(test
.width
, test
.height
);
92 createImageBitmap(ctx
.canvas
, 0, 0, test
.width
, test
.height
).then(function(imageBitmap
) {
93 doTexImage(imageBitmap
);
94 setTimeout(runNextTest
, 0);
96 debug("createImageBitmap was rejected");
97 setTimeout(runNextTest
, 0);
102 { type
: "canvas", width
: 64, height
: 64, run
: testCanvas
},
103 { type
: "image", src
: "../../../resources/red-green.png", run
: testImage
},
104 { type
: "ImageBitmap",width
: 64, height
: 64, run
: testImageBitmap
},
105 { type
: "ImageData", width
: 64, height
: 64, run
: testImageData
},
106 { type
: "video", src
: "../../../resources/red-green.mp4", videoType
: 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', run
: testVideo
},
107 { type
: "video", src
: "../../../resources/red-green.bt601.vp9.webm", videoType
: 'video/webm; codecs="vp9"', run
: testVideo
},
108 { type
: "video", src
: "../../../resources/red-green.webmvp8.webm", videoType
: 'video/webm; codecs="vp8, vorbis"', run
: testVideo
},
112 var runNextTest = function() {
113 if (testIndex
< tests
.length
) {
115 var test
= tests
[testIndex
];