Bug 1918529 - fix some subpixel misalignment issues with gfx.webrender.svg-filter...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / textures / misc / texture-active-bind-2.html
blobf459924ad1bd301c269fa8c87fe92acdb85b6d4f
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL ActiveTexture BindTexture conformance test #2</title>
12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
13 <script src="../../../js/js-test-pre.js"></script>
14 <script src="../../../js/webgl-test-utils.js"> </script>
15 </head>
16 <body>
17 <canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
18 <canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></canvas>
19 <div id="description"></div>
20 <div id="console"></div>
21 <script id="vshader" type="x-shader/x-vertex">
22 uniform mat4 world;
23 attribute vec3 vPosition;
24 attribute vec2 texCoord0;
25 varying vec2 texCoord;
26 void main()
28 gl_Position = world * vec4(vPosition, 1);
29 texCoord = texCoord0;
31 </script>
32 <script id="fshader2d" type="x-shader/x-fragment">
33 precision mediump float;
35 uniform sampler2D tex2d;
36 varying vec2 texCoord;
37 void main()
39 gl_FragColor = texture2D(tex2d, texCoord);
41 </script>
42 <script id="fshaderCube" type="x-shader/x-fragment">
43 precision mediump float;
45 uniform samplerCube texCube;
46 void main()
48 gl_FragColor = textureCube(texCube, vec3(0,1,0));
50 </script>
52 <script>
53 "use strict";
54 function init()
56 description(
57 "Tests that binding both TEXTURE_2D and TEXTURE_CUBE_MAP to the same " +
58 "active texture unit works as long as they are not used " +
59 "simultaneously in the same shader program.");
61 var canvas2d = document.getElementById("canvas2d");
62 var ctx2d = canvas2d.getContext("2d");
63 ctx2d.globalCompositeOperation = "copy";
65 var wtu = WebGLTestUtils;
66 var gl = wtu.create3DContext("example");
67 var program = wtu.setupProgram(
68 gl, ["vshader", "fshader2d"], ["vPosition", "texCoord0"]);
70 var program2d = program;
71 var programCube = wtu.setupProgram(
72 gl, ["vshader", "fshaderCube"], ["vPosition", "texCoord0"]);
74 var vertexObject = gl.createBuffer();
75 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
76 gl.bufferData(
77 gl.ARRAY_BUFFER,
78 new Float32Array([-1, 1,0, 1,1,0, -1,-1,0,
79 -1,-1,0, 1,1,0, 1,-1,0]),
80 gl.STATIC_DRAW);
81 gl.enableVertexAttribArray(0);
82 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
84 var vertexObject = gl.createBuffer();
85 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
86 gl.bufferData(
87 gl.ARRAY_BUFFER,
88 new Float32Array([ 0,0, 1,0, 0,1,
89 0,1, 1,0, 1,1]),
90 gl.STATIC_DRAW);
91 gl.enableVertexAttribArray(1);
92 gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0);
94 // Make texture unit 1 active.
95 gl.activeTexture(gl.TEXTURE1);
97 // Make a 2d texture
98 var tex2d = gl.createTexture();
99 gl.bindTexture(gl.TEXTURE_2D, tex2d);
100 ctx2d.fillStyle = "rgba(0, 0, 255, 255)";
101 ctx2d.fillRect(0, 0, 1, 1);
102 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
104 // make a cube texture
105 var texCube = gl.createTexture();
106 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube);
107 ctx2d.fillStyle = "rgba(255, 0, 255, 255)";
108 ctx2d.fillRect(0, 0, 1, 1);
109 var targets = [
110 gl.TEXTURE_CUBE_MAP_POSITIVE_X,
111 gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
112 gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
113 gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
114 gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
115 gl.TEXTURE_CUBE_MAP_NEGATIVE_Z];
116 for (var ii = 0; ii < targets.length; ++ii) {
117 gl.texImage2D(targets[ii], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
120 // Setup program2d and programCube
121 var tex2dLoc = gl.getUniformLocation(program2d, "tex2d");
122 var world2dLoc = gl.getUniformLocation(program2d, "world");
123 var texCubeLoc = gl.getUniformLocation(programCube, "texCube");
124 var worldCubeLoc = gl.getUniformLocation(programCube, "world");
126 gl.useProgram(program2d);
127 gl.uniform1i(tex2dLoc, 1);
128 gl.useProgram(programCube);
129 gl.uniform1i(texCubeLoc, 1);
131 gl.clearColor(1,0,0,1);
132 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
134 var programs = [program2d, programCube];
135 var worldLocs = [world2dLoc, worldCubeLoc];
136 for (var ii = 0; ii < 4; ++ii) {
137 var x = ii % 2;
138 var y = Math.floor(ii / 2);
139 gl.useProgram(programs[x]);
140 gl.uniformMatrix4fv(
141 worldLocs[x], false,
142 [0.5, 0, 0, 0,
143 0, 0.5, 0, 0,
144 0, 0, 1, 0,
145 -0.5 + x, -0.5 + y, 0, 1]);
146 gl.drawArrays(gl.TRIANGLES, 0, 6);
149 var colors = [
150 [0,0,255,255],
151 [255,0,255,255],
152 [0,0,255,255],
153 [255,0,255,255]];
155 for (var ii = 0; ii < colors.length; ++ii) {
156 var c = colors[ii];
157 var x = ii % 2;
158 var y = Math.floor(ii / 2);
159 wtu.checkCanvasRect(gl, x, y, 1, 1, c);
162 // Test that binding to one target does not affect the other
163 debug("");
164 debug("Testing texture target binding/unbinding");
166 var worldMatrix = [
167 1, 0, 0, 0,
168 0, 1, 0, 0,
169 0, 0, 1, 0,
170 0, 0, 0, 1];
172 gl.activeTexture(gl.TEXTURE2);
174 // Unbinding the TEXTURE_CUBE_MAP target should not affect the TEXTURE_2D target
175 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
177 gl.bindTexture(gl.TEXTURE_2D, tex2d);
178 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube);
179 gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
181 gl.useProgram(program2d);
182 gl.uniform1i(tex2dLoc, 2);
183 gl.uniformMatrix4fv(world2dLoc, false, worldMatrix);
184 gl.drawArrays(gl.TRIANGLES, 0, 6);
186 wtu.checkCanvasRect(gl, 0, 0, 2, 2, [0,0,255,255]);
188 // Unbinding the TEXTURE_2D target should not affect the TEXTURE_CUBE_MAP target
189 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
191 gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube);
192 gl.bindTexture(gl.TEXTURE_2D, tex2d);
193 gl.bindTexture(gl.TEXTURE_2D, null);
195 gl.useProgram(programCube);
196 gl.uniform1i(texCubeLoc, 2);
197 gl.uniformMatrix4fv(worldCubeLoc, false, worldMatrix);
198 gl.drawArrays(gl.TRIANGLES, 0, 6);
200 wtu.checkCanvasRect(gl, 0, 0, 2, 2, [255,0,255,255]);
203 init();
204 var successfullyParsed = true;
205 </script>
206 <script src="../../../js/js-test-post.js"></script>
208 </body>
209 </html>