6 Copyright (c) 2019 The Khronos Group Inc.
7 Use of this source code is governed by an MIT-style license that can be
8 found in the LICENSE.txt file.
10 <link rel=
"stylesheet" type=
"text/css" href=
"../unit.css" />
11 <script type=
"application/javascript" src=
"../unit.js"></script>
12 <script type=
"application/javascript" src=
"../util.js"></script>
13 <script type=
"application/javascript">
15 Tests.startUnit = function () {
16 var canvas = document.getElementById('gl');
17 var gl = wrapGLContext(getGLContext(canvas));
18 var tex = gl.createTexture();
19 gl.bindTexture(gl.TEXTURE_2D, tex);
23 Tests.testTexImage2D = function(gl) {
24 var b = document.createElement('b');
25 var div = document.createElement('div');
26 var c = document.getElementById('c');
27 assertOk(
"make texture",
28 function() {gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c); });
29 assertGLError(gl, gl.INVALID_VALUE,
"y + height > texture height",
30 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
1, gl.RGBA, gl.UNSIGNED_BYTE, c); });
31 assertGLError(gl, gl.INVALID_VALUE,
"x + width > texture width",
32 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
1,
0, gl.RGBA, gl.UNSIGNED_BYTE, c); });
33 assertGLError(gl, gl.INVALID_VALUE,
"negative x",
34 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0, -
1,
0, gl.RGBA, gl.UNSIGNED_BYTE, c); });
35 assertGLError(gl, gl.INVALID_VALUE,
"negative y",
36 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0, -
1, gl.RGBA, gl.UNSIGNED_BYTE, c); });
37 assertGLError(gl, gl.INVALID_VALUE,
"negative level",
38 function() {gl.texSubImage2D(gl.TEXTURE_2D, -
1,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE, c); });
39 assertThrowNoGLError(gl,
"bad element b",
40 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE, b); });
41 assertThrowNoGLError(gl,
"bad element div",
42 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE, div); });
43 assertThrowNoGLError(gl,
"no element",
44 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE,
0); });
45 assertThrowNoGLError(gl,
"string as data",
46 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE,
"foo"); });
47 assertGLError(gl, gl.INVALID_ENUM,
"bad target",
48 function() {gl.texSubImage2D(gl.FLOAT,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE, c); });
50 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE, c); });
51 assertGLError(gl, gl.INVALID_OPERATION,
"format not same as original",
52 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGB, gl.UNSIGNED_BYTE, c); });
53 assertGLError(gl, gl.INVALID_OPERATION,
"type not same as original",
54 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, c); });
55 assertOk(
"make texture RGB",
56 function() {gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, c); });
57 assertOk(
"format same as original RGB",
58 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGB, gl.UNSIGNED_BYTE, c); });
59 assertGLError(gl, gl.INVALID_OPERATION,
"format not same as original RGB",
60 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE, c); });
61 assertGLError(gl, gl.INVALID_OPERATION,
"type not same as original RGB",
62 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGB, gl.UNSIGNED_SHORT_5_6_5, c); });
63 assertOk(
"make texture RGBA 4_4_4_4",
64 function() {gl.texImage2D(gl.TEXTURE_2D,
0, gl.RGBA, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, c); });
65 assertOk(
"format same as original RGBA 4_4_4_4",
66 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_SHORT_4_4_4_4, c); });
67 assertGLError(gl, gl.INVALID_OPERATION,
"format not same as original RGBA 4_4_4_4",
68 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGB, gl.UNSIGNED_BYTE, c); });
69 assertGLError(gl, gl.INVALID_OPERATION,
"type not same as original RGBA 4_4_4_4",
70 function() {gl.texSubImage2D(gl.TEXTURE_2D,
0,
0,
0, gl.RGBA, gl.UNSIGNED_BYTE, c); });
73 Tests.endUnit = function(gl, tex) {
74 gl.bindTexture(gl.TEXTURE_2D, null);
75 gl.deleteTexture(tex);
79 <style>canvas{ position:absolute; }
</style>
81 <canvas id=
"gl" width=
"16" height=
"16"></canvas>
82 <canvas id=
"c" width=
"16" height=
"16"></canvas>