1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/textures/texture-active-bind-2.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,189 @@ 1.4 +<!-- 1.5 +Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 + --> 1.9 +<!DOCTYPE html> 1.10 +<html> 1.11 + <head> 1.12 +<meta charset="utf-8"> 1.13 + <title>WebGL ActiveTexture BindTexture conformance test #2</title> 1.14 + <link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.15 + <script src="../../resources/js-test-pre.js"></script> 1.16 + <script src="../resources/webgl-test.js"> </script> 1.17 +</head> 1.18 +<body> 1.19 +<canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas> 1.20 +<canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></canvas> 1.21 +<div id="description"></div> 1.22 +<div id="console"></div> 1.23 +<script id="vshader" type="x-shader/x-vertex"> 1.24 +uniform mat4 world; 1.25 +attribute vec3 vPosition; 1.26 +attribute vec2 texCoord0; 1.27 +varying vec2 texCoord; 1.28 +void main() 1.29 +{ 1.30 + gl_Position = world * vec4(vPosition, 1); 1.31 + texCoord = texCoord0; 1.32 +} 1.33 +</script> 1.34 +<script id="fshader2d" type="x-shader/x-fragment"> 1.35 +precision mediump float; 1.36 + 1.37 +uniform sampler2D tex2d; 1.38 +varying vec2 texCoord; 1.39 +void main() 1.40 +{ 1.41 + gl_FragColor = texture2D(tex2d, texCoord); 1.42 +} 1.43 +</script> 1.44 +<script id="fshaderCube" type="x-shader/x-fragment"> 1.45 +precision mediump float; 1.46 + 1.47 +uniform samplerCube texCube; 1.48 +void main() 1.49 +{ 1.50 + gl_FragColor = textureCube(texCube, vec3(0,1,0)); 1.51 +} 1.52 +</script> 1.53 + 1.54 +<script> 1.55 +function init() 1.56 +{ 1.57 + if (window.initNonKhronosFramework) { 1.58 + window.initNonKhronosFramework(false); 1.59 + } 1.60 + 1.61 + description( 1.62 + "Tests that binding both TEXTURE_2D and TEXTURE_CUBE_MAP to the same" + 1.63 + "active texture unit works as long as they are not used" + 1.64 + "simultaneously in the same shader program."); 1.65 + 1.66 + var canvas2d = document.getElementById("canvas2d"); 1.67 + var ctx2d = canvas2d.getContext("2d"); 1.68 + ctx2d.globalCompositeOperation = "copy"; 1.69 + 1.70 + gl = initWebGL("example", "vshader", "fshader2d", ["vPosition", "texCoord0"], 1.71 + [ 0, 0, 0, 1 ], 1); 1.72 + 1.73 + var program2d = gl.program; 1.74 + var programCube = createProgram( 1.75 + gl, "vshader", "fshaderCube", ["vPosition", "texCoord0"]); 1.76 + 1.77 + gl.disable(gl.DEPTH_TEST); 1.78 + gl.disable(gl.BLEND); 1.79 + 1.80 + var vertexObject = gl.createBuffer(); 1.81 + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 1.82 + gl.bufferData( 1.83 + gl.ARRAY_BUFFER, 1.84 + new Float32Array([-1, 1,0, 1,1,0, -1,-1,0, 1.85 + -1,-1,0, 1,1,0, 1,-1,0]), 1.86 + gl.STATIC_DRAW); 1.87 + gl.enableVertexAttribArray(0); 1.88 + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); 1.89 + 1.90 + var vertexObject = gl.createBuffer(); 1.91 + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 1.92 + gl.bufferData( 1.93 + gl.ARRAY_BUFFER, 1.94 + new Float32Array([ 0,0, 1,0, 0,1, 1.95 + 0,1, 1,0, 1,1]), 1.96 + gl.STATIC_DRAW); 1.97 + gl.enableVertexAttribArray(1); 1.98 + gl.vertexAttribPointer(1, 2, gl.FLOAT, false, 0, 0); 1.99 + 1.100 + // Make texture unit 1 active. 1.101 + gl.activeTexture(gl.TEXTURE1); 1.102 + 1.103 + // Make a 2d texture 1.104 + var tex2d = gl.createTexture(); 1.105 + gl.bindTexture(gl.TEXTURE_2D, tex2d); 1.106 + ctx2d.fillStyle = "rgba(0, 0, 255, 255)"; 1.107 + ctx2d.fillRect(0, 0, 1, 1); 1.108 + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); 1.109 + 1.110 + // make a cube texture 1.111 + var texCube = gl.createTexture(); 1.112 + gl.bindTexture(gl.TEXTURE_CUBE_MAP, texCube); 1.113 + ctx2d.fillStyle = "rgba(255, 0, 255, 255)"; 1.114 + ctx2d.fillRect(0, 0, 1, 1); 1.115 + var targets = [ 1.116 + gl.TEXTURE_CUBE_MAP_POSITIVE_X, 1.117 + gl.TEXTURE_CUBE_MAP_NEGATIVE_X, 1.118 + gl.TEXTURE_CUBE_MAP_POSITIVE_Y, 1.119 + gl.TEXTURE_CUBE_MAP_NEGATIVE_Y, 1.120 + gl.TEXTURE_CUBE_MAP_POSITIVE_Z, 1.121 + gl.TEXTURE_CUBE_MAP_NEGATIVE_Z]; 1.122 + for (var ii = 0; ii < targets.length; ++ii) { 1.123 + gl.texImage2D(targets[ii], 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d); 1.124 + } 1.125 + 1.126 + // Setup program2d and programCube 1.127 + var tex2dLoc = gl.getUniformLocation(program2d, "tex2d"); 1.128 + var world2dLoc = gl.getUniformLocation(program2d, "world"); 1.129 + var texCubeLoc = gl.getUniformLocation(programCube, "texCube"); 1.130 + var worldCubeLoc = gl.getUniformLocation(programCube, "world"); 1.131 + 1.132 + gl.useProgram(program2d); 1.133 + gl.uniform1i(tex2dLoc, 1); 1.134 + gl.useProgram(programCube); 1.135 + gl.uniform1i(texCubeLoc, 1); 1.136 + 1.137 + gl.clearColor(1,0,0,1); 1.138 + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 1.139 + 1.140 + var programs = [program2d, programCube]; 1.141 + var worldLocs = [world2dLoc, worldCubeLoc]; 1.142 + for (var ii = 0; ii < 4; ++ii) { 1.143 + var x = ii % 2; 1.144 + var y = Math.floor(ii / 2); 1.145 + gl.useProgram(programs[x]); 1.146 + gl.uniformMatrix4fv( 1.147 + worldLocs[x], false, 1.148 + [0.5, 0, 0, 0, 1.149 + 0, 0.5, 0, 0, 1.150 + 0, 0, 1, 0, 1.151 + -0.5 + x, -0.5 + y, 0, 1]); 1.152 + gl.drawArrays(gl.TRIANGLES, 0, 6); 1.153 + } 1.154 + 1.155 + var colors = [ 1.156 + [0,0,255,255], 1.157 + [255,0,255,255], 1.158 + [0,0,255,255], 1.159 + [255,0,255,255]]; 1.160 + 1.161 + for (var ii = 0; ii < colors.length; ++ii) { 1.162 + var c = colors[ii]; 1.163 + var x = ii % 2; 1.164 + var y = Math.floor(ii / 2); 1.165 + var buf = new Uint8Array(4); 1.166 + gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf); 1.167 + var msg = 'expected:' + 1.168 + c[0] + ', ' + c[1] + ', ' + c[2] + ', ' + c[3] + ' found: ' + 1.169 + buf[0] + ', ' + 1.170 + buf[1] + ', ' + 1.171 + buf[2] + ', ' + 1.172 + buf[3]; 1.173 + if (buf[0] != c[0] || 1.174 + buf[1] != c[1] || 1.175 + buf[2] != c[2] || 1.176 + buf[3] != c[3]) { 1.177 + testFailed(msg); 1.178 + return; 1.179 + } 1.180 + 1.181 + testPassed(msg); 1.182 + } 1.183 +} 1.184 + 1.185 +init(); 1.186 +successfullyParsed = true; 1.187 +</script> 1.188 +<script>finishTest();</script> 1.189 + 1.190 +</body> 1.191 +</html> 1.192 +