1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
5 <title>WebGL ActiveTexture BindTexture conformance test.
</title>
6 <script src=
"../../../resources/js-test.js"></script>
7 <script src=
"resources/webgl-test.js"> </script>
10 <canvas id=
"example" width=
"2" height=
"2" style=
"width: 40px; height: 40px;"></canvas>
11 <canvas id=
"canvas2d" width=
"1" height=
"1" 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 attribute vec3 vPosition;
17 attribute vec2 texCoord0;
18 varying vec2 texCoord;
21 gl_Position = world * vec4(vPosition,
1);
26 <script id=
"fshader" type=
"x-shader/x-fragment">
28 precision highp float;
30 uniform sampler2D tex;
31 varying vec2 texCoord;
34 gl_FragColor = texture2D(tex, texCoord);
41 if (window
.initNonKhronosFramework
) {
42 window
.initNonKhronosFramework(false);
45 debug("Tests that glActiveTexture and glBindTexture work as expected");
46 debug("Specifically texture targets are per active texture unit.");
49 var canvas2d
= document
.getElementById("canvas2d");
50 var ctx2d
= canvas2d
.getContext("2d");
52 gl
= initWebGL("example", "vshader", "fshader", [ "vPosition", "texCoord0"],
55 gl
.disable(gl
.DEPTH_TEST
);
58 var vertexObject
= gl
.createBuffer();
59 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
62 new Float32Array([-1, 1,0, 1,1,0, -1,-1,0,
63 -1,-1,0, 1,1,0, 1,-1,0]),
65 gl
.enableVertexAttribArray(0);
66 gl
.vertexAttribPointer(0, 3, gl
.FLOAT
, false, 0, 0);
68 var vertexObject
= gl
.createBuffer();
69 gl
.bindBuffer(gl
.ARRAY_BUFFER
, vertexObject
);
72 new Float32Array([ 0,0, 1,0, 0,1,
75 gl
.enableVertexAttribArray(1);
76 gl
.vertexAttribPointer(1, 2, gl
.FLOAT
, false, 0, 0);
77 shouldBe("gl.getError()", "gl.NO_ERROR");
85 // Make 4 textures by using 4 active texture units.
87 for (var ii
= 0; ii
< colors
.length
; ++ii
) {
88 var tex
= gl
.createTexture();
89 gl
.activeTexture(gl
.TEXTURE0
+ ii
);
90 gl
.bindTexture(gl
.TEXTURE_2D
, tex
);
93 shouldBe("gl.getError()", "gl.NO_ERROR");
95 // now use each texture unit to write into the textures,
96 for (var ii
= 0; ii
< colors
.length
; ++ii
) {
99 "rgba(" + c
[0] + "," + c
[1] + "," + c
[2] + "," + c
[3] + ")";
100 ctx2d
.fillRect(0, 0, 1, 1);
101 gl
.activeTexture(gl
.TEXTURE0
+ ii
);
102 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, canvas2d
);
104 shouldBe("gl.getError()", "gl.NO_ERROR");
106 var textureLoc
= gl
.getUniformLocation(gl
.program
, "tex");
107 var worldLoc
= gl
.getUniformLocation(gl
.program
, "world");
108 shouldBe("gl.getError()", "gl.NO_ERROR");
110 gl
.clearColor(1,0,0,1);
111 gl
.clear(gl
.COLOR_BUFFER_BIT
| gl
.DEPTH_BUFFER_BIT
);
113 for (var ii
= 0; ii
< colors
.length
; ++ii
) {
115 var y
= Math
.floor(ii
/ 2);
116 gl
.uniform1i(textureLoc
, ii
);
122 -0.5 + x
, -0.5 + y
, 0, 1]);
123 gl
.drawArrays(gl
.TRIANGLES
, 0, 6);
125 shouldBe("gl.getError()", "gl.NO_ERROR");
127 for (var ii
= 0; ii
< colors
.length
; ++ii
) {
130 var y
= Math
.floor(ii
/ 2);
131 var buf
= new Uint8Array(4);
132 gl
.readPixels(x
, y
, 1, 1, gl
.RGBA
, gl
.UNSIGNED_BYTE
, buf
);
133 var msg
= 'expected:' +
134 c
[0] + ', ' + c
[1] + ', ' + c
[2] + ', ' + c
[3] + ' found: ' +
139 if (buf
[0] != c
[0] ||