content/canvas/test/webgl-conformance/conformance/textures/texture-active-bind-2.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

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

mercurial