OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |
7 "http://www.w3.org/TR/html4/loose.dtd"> | |
8 <html> | |
9 <head> | |
10 <title>WebGL ActiveTexture BindTexture conformance test #2</title> | |
11 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
12 <script src="../resources/js-test-pre.js"></script> | |
13 <script src="resources/webgl-test.js"> </script> | |
14 </head> | |
15 <body> | |
16 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></c
anvas> | |
17 <canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></
canvas> | |
18 <div id="description"></div> | |
19 <div id="console"></div> | |
20 <script id="vshader" type="x-shader/x-vertex"> | |
21 uniform mat4 world; | |
22 attribute vec3 vPosition; | |
23 attribute vec2 texCoord0; | |
24 varying vec2 texCoord; | |
25 void main() | |
26 { | |
27 gl_Position = world * vec4(vPosition, 1); | |
28 texCoord = texCoord0; | |
29 } | |
30 </script> | |
31 <script id="fshader2d" type="x-shader/x-fragment"> | |
32 #ifdef GL_ES | |
33 precision highp float; | |
34 #endif | |
35 uniform sampler2D tex2d; | |
36 varying vec2 texCoord; | |
37 void main() | |
38 { | |
39 gl_FragColor = texture2D(tex2d, texCoord); | |
40 } | |
41 </script> | |
42 <script id="fshaderCube" type="x-shader/x-fragment"> | |
43 #ifdef GL_ES | |
44 precision highp float; | |
45 #endif | |
46 uniform samplerCube texCube; | |
47 void main() | |
48 { | |
49 gl_FragColor = textureCube(texCube, vec3(0,1,0)); | |
50 } | |
51 </script> | |
52 | |
53 <script> | |
54 function init() | |
55 { | |
56 if (window.initNonKhronosFramework) { | |
57 window.initNonKhronosFramework(false); | |
58 } | |
59 | |
60 debug("Tests that binding both TEXTURE_2D and TEXTURE_CUBE_MAP to the same"); | |
61 debug("active texture unit works as long as they are not used"); | |
62 debug("simultaneously in the same shader program."); | |
63 debug(""); | |
64 | |
65 var canvas2d = document.getElementById("canvas2d"); | |
66 var ctx2d = canvas2d.getContext("2d"); | |
67 ctx2d.globalCompositeOperation = "copy"; | |
68 | |
69 gl = initWebGL("example", "vshader", "fshader2d", ["vPosition", "texCoord0"], | |
70 [ 0, 0, 0, 1 ], 1); | |
71 | |
72 var program2d = gl.program; | |
73 var programCube = createProgram( | |
74 gl, "vshader", "fshaderCube", ["vPosition", "texCoord0"]); | |
75 | |
76 gl.disable(gl.DEPTH_TEST); | |
77 gl.disable(gl.BLEND); | |
78 | |
79 var vertexObject = gl.createBuffer(); | |
80 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
81 gl.bufferData( | |
82 gl.ARRAY_BUFFER, | |
83 new Float32Array([-1, 1,0, 1,1,0, -1,-1,0, | |
84 -1,-1,0, 1,1,0, 1,-1,0]), | |
85 gl.STATIC_DRAW); | |
86 gl.enableVertexAttribArray(0); | |
87 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
88 | |
89 var vertexObject = gl.createBuffer(); | |
90 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
91 gl.bufferData( | |
92 gl.ARRAY_BUFFER, | |
93 new Float32Array([ 0,0, 1,0, 0,1, | |
94 0,1, 1,0, 1,1]), | |
95 gl.STATIC_DRAW); | |
96 gl.enableVertexAttribArray(1); | |
97 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); | |
98 | |
99 // Make texture unit 1 active. | |
100 gl.activeTexture(gl.TEXTURE1); | |
101 | |
102 // Make a 2d texture | |
103 var tex2d = gl.createTexture(); | |
104 gl.bindTexture(gl.TEXTURE_2D, tex2d); | |
105 ctx2d.fillStyle = "rgba(0, 0, 255, 255)"; | |
106 ctx2d.fillRect(0, 0, 1, 1); | |
107 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); | |
108 | |
109 // make a cube texture | |
110 var texCube = gl.createTexture(); | |
111 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube); | |
112 ctx2d.fillStyle = "rgba(255, 0, 255, 255)"; | |
113 ctx2d.fillRect(0, 0, 1, 1); | |
114 var targets = [ | |
115 gl.TEXTURE_CUBE_MAP_POSITIVE_X, | |
116 gl.TEXTURE_CUBE_MAP_NEGATIVE_X, | |
117 gl.TEXTURE_CUBE_MAP_POSITIVE_Y, | |
118 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, | |
119 gl.TEXTURE_CUBE_MAP_POSITIVE_Z, | |
120 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; | |
121 for (var ii = 0; ii < targets.length; ++ii) { | |
122 gl.texImage2D(targets[ii], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); | |
123 } | |
124 | |
125 // Setup program2d and programCube | |
126 var tex2dLoc = gl.getUniformLocation(program2d, "tex2d"); | |
127 var world2dLoc = gl.getUniformLocation(program2d, "world"); | |
128 var texCubeLoc = gl.getUniformLocation(programCube, "texCube"); | |
129 var worldCubeLoc = gl.getUniformLocation(programCube, "world"); | |
130 | |
131 gl.useProgram(program2d); | |
132 gl.uniform1i(tex2dLoc, 1); | |
133 gl.useProgram(programCube); | |
134 gl.uniform1i(texCubeLoc, 1); | |
135 | |
136 gl.clearColor(1,0,0,1); | |
137 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
138 | |
139 var programs = [program2d, programCube]; | |
140 var worldLocs = [world2dLoc, worldCubeLoc]; | |
141 for (var ii = 0; ii < 4; ++ii) { | |
142 var x = ii % 2; | |
143 var y = Math.floor(ii / 2); | |
144 gl.useProgram(programs[x]); | |
145 gl.uniformMatrix4fv( | |
146 worldLocs[x], false, | |
147 [0.5, 0, 0, 0, | |
148 0, 0.5, 0, 0, | |
149 0, 0, 1, 0, | |
150 -0.5 + x, -0.5 + y, 0, 1]); | |
151 gl.drawArrays(gl.TRIANGLES, 0, 6); | |
152 } | |
153 | |
154 var colors = [ | |
155 [0,0,255,255], | |
156 [255,0,255,255], | |
157 [0,0,255,255], | |
158 [255,0,255,255]]; | |
159 | |
160 for (var ii = 0; ii < colors.length; ++ii) { | |
161 var c = colors[ii]; | |
162 var x = ii % 2; | |
163 var y = Math.floor(ii / 2); | |
164 var buf = new Uint8Array(4); | |
165 gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
166 var msg = 'expected:' + | |
167 c[0] + ', ' + c[1] + ', ' + c[2] + ', ' + c[3] + ' found: ' + | |
168 buf[0] + ', ' + | |
169 buf[1] + ', ' + | |
170 buf[2] + ', ' + | |
171 buf[3]; | |
172 if (buf[0] != c[0] || | |
173 buf[1] != c[1] || | |
174 buf[2] != c[2] || | |
175 buf[3] != c[3]) { | |
176 testFailed(msg); | |
177 return; | |
178 } | |
179 | |
180 testPassed(msg); | |
181 } | |
182 } | |
183 | |
184 init(); | |
185 successfullyParsed = true; | |
186 </script> | |
187 <script src="../resources/js-test-post.js"></script> | |
188 | |
189 </body> | |
190 </html> | |
191 | |
OLD | NEW |