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

changeset 0
6474c204b198
     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.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     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.</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 +<script src="../resources/webgl-test-utils.js"></script>
    1.18 +</head>
    1.19 +<body>
    1.20 +<canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas>
    1.21 +<canvas id="canvas2d" width="1" height="1" style="width: 40px; height: 40px;"></canvas>
    1.22 +<div id="description"></div>
    1.23 +<div id="console"></div>
    1.24 +<script id="vshader" type="x-shader/x-vertex">
    1.25 +uniform mat4 world;
    1.26 +attribute vec3 vPosition;
    1.27 +attribute vec2 texCoord0;
    1.28 +varying vec2 texCoord;
    1.29 +void main()
    1.30 +{
    1.31 +  gl_Position = world * vec4(vPosition, 1);
    1.32 +  texCoord = texCoord0;
    1.33 +}
    1.34 +</script>
    1.35 +<script>
    1.36 +var gl;
    1.37 +
    1.38 +function init()
    1.39 +{
    1.40 +  if (window.initNonKhronosFramework) {
    1.41 +    window.initNonKhronosFramework(false);
    1.42 +  }
    1.43 +
    1.44 +  description(
    1.45 +      "Tests that glActiveTexture and glBindTexture work as expected" +
    1.46 +      "Specifically texture targets are per active texture unit.");
    1.47 +
    1.48 +  var canvas2d = document.getElementById("canvas2d");
    1.49 +  var ctx2d = canvas2d.getContext("2d");
    1.50 +
    1.51 +  var wtu = WebGLTestUtils;
    1.52 +  gl = wtu.create3DContext("example");
    1.53 +  var program = wtu.setupProgram(
    1.54 +      gl,
    1.55 +      ["vshader", wtu.setupSimpleTextureFragmentShader(gl)],
    1.56 +      ['vPosition', 'texCoord0']);
    1.57 +  wtu.setupUnitQuad(gl);
    1.58 +  gl.disable(gl.DEPTH_TEST);
    1.59 +  gl.disable(gl.BLEND);
    1.60 +  glErrorShouldBe(gl, gl.NO_ERROR);
    1.61 +
    1.62 +  var colors = [
    1.63 +      [0,192,128,255],
    1.64 +      [128,64,255,255],
    1.65 +      [192,255,64,255],
    1.66 +      [200,0,255,255]];
    1.67 +
    1.68 +  // Make 4 textures by using 4 active texture units if available.
    1.69 +  var texunits = Math.min(colors.length, gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS))
    1.70 +  var textures = [];
    1.71 +  for (var ii = 0; ii < texunits; ++ii) {
    1.72 +    var tex = gl.createTexture();
    1.73 +    gl.activeTexture(gl.TEXTURE0 + ii);
    1.74 +    gl.bindTexture(gl.TEXTURE_2D, tex);
    1.75 +    textures[ii] = tex;
    1.76 +  }
    1.77 +  glErrorShouldBe(gl, gl.NO_ERROR);
    1.78 +
    1.79 +  // now use each texture unit to write into the textures,
    1.80 +  for (var ii = 0; ii < texunits; ++ii) {
    1.81 +    var c = colors[ii];
    1.82 +    ctx2d.fillStyle =
    1.83 +        "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")";
    1.84 +    ctx2d.fillRect(0, 0, 1, 1);
    1.85 +    gl.activeTexture(gl.TEXTURE0 + ii);
    1.86 +    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas2d);
    1.87 +  }
    1.88 +  glErrorShouldBe(gl, gl.NO_ERROR);
    1.89 +
    1.90 +  var textureLoc = gl.getUniformLocation(program, "tex");
    1.91 +  var worldLoc = gl.getUniformLocation(program, "world");
    1.92 +  glErrorShouldBe(gl, gl.NO_ERROR);
    1.93 +
    1.94 +  gl.clearColor(1,0,0,1);
    1.95 +  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    1.96 +
    1.97 +  for (var ii = 0; ii < texunits; ++ii) {
    1.98 +    var x = ii % 2;
    1.99 +    var y = Math.floor(ii / 2);
   1.100 +    gl.uniform1i(textureLoc, ii);
   1.101 +    gl.uniformMatrix4fv(
   1.102 +        worldLoc, false,
   1.103 +        [0.5, 0, 0, 0,
   1.104 +         0, 0.5, 0, 0,
   1.105 +         0, 0, 1, 0,
   1.106 +         -0.5 + x, -0.5 + y, 0, 1]);
   1.107 +    gl.drawArrays(gl.TRIANGLES, 0, 6);
   1.108 +  }
   1.109 +  glErrorShouldBe(gl, gl.NO_ERROR);
   1.110 +
   1.111 +  for (var ii = 0; ii < texunits; ++ii) {
   1.112 +    var c = colors[ii];
   1.113 +    var x = ii % 2;
   1.114 +    var y = Math.floor(ii / 2);
   1.115 +    var buf = new Uint8Array(4);
   1.116 +    gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, buf);
   1.117 +    var msg = 'expected:' +
   1.118 +        c[0] + ', ' + c[1] + ', ' + c[2] + ', ' + c[3] + ' found: ' +
   1.119 +        buf[0] + ', ' +
   1.120 +        buf[1] + ', ' +
   1.121 +        buf[2] + ', ' +
   1.122 +        buf[3];
   1.123 +    if (buf[0] != c[0] ||
   1.124 +        buf[1] != c[1] ||
   1.125 +        buf[2] != c[2] ||
   1.126 +        buf[3] != c[3])
   1.127 +      testFailed(msg);
   1.128 +    else
   1.129 +      testPassed(msg);
   1.130 +  }
   1.131 +}
   1.132 +
   1.133 +init();
   1.134 +successfullyParsed = true;
   1.135 +</script>
   1.136 +
   1.137 +<script>finishTest();</script>
   1.138 +
   1.139 +</body>
   1.140 +</html>
   1.141 +

mercurial