OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <!-- |
| 6 |
| 7 /* |
| 8 ** Copyright (c) 2012 The Khronos Group Inc. |
| 9 ** |
| 10 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 11 ** copy of this software and/or associated documentation files (the |
| 12 ** "Materials"), to deal in the Materials without restriction, including |
| 13 ** without limitation the rights to use, copy, modify, merge, publish, |
| 14 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 15 ** permit persons to whom the Materials are furnished to do so, subject to |
| 16 ** the following conditions: |
| 17 ** |
| 18 ** The above copyright notice and this permission notice shall be included |
| 19 ** in all copies or substantial portions of the Materials. |
| 20 ** |
| 21 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 22 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 23 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 24 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 25 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 26 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 27 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 28 */ |
| 29 |
| 30 --> |
| 31 <link rel="stylesheet" type="text/css" href="../unit.css" /> |
| 32 <script type="application/x-javascript" src="../unit.js"></script> |
| 33 <script type="application/x-javascript" src="../util.js"></script> |
| 34 <script type="application/x-javascript"> |
| 35 |
| 36 Tests.startUnit = function () { |
| 37 var canvas = document.getElementById('gl'); |
| 38 var gl = wrapGLContext(getGLContext(canvas)); |
| 39 return [gl]; |
| 40 } |
| 41 |
| 42 Tests.testReadPixels = function(gl) { |
| 43 // we can't know if this is going to fail because of negative width |
| 44 // or because the buffer size doesn't match the dimensions. |
| 45 assertSomeGLError(gl, "negative width", |
| 46 function(){gl.readPixels(0,0,-1,1, gl.RGBA, gl.UNSIGNED_BYTE, |
| 47 new Uint8Array(4));}); |
| 48 assertSomeGLError(gl, "negative height", |
| 49 function(){gl.readPixels(0,0,1,-1, gl.RGBA, gl.UNSIGNED_BYTE, |
| 50 new Uint8Array(4));}); |
| 51 assertOk("negative x", |
| 52 function(){gl.readPixels(-1,0,1,1, gl.RGBA, gl.UNSIGNED_BYTE, |
| 53 new Uint8Array(4));}); |
| 54 assertOk("negative y", |
| 55 function(){gl.readPixels(0,-1,1,1, gl.RGBA, gl.UNSIGNED_BYTE, |
| 56 new Uint8Array(4));}); |
| 57 assertOk("height > backbuffer height", |
| 58 function(){gl.readPixels(0,0,16,17, gl.RGBA, gl.UNSIGNED_BYTE, |
| 59 new Uint8Array(16*17*4));}); |
| 60 assertOk("width > backbuffer width", |
| 61 function(){gl.readPixels(0,0,17,16, gl.RGBA, gl.UNSIGNED_BYTE, |
| 62 new Uint8Array(17*16*4));}); |
| 63 assertOk("width, height = 0", |
| 64 function(){gl.readPixels(0,0,0,0, gl.RGBA, gl.UNSIGNED_BYTE, |
| 65 new Uint8Array(0));}); |
| 66 // we can't know if this is going to fail because of negative width |
| 67 // or because the buffer size doesn't match the dimensions. |
| 68 assertSomeGLError(gl, "bad format", |
| 69 function(){gl.readPixels(0,0,1,1, gl.FLOAT, gl.UNSIGNED_BYTE, |
| 70 new Uint8Array(4*4));}); |
| 71 // we can't know if this is going to fail because of negative width |
| 72 // or because the buffer size doesn't match the dimensions. |
| 73 assertSomeGLError(gl, "bad type", |
| 74 function(){gl.readPixels(0,0,1,1, gl.ALPHA, gl.FLOAT, |
| 75 new Uint8Array(1*4));}); |
| 76 } |
| 77 |
| 78 Tests.testReadPixelsSOPIMG = function(gl) { |
| 79 var img = document.getElementById("i"); |
| 80 while (!img.complete) {} |
| 81 var tex = gl.createTexture(); |
| 82 gl.bindTexture(gl.TEXTURE_2D, tex); |
| 83 // SOP failure |
| 84 assertThrowNoGLError(gl, "throw because img is from another domain", |
| 85 function(){gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_B
YTE, img);}); |
| 86 gl.bindTexture(gl.TEXTURE_2D, null); |
| 87 assertOk("canvas still origin-clean", |
| 88 function(){gl.readPixels(0,0,1,1, gl.RGBA, gl.UNSIGNED_BYTE, |
| 89 new Uint8Array(4));}); |
| 90 gl.deleteTexture(tex); |
| 91 } |
| 92 Tests.testReadPixelsSOPCanvas = function(gl) { |
| 93 var img = document.getElementById("i"); |
| 94 while (!img.complete) {} |
| 95 var c = document.getElementById("c"); |
| 96 c.getContext("2d").drawImage(img, 0, 0); |
| 97 assertFail("canvas throws because not origin clean", |
| 98 function(){c.getContext("2d").getImageData(0,0,1,1);}); |
| 99 var tex = gl.createTexture(); |
| 100 gl.bindTexture(gl.TEXTURE_2D, tex); |
| 101 // SOP failure |
| 102 assertThrowNoGLError(gl, "throw because canvas is not origin clean", |
| 103 function(){gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_B
YTE, c);}); |
| 104 gl.bindTexture(gl.TEXTURE_2D, null); |
| 105 assertOk("canvas still origin-clean", |
| 106 function(){gl.readPixels(0,0,1,1, gl.RGBA, gl.UNSIGNED_BYTE, |
| 107 new Uint8Array(4));}); |
| 108 gl.deleteTexture(tex); |
| 109 } |
| 110 |
| 111 Tests.endUnit = function(gl) { |
| 112 } |
| 113 |
| 114 </script> |
| 115 </head><body> |
| 116 <canvas id="gl" width="16" height="16"></canvas> |
| 117 <canvas id="c" width="128" height="128"></canvas> |
| 118 <img id="i" src="http://www.opengl.org/img/opengl_logo.jpg"> |
| 119 </body></html> |
OLD | NEW |