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 var indices = [0,1,2] |
| 40 |
| 41 Tests.startUnit = function () { |
| 42 var canvas = document.getElementById('gl'); |
| 43 var gl = wrapGLContext(canvas.getContext(GL_CONTEXT_ID)); |
| 44 var prog = new Shader(gl, 'vert', 'frag'); |
| 45 prog.use(); |
| 46 var sh = prog.shader.program; |
| 47 var v = gl.getAttribLocation(sh, 'Vertex'); |
| 48 var n = gl.getAttribLocation(sh, 'Normal'); |
| 49 var t = gl.getAttribLocation(sh, 'Tex'); |
| 50 return [gl,prog,v,n,t]; |
| 51 } |
| 52 |
| 53 Tests.setup = function(gl, prog, v,n,t) { |
| 54 assert(0 == gl.getError()); |
| 55 return [gl, prog, v,n,t]; |
| 56 } |
| 57 Tests.teardown = function(gl, prog, v,n,t) { |
| 58 gl.disableVertexAttribArray(v); |
| 59 gl.disableVertexAttribArray(n); |
| 60 gl.disableVertexAttribArray(t); |
| 61 } |
| 62 |
| 63 Tests.endUnit = function(gl, prog, v,n,t) { |
| 64 prog.destroy(); |
| 65 } |
| 66 |
| 67 Tests.testDrawElementsVBO = function(gl, prog, v,n,t) { |
| 68 var vbo = new VBO(gl, |
| 69 {size:3, data:Quad.vertices}, |
| 70 {elements:true, data:Quad.indices}); |
| 71 vbo.draw(v); |
| 72 assert(gl.NO_ERROR == checkError(gl, "vbo.draw")); |
| 73 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);}
); |
| 74 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);}
); |
| 75 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*1);}
); |
| 76 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);}
); |
| 77 vbo.destroy(); |
| 78 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 79 } |
| 80 |
| 81 Tests.testDrawElementsVBOMulti = function(gl, prog, v,n,t) { |
| 82 // creates VBOs for the quad arrays, binds them with |
| 83 // vertexAttribPointer and calls drawElements |
| 84 var vbo = new VBO(gl, |
| 85 {size:3, data:Quad.vertices}, |
| 86 {size:3, data:Quad.normals}, |
| 87 {size:2, data:Quad.texcoords}, |
| 88 {elements:true, data:Quad.indices}); |
| 89 vbo.draw(v, n, t); |
| 90 assert(gl.NO_ERROR == checkError(gl, "vbo.draw")); |
| 91 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);}
); |
| 92 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*2);}
); |
| 93 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);}
); |
| 94 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);}
); |
| 95 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range", |
| 96 function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2);}); |
| 97 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 2", |
| 98 function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2);}); |
| 99 gl.bindBuffer(gl.ARRAY_BUFFER, null); |
| 100 gl.bindBuffer(gl.ARRAY_BUFFER, vbo.vbos[1]); |
| 101 gl.vertexAttribPointer(n, 3, gl.FLOAT, false, 0, 0); |
| 102 assertOk(function(){gl.drawElements(gl.TRIANGLES, 5, gl.UNSIGNED_SHORT, 1*2);}
); |
| 103 assertOk(function(){gl.drawElements(gl.TRIANGLES, 0, gl.UNSIGNED_SHORT, 2*2);}
); |
| 104 assertOk(function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0*2);}
); |
| 105 assertOk(function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 5*2);}
); |
| 106 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 3", |
| 107 function(){gl.drawElements(gl.TRIANGLES, 1, gl.UNSIGNED_SHORT, 6*2);}); |
| 108 assertGLError(gl, gl.INVALID_OPERATION, "count + offset out of range 4", |
| 109 function(){gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 1*2);}); |
| 110 vbo.destroy(); |
| 111 assert(gl.NO_ERROR == checkError(gl, "vbo.destroy")); |
| 112 } |
| 113 |
| 114 |
| 115 </script> |
| 116 <script id="vert" type="x-shader/x-vertex"> |
| 117 attribute vec3 Vertex; |
| 118 attribute vec3 Normal; |
| 119 attribute vec2 Tex; |
| 120 |
| 121 varying vec4 texCoord0; |
| 122 void main() |
| 123 { |
| 124 gl_Position = vec4(Vertex * Normal, 1.0); |
| 125 texCoord0 = vec4(Tex,0.0,0.0) + gl_Position; |
| 126 } |
| 127 </script> |
| 128 <script id="frag" type="x-shader/x-fragment"> |
| 129 precision mediump float; |
| 130 |
| 131 varying vec4 texCoord0; |
| 132 void main() |
| 133 { |
| 134 vec4 c = texCoord0; |
| 135 gl_FragColor = c; |
| 136 } |
| 137 </script> |
| 138 |
| 139 |
| 140 <style>canvas{ position:absolute; }</style> |
| 141 </head><body> |
| 142 <canvas id="gl" width="1" height="1"></canvas> |
| 143 </body></html> |
OLD | NEW |