content/canvas/test/webgl-conformance/conformance/textures/tex-image-and-sub-image-2d-with-canvas.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/tex-image-and-sub-image-2d-with-canvas.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     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 +<script>
    1.18 +var wtu = WebGLTestUtils;
    1.19 +var gl = null;
    1.20 +var textureLoc = null;
    1.21 +var successfullyParsed = false;
    1.22 +
    1.23 +function init()
    1.24 +{
    1.25 +    if (window.initNonKhronosFramework) {
    1.26 +        window.initNonKhronosFramework(true);
    1.27 +    }
    1.28 +
    1.29 +    description('Verify texImage2D and texSubImage2D code paths taking Images');
    1.30 +
    1.31 +    var canvas = document.getElementById("example");
    1.32 +    gl = wtu.create3DContext(canvas);
    1.33 +    var program = wtu.setupTexturedQuad(gl);
    1.34 +
    1.35 +    gl.clearColor(0,0,0,1);
    1.36 +    gl.clearDepth(1);
    1.37 +
    1.38 +    var testCanvas = document.createElement('canvas');
    1.39 +    testCanvas.width = 1;
    1.40 +    testCanvas.height = 2;
    1.41 +    var ctx = testCanvas.getContext("2d");
    1.42 +    ctx.fillStyle = "#ff0000";
    1.43 +    ctx.fillRect(0,0,1,1);
    1.44 +    ctx.fillStyle = "#00ff00";
    1.45 +    ctx.fillRect(0,1,1,1);
    1.46 +    runTest(testCanvas);
    1.47 +}
    1.48 +
    1.49 +// These two declarations need to be global for "shouldBe" to see them
    1.50 +var buf = null;
    1.51 +var idx = 0;
    1.52 +var pixel = [0, 0, 0];
    1.53 +var correctColor = null;
    1.54 +
    1.55 +function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomColor)
    1.56 +{
    1.57 +    debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') +
    1.58 +          ' with flipY=' + flipY);
    1.59 +    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    1.60 +    // Disable any writes to the alpha channel
    1.61 +    gl.colorMask(1, 1, 1, 0);
    1.62 +    var texture = gl.createTexture();
    1.63 +    // Bind the texture to texture unit 0
    1.64 +    gl.bindTexture(gl.TEXTURE_2D, texture);
    1.65 +    // Set up texture parameters
    1.66 +    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
    1.67 +    gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
    1.68 +    // Set up pixel store parameters
    1.69 +    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY);
    1.70 +    gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
    1.71 +    gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
    1.72 +    // Upload the image into the texture
    1.73 +    if (useTexSubImage2D) {
    1.74 +        // Initialize the texture to black first
    1.75 +        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, image.width, image.height, 0,
    1.76 +                      gl.RGBA, gl.UNSIGNED_BYTE, null);
    1.77 +        gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, image);
    1.78 +    } else {
    1.79 +        gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
    1.80 +    }
    1.81 +
    1.82 +    // Point the uniform sampler to texture unit 0
    1.83 +    gl.uniform1i(textureLoc, 0);
    1.84 +    // Draw the triangles
    1.85 +    wtu.drawQuad(gl, [0, 0, 0, 255]);
    1.86 +    // Check a few pixels near the top and bottom and make sure they have
    1.87 +    // the right color.
    1.88 +    debug("Checking lower left corner");
    1.89 +    wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor,
    1.90 +                        "shouldBe " + bottomColor);
    1.91 +    debug("Checking upper left corner");
    1.92 +    wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor,
    1.93 +                        "shouldBe " + topColor);
    1.94 +}
    1.95 +
    1.96 +function runTest(image)
    1.97 +{
    1.98 +    var red = [255, 0, 0];
    1.99 +    var green = [0, 255, 0];
   1.100 +    runOneIteration(image, false, true, red, green);
   1.101 +    runOneIteration(image, false, false, green, red);
   1.102 +    runOneIteration(image, true, true, red, green);
   1.103 +    runOneIteration(image, true, false, green, red);
   1.104 +
   1.105 +    glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors");
   1.106 +    finishTest();
   1.107 +}
   1.108 +
   1.109 +</script>
   1.110 +</head>
   1.111 +<body onload="init()">
   1.112 +<canvas id="example" width="32px" height="32px"></canvas>
   1.113 +<div id="description"></div>
   1.114 +<div id="console"></div>
   1.115 +</body>
   1.116 +</html>
   1.117 +
   1.118 +

mercurial