1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
5 <title>WebGL
"Texture Complete" texture conformance test.
</title>
6 <script src=
"../../../resources/js-test.js"></script>
7 <script src=
"resources/webgl-test.js"> </script>
10 <canvas id=
"example" width=
"40" height=
"40" style=
"width: 40px; height: 40px;"></canvas>
11 <canvas id=
"canvas2d" width=
"16" height=
"16" style=
"width: 40px; height: 40px;"></canvas>
12 <div id=
"description"></div>
13 <div id=
"console"></div>
14 <script id=
"vshader" type=
"x-shader/x-vertex">
16 precision highp float;
18 attribute vec4 vPosition;
19 attribute vec2 texCoord0;
20 varying vec2 texCoord;
23 gl_Position = vPosition;
28 <script id=
"fshader" type=
"x-shader/x-fragment">
30 precision highp float;
32 uniform sampler2D tex;
33 varying vec2 texCoord;
36 gl_FragColor = texture2D(tex, texCoord);
43 if (window
.initNonKhronosFramework
) {
44 window
.initNonKhronosFramework(false);
48 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
50 debug("Checks that a texture that is not -texture-complete- does not draw if"+
51 " filtering needs mips");
54 var canvas2d
= document
.getElementById("canvas2d");
55 var ctx2d
= canvas2d
.getContext("2d");
56 ctx2d
.fillStyle
= "rgba(0,192,128,255)";
57 ctx2d
.fillRect(0, 0, 16, 16);
59 gl
= initWebGL("example", "vshader", "fshader", [ "vPosition", "texCoord0"],
62 gl
.disable(gl
.DEPTH_TEST
);
65 var vertexObject
= gl
.createBuffer();
66 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
67 gl
.bufferData(gl
.ARRAY_BUFFER
,
68 new Float32Array([ -1,1,0, 1,1,0, -1,-1,0,
69 -1,-1,0, 1,1,0, 1,-1,0 ]),
71 gl
.enableVertexAttribArray(0);
72 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
74 var vertexObject
= gl
.createBuffer();
75 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
76 gl
.bufferData(gl
.ARRAY_BUFFER
,
77 new Float32Array([ 0,0, 1,0, 0,1,
80 gl
.enableVertexAttribArray(1);
81 gl
.vertexAttribPointer(1, 2, gl
.FLOAT
, false, 0, 0);
83 var tex
= gl
.createTexture();
84 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
85 // 16x16 texture no mips
86 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas2d
);
88 var loc
= gl
.getUniformLocation(gl
.program
, "tex");
91 checkBuffer(0,0,0,255,
92 "texture that is not -texture-complete- when " +
93 "TEXTURE_MIN_FILTER not NEAREST or LINEAR should draw with 0,0,0,255");
95 function checkBuffer(r
, g
, b
, a
, msg
) {
96 gl
.clearColor(1,1,1,1);
97 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
98 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
100 var buf
= new Uint8Array(4 * 4 * 4);
101 gl
.readPixels(0, 0, 4, 4, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
102 for (var i
= 0; i
< 4 * 4; ++i
) {
104 if (buf
[offset
+ 0] != r
||
105 buf
[offset
+ 1] != g
||
106 buf
[offset
+ 2] != b
||
107 buf
[offset
+ 3] != a
) {
108 debug('expected: ' + r
+ ', ' + g
+ ', ' + b
+ ', ' + a
+
110 buf
[offset
+ 0] + ', ' +
111 buf
[offset
+ 1] + ', ' +
112 buf
[offset
+ 2] + ', ' +