content/canvas/test/webgl-conformance/conformance/textures/copy-tex-image-and-sub-image-2d.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 11 <script src="../../resources/js-test-pre.js"></script>
michael@0 12 <script src="../resources/webgl-test.js"></script>
michael@0 13 <script src="../resources/webgl-test-utils.js"></script>
michael@0 14
michael@0 15 <script>
michael@0 16 var successfullyParsed = false;
michael@0 17
michael@0 18 function init()
michael@0 19 {
michael@0 20 if (window.initNonKhronosFramework) {
michael@0 21 window.initNonKhronosFramework(true);
michael@0 22 }
michael@0 23
michael@0 24 description('Verify copyTexImage2D and copyTexSubImage2D');
michael@0 25
michael@0 26 runTest();
michael@0 27 }
michael@0 28
michael@0 29 var gl = null;
michael@0 30 var wtu = WebGLTestUtils;
michael@0 31
michael@0 32 function runTestIteration(antialias)
michael@0 33 {
michael@0 34 var canvas = document.getElementById(
michael@0 35 antialias ? "antialiasOn" : "antialiasOff");
michael@0 36 var attribs = antialias ? { antialias: false } : undefined;
michael@0 37 gl = wtu.create3DContext(canvas, attribs);
michael@0 38 var program = wtu.setupTexturedQuad(gl);
michael@0 39 var textureLoc = gl.getUniformLocation(program, "tex");
michael@0 40 glErrorShouldBe(gl, gl.NO_ERROR, "During Initialization");
michael@0 41
michael@0 42 gl.colorMask(1, 1, 1, 1);
michael@0 43 gl.disable(gl.BLEND);
michael@0 44 debug('Testing copyTexImage2D');
michael@0 45
michael@0 46 // Red canvas
michael@0 47 gl.clearColor(1, 0, 0, 1);
michael@0 48 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
michael@0 49
michael@0 50 var texture = gl.createTexture();
michael@0 51 // Bind the texture to texture unit 0
michael@0 52 gl.bindTexture(gl.TEXTURE_2D, texture);
michael@0 53 // Set up texture
michael@0 54 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
michael@0 55 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
michael@0 56 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
michael@0 57 gl.uniform1i(textureLoc, 0);
michael@0 58
michael@0 59 var colors = [
michael@0 60 [1, 0, 0, 1],
michael@0 61 [0, 1, 0, 1],
michael@0 62 [0, 0, 1, 1],
michael@0 63 [0.5, 0.5, 0.5, 0.5],
michael@0 64 ];
michael@0 65 var count = 0;
michael@0 66 for (var yy = -2; yy <= 2; ++yy) {
michael@0 67 for (var xx = -2; xx <= 2; ++xx) {
michael@0 68 for (var ii = 0; ii < 2; ++ii) {
michael@0 69 var texColor = colors[count];
michael@0 70 var clearColor = colors[(count + 1) % colors.length];
michael@0 71 // clear to some color
michael@0 72 gl.clearColor(texColor[0], texColor[1], texColor[2], texColor[3]);
michael@0 73 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
michael@0 74
michael@0 75 // copy that color to the texture.
michael@0 76 switch (ii) {
michael@0 77 case 0:
michael@0 78 gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, xx, yy, 2, 2, 0);
michael@0 79 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 80 "using copyTexImage2D: x =" + xx + ", y = " + yy);
michael@0 81 break;
michael@0 82 case 1:
michael@0 83 gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, xx, yy, 2, 2);
michael@0 84 glErrorShouldBe(gl, gl.NO_ERROR,
michael@0 85 "using copyTexSubImage2D: x =" + xx + ", y = " + yy);
michael@0 86 break;
michael@0 87 }
michael@0 88
michael@0 89 // clear to some other color.
michael@0 90 gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
michael@0 91 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
michael@0 92
michael@0 93 // Draw the triangles
michael@0 94 wtu.drawQuad(gl);
michael@0 95
michael@0 96 // check the rendering results
michael@0 97 for (var iy = 0; iy < 2; ++iy) {
michael@0 98 for (var ix = 0; ix < 2; ++ix) {
michael@0 99 var x = xx + ix;
michael@0 100 var y = yy + iy;
michael@0 101 var expectedColor = (x < 0 || y < 0 || x >= 2 || y >= 2) ?
michael@0 102 [0,0,0,0] :
michael@0 103 [Math.floor(255 * texColor[0]),
michael@0 104 Math.floor(255 * texColor[1]),
michael@0 105 Math.floor(255 * texColor[2]),
michael@0 106 Math.floor(255 * texColor[3])];
michael@0 107 wtu.checkCanvasRect(gl, ix, iy, 1, 1, expectedColor,
michael@0 108 "" + ix + ", " + iy + " should render " + expectedColor + " (+/-1)", 1);
michael@0 109 }
michael@0 110 }
michael@0 111 count = (count + 1) % colors.length;
michael@0 112 }
michael@0 113 }
michael@0 114 }
michael@0 115
michael@0 116 debug("");
michael@0 117 }
michael@0 118
michael@0 119 function runTest(antialias)
michael@0 120 {
michael@0 121 debug("Testing with antialias on");
michael@0 122 runTestIteration(true);
michael@0 123 debug("Testing with antialias off");
michael@0 124 runTestIteration(false);
michael@0 125
michael@0 126 finishTest();
michael@0 127 }
michael@0 128 </script>
michael@0 129 </head>
michael@0 130 <body onload="init()">
michael@0 131 <canvas id="antialiasOn" width="2px" height="2px"></canvas>
michael@0 132 <canvas id="antialiasOff" width="2px" height="2px"></canvas>
michael@0 133 <div id="description"></div>
michael@0 134 <div id="console"></div>
michael@0 135 </body>
michael@0 136 </html>

mercurial