OLD | NEW |
(Empty) | |
| 1 /* |
| 2 ** Copyright (c) 2012 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, prologue) { |
| 25 var wtu = WebGLTestUtils; |
| 26 var gl = null; |
| 27 var textureLoc = null; |
| 28 var successfullyParsed = false; |
| 29 var imageData = null; |
| 30 |
| 31 var init = function() |
| 32 { |
| 33 description('Verify texImage2D and texSubImage2D code paths taking Image
Data (' + pixelFormat + '/' + pixelType + ')'); |
| 34 |
| 35 gl = wtu.create3DContext("example"); |
| 36 |
| 37 if (!prologue(gl)) { |
| 38 finishTest(); |
| 39 return; |
| 40 } |
| 41 |
| 42 var program = wtu.setupTexturedQuad(gl); |
| 43 gl.clearColor(0,0,0,1); |
| 44 gl.clearDepth(1); |
| 45 gl.disable(gl.BLEND); |
| 46 |
| 47 textureLoc = gl.getUniformLocation(program, "tex"); |
| 48 |
| 49 var canvas2d = document.getElementById("texcanvas"); |
| 50 var context2d = canvas2d.getContext("2d"); |
| 51 imageData = context2d.createImageData(1, 2); |
| 52 var data = imageData.data; |
| 53 data[0] = 255; |
| 54 data[1] = 0; |
| 55 data[2] = 0; |
| 56 data[3] = 255; |
| 57 data[4] = 0; |
| 58 data[5] = 255; |
| 59 data[6] = 0; |
| 60 data[7] = 0; |
| 61 |
| 62 runTest(); |
| 63 } |
| 64 |
| 65 function runOneIteration(useTexSubImage2D, flipY, premultiplyAlpha, topColor
, bottomColor) |
| 66 { |
| 67 debug('Testing ' + (useTexSubImage2D ? 'texSubImage2D' : 'texImage2D') + |
| 68 ' with flipY=' + flipY + ' and premultiplyAlpha=' + premultiplyAlp
ha); |
| 69 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 70 // Enable writes to the RGBA channels |
| 71 gl.colorMask(1, 1, 1, 0); |
| 72 var texture = gl.createTexture(); |
| 73 // Bind the texture to texture unit 0 |
| 74 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 75 // Set up texture parameters |
| 76 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
| 77 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
| 78 // Set up pixel store parameters |
| 79 gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, flipY); |
| 80 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, premultiplyAlpha); |
| 81 // Upload the image into the texture |
| 82 if (useTexSubImage2D) { |
| 83 // Initialize the texture to black first |
| 84 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], 1, 2, 0, |
| 85 gl[pixelFormat], gl[pixelType], null); |
| 86 gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl[pixelFormat], gl[pixelTy
pe], imageData); |
| 87 } else { |
| 88 gl.texImage2D(gl.TEXTURE_2D, 0, gl[pixelFormat], gl[pixelFormat], gl
[pixelType], imageData); |
| 89 } |
| 90 |
| 91 // Point the uniform sampler to texture unit 0 |
| 92 gl.uniform1i(textureLoc, 0); |
| 93 // Draw the triangles |
| 94 wtu.clearAndDrawUnitQuad(gl, [0, 0, 0, 255]); |
| 95 |
| 96 // Check the top pixel and bottom pixel and make sure they have |
| 97 // the right color. |
| 98 debug("Checking bottom pixel"); |
| 99 wtu.checkCanvasRect(gl, 0, 0, 1, 1, bottomColor, "shouldBe " + bottomCol
or); |
| 100 debug("Checking top pixel"); |
| 101 wtu.checkCanvasRect(gl, 0, 1, 1, 1, topColor, "shouldBe " + topColor); |
| 102 } |
| 103 |
| 104 function runTest() |
| 105 { |
| 106 var red = [255, 0, 0, 255]; |
| 107 var green = [0, 255, 0, 255]; |
| 108 var redPremultiplyAlpha = [255, 0, 0, 255]; |
| 109 var greenPremultiplyAlpha = [0, 0, 0, 255]; |
| 110 |
| 111 runOneIteration(false, true, false, |
| 112 red, green); |
| 113 runOneIteration(false, false, false, |
| 114 green, red); |
| 115 runOneIteration(false, true, true, |
| 116 redPremultiplyAlpha, greenPremultiplyAlpha); |
| 117 runOneIteration(false, false, true, |
| 118 greenPremultiplyAlpha, redPremultiplyAlpha); |
| 119 runOneIteration(true, true, false, |
| 120 red, green); |
| 121 runOneIteration(true, false, false, |
| 122 green, red); |
| 123 runOneIteration(true, true, true, |
| 124 redPremultiplyAlpha, greenPremultiplyAlpha); |
| 125 runOneIteration(true, false, true, |
| 126 greenPremultiplyAlpha, redPremultiplyAlpha); |
| 127 |
| 128 glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors"); |
| 129 finishTest(); |
| 130 } |
| 131 |
| 132 return init; |
| 133 } |
OLD | NEW |