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.autorun = false; |
| 37 // Tests.message = "Caution: May crash your browser"; |
| 38 |
| 39 var verts = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0]; |
| 40 var normals = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0]; |
| 41 var texcoords = [0.0,0.0, 1.0,0.0, 0.0,1.0]; |
| 42 var indices = [60000000,1,2] |
| 43 |
| 44 Tests.startUnit = function () { |
| 45 var canvas = document.getElementById('gl'); |
| 46 var gl = wrapGLContext(canvas.getContext(GL_CONTEXT_ID)); |
| 47 var prog = new Shader(gl, 'vert', 'frag'); |
| 48 prog.use(); |
| 49 var sh = prog.shader.program; |
| 50 var v = gl.getAttribLocation(sh, 'Vertex'); |
| 51 var n = gl.getAttribLocation(sh, 'Normal'); |
| 52 var t = gl.getAttribLocation(sh, 'Tex'); |
| 53 return [gl,prog,v,n,t]; |
| 54 } |
| 55 |
| 56 Tests.setup = function(gl, prog, v,n,t) { |
| 57 assert(0 == gl.getError()); |
| 58 return [gl, prog, v,n,t]; |
| 59 } |
| 60 Tests.teardown = function(gl, prog, v,n,t) { |
| 61 gl.disableVertexAttribArray(v); |
| 62 gl.disableVertexAttribArray(n); |
| 63 gl.disableVertexAttribArray(t); |
| 64 } |
| 65 |
| 66 Tests.endUnit = function(gl, prog, v,n,t) { |
| 67 prog.destroy(); |
| 68 } |
| 69 |
| 70 |
| 71 Tests.testDrawElementsVBO = function(gl, prog, v,n,t) { |
| 72 var vbo = new VBO(gl, |
| 73 {size:3, data:Quad.vertices}, |
| 74 {elements:true, data:[0,1,2,2000, 40802, 5887992]}); |
| 75 assertFail(function(){vbo.draw(v);}); |
| 76 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2)
;}); |
| 77 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);}
); |
| 78 assertOk(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0);}); |
| 79 assertFail(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1);}
); |
| 80 assertFail(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2)
;}); |
| 81 vbo.destroy(); |
| 82 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 83 } |
| 84 |
| 85 Tests.testDrawElementsVBOByte = function(gl, prog, v,n,t) { |
| 86 var vbo = new VBO(gl, |
| 87 {size:3, data:Quad.vertices}, |
| 88 {elements:true, type:gl.UNSIGNED_BYTE, data:[0,1,2,2000,
40802, 5887992]}); |
| 89 assertFail(function(){vbo.draw(v);}); |
| 90 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_BYTE, 5);})
; |
| 91 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);})
; |
| 92 assertOk(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0);}); |
| 93 assertFail(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_BYTE, 1);})
; |
| 94 vbo.destroy(); |
| 95 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 96 } |
| 97 |
| 98 Tests.testDrawElementsVBOMulti = function(gl, prog, v,n,t) { |
| 99 // creates VBOs for the quad arrays, binds them with |
| 100 // vertexAttribPointer and calls drawElements |
| 101 // The quad has 6 vertices |
| 102 var vbo = new VBO(gl, |
| 103 {size:3, data:Quad.vertices}, |
| 104 {size:3, data:Quad.normals}, |
| 105 {size:2, data:Quad.texcoords}, |
| 106 {elements:true, data:[0,1,2,6,2000, 256]}); |
| 107 assertFail(function(){vbo.draw(v, n, t);}); |
| 108 gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0); |
| 109 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2)
;}); |
| 110 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);}
); |
| 111 assertOk(function(){gl.drawElements(gl.TRIANGLES, 2, gl.UNSIGNED_SHORT, 0);}); |
| 112 assertOk(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0);}); |
| 113 assertFail(function(){gl.drawElements(gl.TRIANGLES, 4, gl.UNSIGNED_SHORT, 0);}
); |
| 114 assertFail(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 1*2)
;}); |
| 115 assertFail(function(){gl.drawElements(gl.TRIANGLES, 2, gl.UNSIGNED_SHORT, 2*2)
;}); |
| 116 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 3*2)
;}); |
| 117 assertFail(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2)
;}); |
| 118 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2)
;}); |
| 119 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1);}
); |
| 120 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2)
;}); |
| 121 gl.bindBuffer(gl.ARRAY_BUFFER, vbo.vbos[1]); |
| 122 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 123 gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0); |
| 124 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2)
;}); |
| 125 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);}
); |
| 126 assertOk(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_SHORT, 0);}); |
| 127 assertFail(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2)
;}); |
| 128 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2)
;}); |
| 129 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1);}
); |
| 130 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2)
;}); |
| 131 vbo.destroy(); |
| 132 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 133 } |
| 134 |
| 135 Tests.testDrawElementsVBOMultiByte = function(gl, prog, v,n,t) { |
| 136 // creates VBOs for the quad arrays, binds them with |
| 137 // vertexAttribPointer and calls drawElements |
| 138 // The quad has 6 vertices |
| 139 var vbo = new VBO(gl, |
| 140 {size:3, data:Quad.vertices}, |
| 141 {size:3, data:Quad.normals}, |
| 142 {size:2, data:Quad.texcoords}, |
| 143 {elements:true, type:gl.UNSIGNED_BYTE, data:[0,1,2,6,2000, 2
56]}); |
| 144 assertFail(function(){vbo.draw(v, n, t);}); |
| 145 gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0); |
| 146 assertFail(function(){gl.drawElements(gl.TRIANGLES, 4, gl.UNSIGNED_BYTE, -1);}
); |
| 147 assertFail(function(){gl.drawElements(gl.TRIANGLES, -1, gl.UNSIGNED_BYTE, 0);}
); |
| 148 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_BYTE, 5);}); |
| 149 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);})
; |
| 150 assertOk(function(){gl.drawElements(gl.TRIANGLES, 2, gl.UNSIGNED_BYTE, 0);}); |
| 151 assertOk(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0);}); |
| 152 assertFail(function(){gl.drawElements(gl.TRIANGLES, 4, gl.UNSIGNED_BYTE, 0);})
; |
| 153 assertFail(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 1);})
; |
| 154 assertFail(function(){gl.drawElements(gl.TRIANGLES, 2, gl.UNSIGNED_BYTE, 2);})
; |
| 155 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_BYTE, 3);})
; |
| 156 assertFail(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_BYTE, 1);})
; |
| 157 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 1);})
; |
| 158 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_BYTE, 6);})
; |
| 159 gl.bindBuffer(gl.ARRAY_BUFFER, vbo.vbos[1]); |
| 160 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 161 gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0); |
| 162 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_BYTE, 5);}); |
| 163 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0);})
; |
| 164 assertOk(function(){gl.drawElements(gl.TRIANGLES, 3, gl.UNSIGNED_BYTE, 0);}); |
| 165 assertFail(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_BYTE, 1);})
; |
| 166 assertFail(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 1);})
; |
| 167 assertFail(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_BYTE, 6);})
; |
| 168 vbo.destroy(); |
| 169 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 170 } |
| 171 |
| 172 Tests.testSharedBuffers = function(gl, prog, v,n,t) { |
| 173 var vbo = gl.createBuffer(); |
| 174 var vertsArr = new Uint16Array([0,1,3,3,4,5,6,7,8]); |
| 175 gl.bindBuffer(gl.ARRAY_BUFFER, vbo); |
| 176 gl.bufferData(gl.ARRAY_BUFFER, vertsArr, gl.STATIC_DRAW); |
| 177 assertFail(function(){gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, vbo)}); |
| 178 gl.deleteBuffer(vbo); |
| 179 } |
| 180 |
| 181 </script> |
| 182 <script id="vert" type="x-shader/x-vertex"> |
| 183 attribute vec3 Vertex; |
| 184 attribute vec3 Normal; |
| 185 attribute vec2 Tex; |
| 186 |
| 187 varying vec4 texCoord0; |
| 188 void main() |
| 189 { |
| 190 gl_Position = vec4(Vertex * Normal, 1.0); |
| 191 texCoord0 = vec4(Tex,0.0,0.0) + gl_Position; |
| 192 } |
| 193 </script> |
| 194 <script id="frag" type="x-shader/x-fragment"> |
| 195 precision mediump float; |
| 196 |
| 197 varying vec4 texCoord0; |
| 198 void main() |
| 199 { |
| 200 vec4 c = texCoord0; |
| 201 gl_FragColor = c; |
| 202 } |
| 203 </script> |
| 204 |
| 205 |
| 206 <style>canvas{ position:absolute; }</style> |
| 207 </head><body> |
| 208 <canvas id="gl" width="1" height="1"></canvas> |
| 209 </body></html> |
OLD | NEW |