OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 31 <meta charset="utf-8"> |
| 32 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 33 <script src="../../resources/js-test-pre.js"></script> |
| 34 <script src="../resources/webgl-test.js"></script> |
| 35 <script src="../resources/webgl-test-utils.js"></script> |
| 36 |
| 37 <script> |
| 38 var successfullyParsed = false; |
| 39 |
| 40 function init() |
| 41 { |
| 42 if (window.initNonKhronosFramework) { |
| 43 window.initNonKhronosFramework(true); |
| 44 } |
| 45 |
| 46 description('Verify copyTexImage2D and copyTexSubImage2D'); |
| 47 |
| 48 runTest(); |
| 49 } |
| 50 |
| 51 var gl = null; |
| 52 var wtu = WebGLTestUtils; |
| 53 |
| 54 function runTestIteration(antialias) |
| 55 { |
| 56 var canvas = document.getElementById( |
| 57 antialias ? "antialiasOn" : "antialiasOff"); |
| 58 var attribs = antialias ? { antialias: false } : undefined; |
| 59 gl = wtu.create3DContext(canvas, attribs); |
| 60 var program = wtu.setupTexturedQuad(gl); |
| 61 var textureLoc = gl.getUniformLocation(program, "tex"); |
| 62 glErrorShouldBe(gl, gl.NO_ERROR, "During Initialization"); |
| 63 |
| 64 gl.colorMask(1, 1, 1, 1); |
| 65 gl.disable(gl.BLEND); |
| 66 debug('Testing copyTexImage2D'); |
| 67 |
| 68 // Red canvas |
| 69 gl.clearColor(1, 0, 0, 1); |
| 70 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 71 |
| 72 var texture = gl.createTexture(); |
| 73 // Bind the texture to texture unit 0 |
| 74 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 75 // Set up texture |
| 76 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE,
null); |
| 77 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 78 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 79 gl.uniform1i(textureLoc, 0); |
| 80 |
| 81 var colors = [ |
| 82 [1, 0, 0, 1], |
| 83 [0, 1, 0, 1], |
| 84 [0, 0, 1, 1], |
| 85 [0.5, 0.5, 0.5, 0.5], |
| 86 ]; |
| 87 var count = 0; |
| 88 for (var yy = -2; yy <= 2; ++yy) { |
| 89 for (var xx = -2; xx <= 2; ++xx) { |
| 90 for (var ii = 0; ii < 2; ++ii) { |
| 91 var texColor = colors[count]; |
| 92 var clearColor = colors[(count + 1) % colors.length]; |
| 93 // clear to some color |
| 94 gl.clearColor(texColor[0], texColor[1], texColor[2], texColor[3]); |
| 95 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 96 |
| 97 // copy that color to the texture. |
| 98 switch (ii) { |
| 99 case 0: |
| 100 gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, xx, yy, 2, 2, 0); |
| 101 glErrorShouldBe(gl, gl.NO_ERROR, |
| 102 "using copyTexImage2D: x =" + xx + ", y = " + yy); |
| 103 break; |
| 104 case 1: |
| 105 gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, xx, yy, 2, 2); |
| 106 glErrorShouldBe(gl, gl.NO_ERROR, |
| 107 "using copyTexSubImage2D: x =" + xx + ", y = " + yy); |
| 108 break; |
| 109 } |
| 110 |
| 111 // clear to some other color. |
| 112 gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[
3]); |
| 113 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 114 |
| 115 // Draw the triangles |
| 116 wtu.drawQuad(gl); |
| 117 |
| 118 // check the rendering results |
| 119 for (var iy = 0; iy < 2; ++iy) { |
| 120 for (var ix = 0; ix < 2; ++ix) { |
| 121 var x = xx + ix; |
| 122 var y = yy + iy; |
| 123 var expectedColor = (x < 0 || y < 0 || x >= 2 || y >= 2) ? |
| 124 [0,0,0,0] : |
| 125 [Math.floor(255 * texColor[0]), |
| 126 Math.floor(255 * texColor[1]), |
| 127 Math.floor(255 * texColor[2]), |
| 128 Math.floor(255 * texColor[3])]; |
| 129 wtu.checkCanvasRect(gl, ix, iy, 1, 1, expectedColor, |
| 130 "" + ix + ", " + iy + " should render " + expectedColor + " (+
/-1)", 1); |
| 131 } |
| 132 } |
| 133 count = (count + 1) % colors.length; |
| 134 } |
| 135 } |
| 136 } |
| 137 |
| 138 debug(""); |
| 139 } |
| 140 |
| 141 function runTest(antialias) |
| 142 { |
| 143 debug("Testing with antialias on"); |
| 144 runTestIteration(true); |
| 145 debug("Testing with antialias off"); |
| 146 runTestIteration(false); |
| 147 |
| 148 finishTest(); |
| 149 } |
| 150 </script> |
| 151 </head> |
| 152 <body onload="init()"> |
| 153 <canvas id="antialiasOn" width="2px" height="2px"></canvas> |
| 154 <canvas id="antialiasOff" width="2px" height="2px"></canvas> |
| 155 <div id="description"></div> |
| 156 <div id="console"></div> |
| 157 </body> |
| 158 </html> |
OLD | NEW |