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 <title>texImage2D and texSubImage2D tests with invalid data
</title>
11 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
12 <script src=
"../../../js/js-test-pre.js"></script>
13 <script src=
"../../../js/webgl-test-utils.js"></script>
16 <div id=
"description"></div>
17 <div id=
"console"></div>
18 <canvas id=
"canvas" width=
"2" height=
"2"> </canvas>
19 <script type=
"application/javascript">
20 description(
"texImage2D and texSubImage2D tests with invalid data");
22 var wtu = WebGLTestUtils;
23 var canvas = document.getElementById(
"canvas");
24 var contextVersion = wtu.getDefault3DContextVersion();
25 var gl = wtu.create3DContext(canvas);
27 testFailed(
"Context created.");
29 testPassed(
"Context created.");
34 tex = gl.createTexture();
35 gl.bindTexture(gl.TEXTURE_2D, tex);
36 gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA,
64,
64,
0, gl.RGBA, gl.UNSIGNED_BYTE, null);
40 gl.deleteTexture(tex);
43 function test(desc, func, expected) {
53 if (expected == gl.INVALID_OPERATION) {
54 wtu.glErrorShouldBe(gl, expected);
55 } else if (expected ==
"exception") {
57 testPassed(
"threw exception");
59 testFailed(
"did not throw exception");
64 test(
"Calling texImage2D with no WebGLTexture bound generates INVALID_OPERATION",
66 gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA,
64,
64,
0, gl.RGBA, gl.UNSIGNED_BYTE, null);
68 gl.INVALID_OPERATION);
70 test(
"Calling texSubImage2D with no WebGLTexture bound generates INVALID_OPERATION",
72 var buffer = new Uint8Array(
4);
73 gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0,
1,
1, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
75 gl.INVALID_OPERATION);
79 test(
"Passing a buffer not large enough to texImage2D should generate an INVALID_OPERATION",
81 var tooSmall = new Uint8Array(
64);
82 gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA,
64,
64,
0, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
84 gl.INVALID_OPERATION);
86 if (contextVersion <
2) {
87 test(
"Passing texImage2D parameter data of Number type should throw an exception",
89 gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA,
64,
64,
0, gl.RGBA, gl.UNSIGNED_BYTE,
42);
93 test(
"Passing texImage2D parameter data of Number type should generate an INVALID_OPERATION",
95 gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA,
64,
64,
0, gl.RGBA, gl.UNSIGNED_BYTE,
42);
97 gl.INVALID_OPERATION);
100 if (contextVersion <
2) {
101 test(
"Passing texImage2D parameter data of String type should throw a TypeError",
103 gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA,
64,
64,
0, gl.RGBA, gl.UNSIGNED_BYTE,
"not a buffer");
107 test(
"Passing texImage2D parameter data of String type should generate an INVALID_OPERATION",
109 gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA,
64,
64,
0, gl.RGBA, gl.UNSIGNED_BYTE,
"not a buffer");
111 gl.INVALID_OPERATION);
114 test(
"Passing a buffer not large enough to texSubImage2D should generate an INVALID_OPERATION",
116 var tooSmall = new Uint8Array(
64);
117 gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0,
64,
64, gl.RGBA, gl.UNSIGNED_BYTE, tooSmall);
119 gl.INVALID_OPERATION);
121 if (contextVersion <
2) {
122 test(
"Passing texSubImage2D parameter data of Number type should throw a TypeError",
124 gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0,
64,
64, gl.RGBA, gl.UNSIGNED_BYTE,
42);
128 test(
"Passing texSubImage2D parameter data of Number type should generate an INVALID_OPERATION",
130 gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0,
64,
64, gl.RGBA, gl.UNSIGNED_BYTE,
42);
132 gl.INVALID_OPERATION);
135 if (contextVersion <
2) {
136 test(
"Passing texSubImage2D parameter data of String type should throw a TypeError",
138 gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0,
64,
64, gl.RGBA, gl.UNSIGNED_BYTE,
"not a buffer");
142 test(
"Passing texSubImage2D parameter data of String type should generate an INVALID_OPERATION",
144 gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0,
64,
64, gl.RGBA, gl.UNSIGNED_BYTE,
"not a buffer");
146 gl.INVALID_OPERATION);
152 var successfullyParsed = true;
154 <script src=
"../../../js/js-test-post.js"></script>