content/canvas/test/webgl-conformance/conformance/textures/copy-tex-image-and-sub-image-2d.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/copy-tex-image-and-sub-image-2d.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,136 @@
     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 +<link rel="stylesheet" href="../../resources/js-test-style.css"/>
    1.14 +<script src="../../resources/js-test-pre.js"></script>
    1.15 +<script src="../resources/webgl-test.js"></script>
    1.16 +<script src="../resources/webgl-test-utils.js"></script>
    1.17 +
    1.18 +<script>
    1.19 +var successfullyParsed = false;
    1.20 +
    1.21 +function init()
    1.22 +{
    1.23 +    if (window.initNonKhronosFramework) {
    1.24 +        window.initNonKhronosFramework(true);
    1.25 +    }
    1.26 +
    1.27 +    description('Verify copyTexImage2D and copyTexSubImage2D');
    1.28 +
    1.29 +    runTest();
    1.30 +}
    1.31 +
    1.32 +var gl = null;
    1.33 +var wtu = WebGLTestUtils;
    1.34 +
    1.35 +function runTestIteration(antialias)
    1.36 +{
    1.37 +    var canvas = document.getElementById(
    1.38 +        antialias ? "antialiasOn" : "antialiasOff");
    1.39 +    var attribs = antialias ? { antialias: false } : undefined;
    1.40 +    gl = wtu.create3DContext(canvas, attribs);
    1.41 +    var program = wtu.setupTexturedQuad(gl);
    1.42 +    var textureLoc = gl.getUniformLocation(program, "tex");
    1.43 +    glErrorShouldBe(gl, gl.NO_ERROR, "During Initialization");
    1.44 +
    1.45 +    gl.colorMask(1, 1, 1, 1);
    1.46 +    gl.disable(gl.BLEND);
    1.47 +    debug('Testing copyTexImage2D');
    1.48 +
    1.49 +    // Red canvas
    1.50 +    gl.clearColor(1, 0, 0, 1);
    1.51 +    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    1.52 +
    1.53 +    var texture = gl.createTexture();
    1.54 +    // Bind the texture to texture unit 0
    1.55 +    gl.bindTexture(gl.TEXTURE_2D, texture);
    1.56 +    // Set up texture
    1.57 +    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
    1.58 +    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
    1.59 +    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
    1.60 +    gl.uniform1i(textureLoc, 0);
    1.61 +
    1.62 +    var colors = [
    1.63 +      [1, 0, 0, 1],
    1.64 +      [0, 1, 0, 1],
    1.65 +      [0, 0, 1, 1],
    1.66 +      [0.5, 0.5, 0.5, 0.5],
    1.67 +    ];
    1.68 +    var count = 0;
    1.69 +    for (var yy = -2; yy <= 2; ++yy) {
    1.70 +      for (var xx = -2; xx <= 2; ++xx) {
    1.71 +         for (var ii = 0; ii < 2; ++ii) {
    1.72 +          var texColor = colors[count];
    1.73 +          var clearColor = colors[(count + 1) % colors.length];
    1.74 +          // clear to some color
    1.75 +          gl.clearColor(texColor[0], texColor[1], texColor[2], texColor[3]);
    1.76 +          gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    1.77 +
    1.78 +          // copy that color to the texture.
    1.79 +          switch (ii) {
    1.80 +          case 0:
    1.81 +            gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, xx, yy, 2, 2, 0);
    1.82 +            glErrorShouldBe(gl, gl.NO_ERROR,
    1.83 +                "using copyTexImage2D: x =" + xx + ", y = " + yy);
    1.84 +            break;
    1.85 +          case 1:
    1.86 +            gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, xx, yy, 2, 2);
    1.87 +            glErrorShouldBe(gl, gl.NO_ERROR,
    1.88 +                "using copyTexSubImage2D: x =" + xx + ", y = " + yy);
    1.89 +            break;
    1.90 +          }
    1.91 +
    1.92 +          // clear to some other color.
    1.93 +          gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
    1.94 +          gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    1.95 +
    1.96 +          // Draw the triangles
    1.97 +          wtu.drawQuad(gl);
    1.98 +
    1.99 +          // check the rendering results
   1.100 +          for (var iy = 0; iy < 2; ++iy) {
   1.101 +            for (var ix = 0; ix < 2; ++ix) {
   1.102 +              var x = xx + ix;
   1.103 +              var y = yy + iy;
   1.104 +              var expectedColor = (x < 0 || y < 0 || x >= 2 || y >= 2) ?
   1.105 +                  [0,0,0,0] :
   1.106 +                  [Math.floor(255 * texColor[0]),
   1.107 +                   Math.floor(255 * texColor[1]),
   1.108 +                   Math.floor(255 * texColor[2]),
   1.109 +                   Math.floor(255 * texColor[3])];
   1.110 +              wtu.checkCanvasRect(gl, ix, iy, 1, 1, expectedColor,
   1.111 +                  "" + ix + ", " + iy + " should render " + expectedColor + " (+/-1)", 1);
   1.112 +            }
   1.113 +          }
   1.114 +          count = (count + 1) % colors.length;
   1.115 +        }
   1.116 +      }
   1.117 +    }
   1.118 +
   1.119 +    debug("");
   1.120 +}
   1.121 +
   1.122 +function runTest(antialias)
   1.123 +{
   1.124 +    debug("Testing with antialias on");
   1.125 +    runTestIteration(true);
   1.126 +    debug("Testing with antialias off");
   1.127 +    runTestIteration(false);
   1.128 +
   1.129 +    finishTest();
   1.130 +}
   1.131 +</script>
   1.132 +</head>
   1.133 +<body onload="init()">
   1.134 +<canvas id="antialiasOn" width="2px" height="2px"></canvas>
   1.135 +<canvas id="antialiasOff" width="2px" height="2px"></canvas>
   1.136 +<div id="description"></div>
   1.137 +<div id="console"></div>
   1.138 +</body>
   1.139 +</html>

mercurial