OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html><head> |
| 3 <meta charset="utf-8"> |
| 4 <!-- |
| 5 Tests for the OpenGL ES 2.0 HTML Canvas context |
| 6 |
| 7 Copyright (C) 2011 Ilmari Heikkinen <ilmari.heikkinen@gmail.com> |
| 8 |
| 9 Permission is hereby granted, free of charge, to any person |
| 10 obtaining a copy of this software and associated documentation |
| 11 files (the "Software"), to deal in the Software without |
| 12 restriction, including without limitation the rights to use, |
| 13 copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 copies of the Software, and to permit persons to whom the |
| 15 Software is furnished to do so, subject to the following |
| 16 conditions: |
| 17 |
| 18 The above copyright notice and this permission notice shall be |
| 19 included in all copies or substantial portions of the Software. |
| 20 |
| 21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 23 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 24 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 25 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 27 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 28 OTHER DEALINGS IN THE SOFTWARE. |
| 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(canvas.getContext(GL_CONTEXT_ID)); |
| 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 |