4 ** Copyright (c) 2012 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>WebGL ActiveTexture BindTexture conformance test.</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test-utils.js"></script>
38 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
39 <canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></canvas>
40 <div id="description"></div>
41 <div id="console"></div>
42 <script id="vshader" type="x-shader/x-vertex">
44 attribute vec3 vPosition;
45 attribute vec2 texCoord0;
46 varying vec2 texCoord;
49 gl_Position = world * vec4(vPosition, 1);
60 "Tests that glActiveTexture and glBindTexture work as expected" +
61 "Specifically texture targets are per active texture unit.");
63 var canvas2d = document.getElementById("canvas2d");
64 var ctx2d = canvas2d.getContext("2d");
66 var wtu = WebGLTestUtils;
67 gl = wtu.create3DContext("example");
68 var program = wtu.setupProgram(
70 ["vshader", wtu.setupSimpleTextureFragmentShader(gl)],
71 ['vPosition', 'texCoord0']);
72 wtu.setupUnitQuad(gl);
73 gl.disable(gl.DEPTH_TEST);
75 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
83 // Make 4 textures by using 4 active texture units if available.
84 var texunits = Math.min(colors.length, gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS))
86 for (var ii = 0; ii < texunits; ++ii) {
87 var tex = gl.createTexture();
88 gl.activeTexture(gl.TEXTURE0 + ii);
89 gl.bindTexture(gl.TEXTURE_2D, tex);
92 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
94 // now use each texture unit to write into the textures,
95 for (var ii = 0; ii < texunits; ++ii) {
98 "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")";
99 ctx2d.fillRect(0, 0, 1, 1);
100 gl.activeTexture(gl.TEXTURE0 + ii);
101 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
103 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
105 var textureLoc = gl.getUniformLocation(program, "tex");
106 var worldLoc = gl.getUniformLocation(program, "world");
107 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
109 gl.clearColor(1,0,0,1);
110 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
112 for (var ii = 0; ii < texunits; ++ii) {
114 var y = Math.floor(ii / 2);
115 gl.uniform1i(textureLoc, ii);
121 -0.5 + x, -0.5 + y, 0, 1]);
122 gl.drawArrays(gl.TRIANGLES, 0, 6);
124 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
126 for (var ii = 0; ii < texunits; ++ii) {
128 var y = Math.floor(ii / 2);
129 wtu.checkCanvasRect(gl, x, y, 1, 1, colors[ii]);
134 var successfullyParsed = true;
137 <script src="../../resources/js-test-post.js"></script>