Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / textures / texture-active-bind.html
1 <!--
2
3 /*
4 ** Copyright (c) 2012 The Khronos Group Inc.
5 **
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:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
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.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
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>
36 </head>
37 <body>
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">
43 uniform mat4 world;
44 attribute vec3 vPosition;
45 attribute vec2 texCoord0;
46 varying vec2 texCoord;
47 void main()
48 {
49   gl_Position = world * vec4(vPosition, 1);
50   texCoord = texCoord0;
51 }
52 </script>
53 <script>
54 "use strict";
55 var gl;
56
57 function init()
58 {
59   description(
60       "Tests that glActiveTexture and glBindTexture work as expected" +
61       "Specifically texture targets are per active texture unit.");
62
63   var canvas2d = document.getElementById("canvas2d");
64   var ctx2d = canvas2d.getContext("2d");
65
66   var wtu = WebGLTestUtils;
67   gl = wtu.create3DContext("example");
68   var program = wtu.setupProgram(
69       gl,
70       ["vshader", wtu.setupSimpleTextureFragmentShader(gl)],
71       ['vPosition', 'texCoord0']);
72   wtu.setupUnitQuad(gl);
73   gl.disable(gl.DEPTH_TEST);
74   gl.disable(gl.BLEND);
75   wtu.glErrorShouldBe(gl, gl.NO_ERROR);
76
77   var colors = [
78       [0,192,128,255],
79       [128,64,255,255],
80       [192,255,64,255],
81       [200,0,255,255]];
82
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))
85   var textures = [];
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);
90     textures[ii] = tex;
91   }
92   wtu.glErrorShouldBe(gl, gl.NO_ERROR);
93
94   // now use each texture unit to write into the textures,
95   for (var ii = 0; ii < texunits; ++ii) {
96     var c = colors[ii];
97     ctx2d.fillStyle =
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);
102   }
103   wtu.glErrorShouldBe(gl, gl.NO_ERROR);
104
105   var textureLoc = gl.getUniformLocation(program, "tex");
106   var worldLoc = gl.getUniformLocation(program, "world");
107   wtu.glErrorShouldBe(gl, gl.NO_ERROR);
108
109   gl.clearColor(1,0,0,1);
110   gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
111
112   for (var ii = 0; ii < texunits; ++ii) {
113     var x = ii % 2;
114     var y = Math.floor(ii / 2);
115     gl.uniform1i(textureLoc, ii);
116     gl.uniformMatrix4fv(
117         worldLoc, false,
118         [0.5, 0, 0, 0,
119          0, 0.5, 0, 0,
120          0, 0, 1, 0,
121          -0.5 + x, -0.5 + y, 0, 1]);
122     gl.drawArrays(gl.TRIANGLES, 0, 6);
123   }
124   wtu.glErrorShouldBe(gl, gl.NO_ERROR);
125
126   for (var ii = 0; ii < texunits; ++ii) {
127     var x = ii % 2;
128     var y = Math.floor(ii / 2);
129     wtu.checkCanvasRect(gl, x, y, 1, 1, colors[ii]);
130   }
131 }
132
133 init();
134 var successfullyParsed = true;
135 </script>
136
137 <script src="../../resources/js-test-post.js"></script>
138
139 </body>
140 </html>
141