| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 /* | 
|  | 2 ** Copyright (c) 2013 The Khronos Group Inc. | 
|  | 3 ** | 
|  | 4 ** Permission is hereby granted, free of charge, to any person obtaining a | 
|  | 5 ** copy of this software and/or associated documentation files (the | 
|  | 6 ** "Materials"), to deal in the Materials without restriction, including | 
|  | 7 ** without limitation the rights to use, copy, modify, merge, publish, | 
|  | 8 ** distribute, sublicense, and/or sell copies of the Materials, and to | 
|  | 9 ** permit persons to whom the Materials are furnished to do so, subject to | 
|  | 10 ** the following conditions: | 
|  | 11 ** | 
|  | 12 ** The above copyright notice and this permission notice shall be included | 
|  | 13 ** in all copies or substantial portions of the Materials. | 
|  | 14 ** | 
|  | 15 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | 
|  | 16 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 
|  | 17 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | 
|  | 18 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | 
|  | 19 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | 
|  | 20 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | 
|  | 21 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. | 
|  | 22 */ | 
|  | 23 | 
|  | 24 function generateTest(pixelFormat, pixelType, pathToTestRoot, prologue) { | 
|  | 25     var wtu = WebGLTestUtils; | 
|  | 26     var gl = null; | 
|  | 27     var textureLoc = null; | 
|  | 28     var successfullyParsed = false; | 
|  | 29     var imgCanvas; | 
|  | 30     var red = [255, 0, 0]; | 
|  | 31     var green = [0, 255, 0]; | 
|  | 32 | 
|  | 33     var init = function() | 
|  | 34     { | 
|  | 35         description('Verify texImage2D and texSubImage2D code paths taking SVG i
     mage elements (' + pixelFormat + '/' + pixelType + ')'); | 
|  | 36 | 
|  | 37         gl = wtu.create3DContext("example"); | 
|  | 38 | 
|  | 39         if (!prologue(gl)) { | 
|  | 40             finishTest(); | 
|  | 41             return; | 
|  | 42         } | 
|  | 43 | 
|  | 44         var program = wtu.setupTexturedQuad(gl); | 
|  | 45 | 
|  | 46         gl.clearColor(0,0,0,1); | 
|  | 47         gl.clearDepth(1); | 
|  | 48 | 
|  | 49         textureLoc = gl.getUniformLocation(program, "tex"); | 
|  | 50 | 
|  | 51         wtu.loadTexture(gl, pathToTestRoot + "/resources/red-green.svg", runTest
     ); | 
|  | 52     } | 
|  | 53 | 
|  | 54     function runOneIteration(image, useTexSubImage2D, flipY, topColor, bottomCol
     or) | 
|  | 55     { | 
|  | 56         debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + | 
|  | 57               ' with flipY=' + flipY); | 
|  | 58         gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | 
|  | 59         // Disable any writes to the alpha channel | 
|  | 60         gl.colorMask(1, 1, 1, 0); | 
|  | 61         var texture = gl.createTexture(); | 
|  | 62         // Bind the texture to texture unit 0 | 
|  | 63         gl.bindTexture(gl.TEXTURE_2D, texture); | 
|  | 64         // Set up texture parameters | 
|  | 65         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); | 
|  | 66         gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); | 
|  | 67         // Set up pixel store parameters | 
|  | 68         gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); | 
|  | 69         gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false); | 
|  | 70         gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); | 
|  | 71         // Upload the image into the texture | 
|  | 72         if (useTexSubImage2D) { | 
|  | 73             // Initialize the texture to black first | 
|  | 74             gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], image.width, image.
     height, 0, | 
|  | 75                           gl[pixelFormat], gl[pixelType], null); | 
|  | 76             gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelTy
     pe], image); | 
|  | 77         } else { | 
|  | 78             gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl
     [pixelType], image); | 
|  | 79         } | 
|  | 80 | 
|  | 81         // Point the uniform sampler to texture unit 0 | 
|  | 82         gl.uniform1i(textureLoc, 0); | 
|  | 83         // Draw the triangles | 
|  | 84         wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]); | 
|  | 85         // Check a few pixels near the top and bottom and make sure they have | 
|  | 86         // the right color. | 
|  | 87         debug("Checking lower left corner"); | 
|  | 88         wtu.checkCanvasRect(gl, 4, 4, 2, 2, bottomColor, | 
|  | 89                             "shouldBe " + bottomColor); | 
|  | 90         debug("Checking upper left corner"); | 
|  | 91         wtu.checkCanvasRect(gl, 4, gl.canvas.height - 8, 2, 2, topColor, | 
|  | 92                             "shouldBe " + topColor); | 
|  | 93     } | 
|  | 94 | 
|  | 95     function runTest(image) | 
|  | 96     { | 
|  | 97         runOneIteration(image, false, true, red, green); | 
|  | 98         runOneIteration(image, false, false, green, red); | 
|  | 99         runOneIteration(image, true, true, red, green); | 
|  | 100         runOneIteration(image, true, false, green, red); | 
|  | 101         finishTest(); | 
|  | 102     } | 
|  | 103 | 
|  | 104     return init; | 
|  | 105 } | 
| OLD | NEW | 
|---|