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 var verts = [0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0]; |
| 37 var normals = [0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0]; |
| 38 var texcoords = [0.0,0.0, 1.0,0.0, 0.0,1.0]; |
| 39 |
| 40 var vertsA = new Float32Array(verts); |
| 41 var normalsA = new Float32Array(normals); |
| 42 var texcoordsA = new Float32Array(texcoords); |
| 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 v = prog.attrib('Vertex'); |
| 50 var n = prog.attrib('Normal'); |
| 51 var t = prog.attrib('Tex'); |
| 52 return [gl,prog,v,n,t]; |
| 53 } |
| 54 |
| 55 Tests.setup = function(gl, prog, v,n,t) { |
| 56 return [gl, prog, v,n,t]; |
| 57 } |
| 58 Tests.teardown = function(gl, prog, v,n,t) { |
| 59 gl.disableVertexAttribArray(v); |
| 60 gl.disableVertexAttribArray(n); |
| 61 gl.disableVertexAttribArray(t); |
| 62 } |
| 63 |
| 64 Tests.endUnit = function(gl, prog, v,n,t) { |
| 65 prog.destroy(); |
| 66 } |
| 67 |
| 68 Tests.testDrawArraysEmpty = function(gl, prog, v,n,t) { |
| 69 var b = gl.createBuffer(); |
| 70 gl.bindBuffer(gl.ARRAY_BUFFER, b); |
| 71 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([]), gl.STATIC_DRAW); |
| 72 assertOk(function(){gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0);}) |
| 73 gl.enableVertexAttribArray(v); |
| 74 assertGLError(gl, gl.INVALID_OPERATION, "zero size array", |
| 75 function(){gl.drawArrays(gl.TRIANGLES, 0, 1);}); |
| 76 gl.deleteBuffer(b); |
| 77 } |
| 78 |
| 79 Tests.testDrawArraysOutOfBounds = function(gl, prog, v,n,t) { |
| 80 var b = gl.createBuffer(); |
| 81 gl.bindBuffer(gl.ARRAY_BUFFER, b); |
| 82 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([]), gl.STATIC_DRAW); |
| 83 assertOk(function(){gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0);}); |
| 84 gl.enableVertexAttribArray(v); |
| 85 assertGLError(gl, gl.INVALID_OPERATION, "zero size array", |
| 86 function(){gl.drawArrays(gl.TRIANGLES, 0, 1);}); |
| 87 assertGLError(gl, gl.INVALID_OPERATION, "zero size array 10000", |
| 88 function(){gl.drawArrays(gl.TRIANGLES, 0, 10000);}); |
| 89 assertGLError(gl, gl.INVALID_OPERATION, "zero size array 10000000000000", |
| 90 function(){gl.drawArrays(gl.TRIANGLES, 0, 10000000000000);}); |
| 91 assertGLError(gl, gl.INVALID_OPERATION, "zero size array fraction", |
| 92 function(){gl.drawArrays(gl.TRIANGLES, 0, 1.6);}); |
| 93 assertGLError(gl, gl.INVALID_VALUE, "negative offset", |
| 94 function(){gl.drawArrays(gl.TRIANGLES, 0, -1);}); |
| 95 assertGLError(gl, gl.INVALID_OPERATION, "count out of range", |
| 96 function(){gl.drawArrays(gl.TRIANGLES, 0, 1);}); |
| 97 assertGLError(gl, gl.INVALID_VALUE, "negative count", |
| 98 function(){gl.drawArrays(gl.TRIANGLES, 0, -1);}); |
| 99 assertGLError(gl, gl.INVALID_VALUE, "positive count, negative offset", |
| 100 function(){gl.drawArrays(gl.TRIANGLES, -1, 1);}); |
| 101 assertGLError(gl, gl.INVALID_VALUE, "negative count, positive offset", |
| 102 function(){gl.drawArrays(gl.TRIANGLES, 1, -1);}); |
| 103 gl.deleteBuffer(b); |
| 104 } |
| 105 |
| 106 |
| 107 Tests.testDrawArraysWithDataOutOfBounds = function(gl, prog, v,n,t) { |
| 108 var b = gl.createBuffer(); |
| 109 gl.bindBuffer(gl.ARRAY_BUFFER, b); |
| 110 gl.bufferData(gl.ARRAY_BUFFER, vertsA, gl.STATIC_DRAW); |
| 111 gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0); |
| 112 gl.enableVertexAttribArray(v); |
| 113 assertGLError(gl, gl.INVALID_OPERATION, "3 element array", |
| 114 function(){gl.drawArrays(gl.TRIANGLES, 3, 2);}); |
| 115 assertGLError(gl, gl.INVALID_OPERATION, "3 element array 10000", |
| 116 function(){gl.drawArrays(gl.TRIANGLES, 0, 10000);}); |
| 117 assertGLError(gl, gl.INVALID_OPERATION, "3 element array 10000000000000", |
| 118 function(){gl.drawArrays(gl.TRIANGLES, 0, 10000000000000);}); |
| 119 assertGLError(gl, gl.INVALID_OPERATION, "fractional count", |
| 120 function(){gl.drawArrays(gl.TRIANGLES, 3, 1.6);}); |
| 121 assertGLError(gl, gl.INVALID_VALUE, "negative offset", |
| 122 function(){gl.drawArrays(gl.TRIANGLES, 0, -1);}); |
| 123 assertGLError(gl, gl.INVALID_OPERATION, "count out of range", |
| 124 function(){gl.drawArrays(gl.TRIANGLES, 0, 4);}); |
| 125 assertGLError(gl, gl.INVALID_VALUE, "negative count", |
| 126 function(){gl.drawArrays(gl.TRIANGLES, 0, -1);}); |
| 127 assertGLError(gl, gl.INVALID_VALUE, "positive count, negative offset", |
| 128 function(){gl.drawArrays(gl.TRIANGLES, -1, 2);}); |
| 129 assertGLError(gl, gl.INVALID_VALUE, "negative count, positive offset", |
| 130 function(){gl.drawArrays(gl.TRIANGLES, 1, -1);}); |
| 131 gl.deleteBuffer(b); |
| 132 } |
| 133 |
| 134 Tests.testDrawArraysMultiOutOfBounds = function(gl, prog, v,n,t) { |
| 135 var bs = []; |
| 136 bs.push(gl.createBuffer()); |
| 137 gl.bindBuffer(gl.ARRAY_BUFFER, bs[bs.length-1]); |
| 138 gl.bufferData(gl.ARRAY_BUFFER, vertsA, gl.STATIC_DRAW); |
| 139 gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0); |
| 140 bs.push(gl.createBuffer()); |
| 141 gl.bindBuffer(gl.ARRAY_BUFFER, bs[bs.length-1]); |
| 142 gl.bufferData(gl.ARRAY_BUFFER, normalsA, gl.STATIC_DRAW); |
| 143 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 144 bs.push(gl.createBuffer()); |
| 145 gl.bindBuffer(gl.ARRAY_BUFFER, bs[bs.length-1]); |
| 146 gl.bufferData(gl.ARRAY_BUFFER, texcoordsA, gl.STATIC_DRAW); |
| 147 gl.vertexAttribPointer(t, 2, gl.FLOAT, false, 0, 0); |
| 148 gl.enableVertexAttribArray(v); |
| 149 gl.enableVertexAttribArray(n); |
| 150 gl.enableVertexAttribArray(t); |
| 151 assertGLError(gl, gl.INVALID_OPERATION, "multi array 1", |
| 152 function(){gl.drawArrays(gl.TRIANGLES, 3, 2);}); |
| 153 bs.push(gl.createBuffer()); |
| 154 gl.bindBuffer(gl.ARRAY_BUFFER, bs[bs.length-1]); |
| 155 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verts.concat(verts)), gl.STATI
C_DRAW); |
| 156 bs.push(gl.createBuffer()); |
| 157 gl.bindBuffer(gl.ARRAY_BUFFER, bs[bs.length-1]); |
| 158 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(texcoords.concat(texcoords)),
gl.STATIC_DRAW); |
| 159 gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0); |
| 160 gl.bindBuffer(gl.ARRAY_BUFFER, bs[1]); |
| 161 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 162 gl.bindBuffer(gl.ARRAY_BUFFER, bs[2]); |
| 163 gl.vertexAttribPointer(t, 2, gl.FLOAT, false, 0, 0); |
| 164 gl.enableVertexAttribArray(v); |
| 165 gl.enableVertexAttribArray(n); |
| 166 gl.enableVertexAttribArray(t); |
| 167 assertGLError(gl, gl.INVALID_OPERATION, "multi array 2", |
| 168 function(){gl.drawArrays(gl.TRIANGLES, 3, 2);}); |
| 169 assertGLError(gl, gl.INVALID_OPERATION, "multi array 3", |
| 170 function(){gl.drawArrays(gl.TRIANGLES, 4, 2);}); |
| 171 gl.bindBuffer(gl.ARRAY_BUFFER, bs[0]); |
| 172 gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0); |
| 173 gl.bindBuffer(gl.ARRAY_BUFFER, bs[3]); |
| 174 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 175 gl.bindBuffer(gl.ARRAY_BUFFER, bs[2]); |
| 176 gl.vertexAttribPointer(t, 2, gl.FLOAT, false, 0, 0); |
| 177 gl.enableVertexAttribArray(v); |
| 178 gl.enableVertexAttribArray(n); |
| 179 gl.enableVertexAttribArray(t); |
| 180 assertGLError(gl, gl.INVALID_OPERATION, "multi array 4", |
| 181 function(){gl.drawArrays(gl.TRIANGLES, 3, 2);}); |
| 182 assertGLError(gl, gl.INVALID_OPERATION, "multi array 5", |
| 183 function(){gl.drawArrays(gl.TRIANGLES, 4, 2);}); |
| 184 gl.bindBuffer(gl.ARRAY_BUFFER, bs[0]); |
| 185 gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0); |
| 186 gl.bindBuffer(gl.ARRAY_BUFFER, bs[1]); |
| 187 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 188 gl.bindBuffer(gl.ARRAY_BUFFER, bs[4]); |
| 189 gl.vertexAttribPointer(t, 2, gl.FLOAT, false, 0, 0); |
| 190 gl.enableVertexAttribArray(v); |
| 191 gl.enableVertexAttribArray(n); |
| 192 gl.enableVertexAttribArray(t); |
| 193 assertGLError(gl, gl.INVALID_OPERATION, "multi array 6", |
| 194 function(){gl.drawArrays(gl.TRIANGLES, 3, 2);}); |
| 195 assertGLError(gl, gl.INVALID_OPERATION, "multi array 7", |
| 196 function(){gl.drawArrays(gl.TRIANGLES, 3, 2);}); |
| 197 gl.bindBuffer(gl.ARRAY_BUFFER, bs[3]); |
| 198 gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0); |
| 199 gl.bindBuffer(gl.ARRAY_BUFFER, bs[3]); |
| 200 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 201 gl.bindBuffer(gl.ARRAY_BUFFER, bs[2]); |
| 202 gl.vertexAttribPointer(t, 2, gl.FLOAT, false, 0, 0); |
| 203 gl.enableVertexAttribArray(v); |
| 204 gl.enableVertexAttribArray(n); |
| 205 gl.enableVertexAttribArray(t); |
| 206 assertGLError(gl, gl.INVALID_OPERATION, "multi array 8", |
| 207 function(){gl.drawArrays(gl.TRIANGLES, 4, 1);}); |
| 208 assertGLError(gl, gl.INVALID_VALUE, "negative count", |
| 209 function(){gl.drawArrays(gl.TRIANGLES, -1, 2);}); |
| 210 assertGLError(gl, gl.INVALID_OPERATION, "zero count???", |
| 211 function(){gl.drawArrays(gl.TRIANGLES, 0, 4);}); |
| 212 assertGLError(gl, gl.INVALID_OPERATION, "multi array 9", |
| 213 function(){gl.drawArrays(gl.TRIANGLES, 1, 4);}); |
| 214 bs.forEach(function(b){ gl.deleteBuffer(b) }); |
| 215 } |
| 216 |
| 217 |
| 218 Tests.testDrawArraysVBOOutOfBounds = function(gl, prog, v,n,t) { |
| 219 var vbo = new VBO(gl, {size:3, data:Quad.vertices}); |
| 220 vbo.use(v); |
| 221 assertGLError(gl, gl.INVALID_OPERATION, "1", |
| 222 function(){gl.drawArrays(gl.TRIANGLES, 6, 1);}); |
| 223 assertGLError(gl, gl.INVALID_VALUE, "negative count", |
| 224 function(){gl.drawArrays(gl.TRIANGLES, 2, -1);}); |
| 225 assertGLError(gl, gl.INVALID_OPERATION, "3", |
| 226 function(){gl.drawArrays(gl.TRIANGLES, 0, 7);}); |
| 227 assertGLError(gl, gl.INVALID_OPERATION, "4", |
| 228 function(){gl.drawArrays(gl.TRIANGLES, 1, 6);}); |
| 229 vbo.destroy(); |
| 230 } |
| 231 |
| 232 Tests.testDrawArraysVBOMultiOutOfBounds = function(gl, prog, v,n,t) { |
| 233 // creates VBOs for the quad arrays, binds them with |
| 234 // vertexAttribPointer and calls drawArrays |
| 235 var vbo = new VBO(gl, |
| 236 {size:3, data:Quad.vertices}, |
| 237 {size:3, data:Quad.normals}, |
| 238 {size:2, data:Quad.texcoords}); |
| 239 vbo.use(v, n, t); |
| 240 assertGLError(gl, gl.INVALID_OPERATION, "1", |
| 241 function(){gl.drawArrays(gl.TRIANGLES, 6, 1);}); |
| 242 assertGLError(gl, gl.INVALID_VALUE, "negative count", |
| 243 function(){gl.drawArrays(gl.TRIANGLES, 2, -1);}); |
| 244 assertGLError(gl, gl.INVALID_OPERATION, "2", |
| 245 function(){gl.drawArrays(gl.TRIANGLES, 0, 7);}); |
| 246 assertGLError(gl, gl.INVALID_OPERATION, "3", |
| 247 function(){gl.drawArrays(gl.TRIANGLES, 1, 6);}); |
| 248 vbo.destroy(); |
| 249 } |
| 250 |
| 251 Tests.testDrawArraysOOBShaderJuggle = function(gl, prog, v,n,t) { |
| 252 var vbo = new VBO(gl, |
| 253 {size:3, data:[0,0,0]}, |
| 254 {size:3, data:[0,0,0,0,0,0]}); |
| 255 vbo.init(); |
| 256 gl.bindBuffer(gl.ARRAY_BUFFER, vbo.vbos[0]); |
| 257 gl.vertexAttribPointer(v, 3, gl.FLOAT, false, 0, 0); |
| 258 gl.enableVertexAttribArray(v); |
| 259 assertGLError(gl, gl.INVALID_OPERATION, "offset too big", |
| 260 function(){gl.drawArrays(gl.TRIANGLES, 0, 2);}); |
| 261 var sh2 = new Shader(gl, 'vert', 'frag'); |
| 262 sh2.use(); |
| 263 gl.bindBuffer(gl.ARRAY_BUFFER, vbo.vbos[1]); |
| 264 gl.vertexAttribPointer(sh2.attrib('Vertex'), 3, gl.FLOAT, false, 0, 0); |
| 265 gl.enableVertexAttribArray(sh2.attrib('Vertex')); |
| 266 assertOk(function(){gl.drawArrays(gl.TRIANGLES, 0, 2);}); |
| 267 assertGLError(gl, gl.INVALID_OPERATION, "offset too big 2", |
| 268 function(){gl.drawArrays(gl.TRIANGLES, 0, 3);}); |
| 269 prog.use(); |
| 270 gl.vertexAttribPointer(prog.attrib('Vertex'), 3, gl.FLOAT, false, 0, 0); |
| 271 gl.enableVertexAttribArray(prog.attrib('Vertex')); |
| 272 assertOk(function(){gl.drawArrays(gl.TRIANGLES, 0, 2);}); |
| 273 assertGLError(gl, gl.INVALID_OPERATION, "offset too big 3", |
| 274 function(){gl.drawArrays(gl.TRIANGLES, 0, 3);}); |
| 275 sh2.destroy(); |
| 276 } |
| 277 |
| 278 </script> |
| 279 <script id="vert" type="x-shader/x-vertex"> |
| 280 attribute vec3 Vertex; |
| 281 attribute vec3 Normal; |
| 282 attribute vec2 Tex; |
| 283 |
| 284 varying vec4 texCoord0; |
| 285 void main() |
| 286 { |
| 287 gl_Position = vec4(Vertex * Normal, 1.0); |
| 288 texCoord0 = vec4(Tex,0.0,0.0) + gl_Position; |
| 289 } |
| 290 </script> |
| 291 <script id="frag" type="x-shader/x-fragment"> |
| 292 precision mediump float; |
| 293 |
| 294 varying vec4 texCoord0; |
| 295 void main() |
| 296 { |
| 297 gl_FragColor = texCoord0; |
| 298 } |
| 299 </script> |
| 300 |
| 301 |
| 302 <style>canvas{ position:absolute; }</style> |
| 303 </head><body> |
| 304 <canvas id="gl" width="1" height="1"></canvas> |
| 305 </body></html> |
OLD | NEW |